springboot快速写接口

一.数据库建表
在这里插入图片描述

二.建entity层(对应数据库表的字段一一对应)
在这里插入图片描述
内容如上,另外注意一点,lombock插件用@data ,就不用写get set方法了

三.建Mapper层(Dao层/domain层)
在这里插入图片描述
解释一下: @select是sql查询语言, “select * from doctor” 查询所有
下面一个findAll()方法

如果是新创建的项目,别忘了扫描mapper
在这里插入图片描述
四. 建controller层
在这里插入图片描述
1.@RestController:使用这个注解后该controller的所有方法都会返回json格式的数据.
2.@Api() : Swagger2接口文档描述
3.@RequestMapping(“/manage-api/v1”) : 接口路径
4.@Resource : 引入文件
5.@GetMapping(“/doctor”) :get请求接口的子路径
6.因为已经引进来DoctorMapper ,就调用他的方法,返回数据

效果图:
在这里插入图片描述
访问接口文档: http://localhost:8901/swagger-ui.html (自己的后端地址)
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/zhangaob/article/details/124651591