快速搭建一个SpringBoot入门项目

在官网创建项目

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);
    }
}

运行

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42545256/article/details/84500705