1. 去https://start.spring.io/默認下載一個maven項目 Generate Project(懂的話也可以更改其中的配置)。
2. 打開Eclipse,導入剛剛解壓的Maven項目。
3. 在demo下建立一個controller包,簡單顯示一點數據:
package com.example.demo.controller; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @SpringBootApplication @RequestMapping("/springboot") public class HelloController { @RequestMapping("/hello") public String hello() { return "Hello Spring Boot"; } }
注意:maven包下還需要引入以下dependency:
<!-- 引入@RestController和@RequestMapping --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
然后Java Application運行DemoApplication,瀏覽器輸入localhost:8080/springboot/hello即可看到
,這樣就搭建好了。