一、首先构建项目
1、访问http://start.spring.io/
2.然后将其导入eclipse
pom.xml中添加支持web的模块
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
pom.xml文件中默认有两个模块:
spring-boot-starter
:核心模块,包括自动配置支持、日志和YAML;
spring-boot-starter-test
:测试模块,包括JUnit、Hamcrest、Mockito。
编写controller
@RestController
public class HelloWorldController {
@RequestMapping("/hello")
public String index() {
return "Hello World";
}
}
@RestController
的意思就是controller里面的方法都以json格式输出,不用再写什么jackjson配置的了!
启动主程序,打开浏览器访问http://localhost:8080/hello,就可以看到效果了,有木有很简单!