利用idea创建项目



spring-boot-starter-web:核心模块,包括自动配置支持,日志和yamlspring-boot-starter-test:测试模块,包括JUnit、Hamcrest、Mockito。
编写Controller
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello(){
return "hello world!";
}
}
@RestController的意思就是controller里面的方法都以json格式输出,不用再写什么jackjson配置
启动程序,访问接口
打开浏览器访问http://localhost:8080/hello
本文详细介绍如何使用IDEA创建Spring Boot项目,包括引入核心模块spring-boot-starter-web和测试模块spring-boot-starter-test,编写Controller实现JSON响应,并通过浏览器访问自定义接口。
303

被折叠的 条评论
为什么被折叠?



