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即可看到
,这样就搭建好了。