1.
1、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。
2、编写controller内容
@RestController
public class HelloWorldController { @RequestMapping("/hello") public String index() { return "Hello World"; } }
@RestController的意思就是controller里面的方法都以json格式输出,不用再写什么jackjson配置的了!
3、启动主程序,打开浏览器访问http://localhost:8080/hello,就可以看到效果了,有木有很简单!
https://zhuanlan.zhihu.com/p/24957789
扫描二维码关注公众号,回复:
4161759 查看本文章
https://www.zhihu.com/question/53729800/answer/255785661