打开IDEA---new Project---Spring Initializr---填写group和artifact---勾选web---点击下一步,IDEA 会加载Springboot的模板。(springboot2.0.5版本)
在pom.xml中配置起步依赖:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>
主目录下写一个启动类:
@SpringBootApplication @RestController public class HelloWordApplication { public static void main(String[] args) { SpringApplication.run(HelloWordApplication.class, args); } @GetMapping("/hi") public String hi(){ return "我是王小二"; } }
启动后在浏览器中输入:localhost:8080/hi,可显示“我是王小二”。