背景: 项目开发提供快速提供假接口,使得前后端并行开发,提升效率。
前置操作
- 本地可运行框架代码
- 熟悉基本JAVA SPRING-BOOT 框架开发
开发规范
假接口编写示例
- Controller层增加入口
- 根据接口业务逻辑 确定接口POST/GET 以及添加相关注释
- 在DTO 中定义 出入参数 结构体
- 如果需要枚举 在common/constant 中定义
- 根据需要 在假接口 增加返回值
@ApiOperation("根据不同类型展示感悟")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<ThoughtListResult> list(
@RequestParam(value = "pageNum", defaultValue = "0") @ApiParam("页码") Integer pageNum,
@RequestParam(value = "offset", defaultValue = "0") @ApiParam("偏移量") Integer offset,
@RequestParam(value = "type", defaultValue = "0") @ApiParam("查询类型") ThoughtSearchType type) {
// 增加假数据 返回五条默认数据感悟
ThoughtListResult list = new ThoughtListResult();
for (int i= 0 ; i < 5; i++) {
list.getThoughtItemList().add(new ThoughtItem());
}
return CommonResult.success(list);
}
将假接口实现
- 在service 下增加对应逻辑层接口 interface
- 在 service/impl 增加 对应接口层实现 impl