在官网创建项目
https://start.spring.io
下载到本地解压
用idea打开
编写HelloWorld服务
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello() {
return "hello world!!";
}
@RequestMapping("/index")
public Map<String,Object> index() {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("code",200);
map.put("msg","success");
return map;
}
}
@ComponentScan(basePackages = "com.xdp.controller")//配置正确的扫包
@EnableAutoConfiguration
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}