接口文档是很重要的,可以提高联调速度、可维护性、问题排查速度。
其中,一定要用注解的方式去生成文档,原因见:这里
虽然这样要求,但总有人不遵守规范,或者是忘记加注解了。低端方法:组长定期检查接口文档,看谁没有写。高端方法:项目启动时自动检测注解是否存在,若不存在,直接报错,不让项目启动起来。
效果展示
Controller
package com.knife.example.business.product.controller;
import com.knife.example.business.product.vo.ProductVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Api(tags = "商品")
@RestController
@RequestMapping("product")
public class ProductController {
// @ApiOperation("查询详情")
@GetMapping("detail")
public ProductVO detail(Long id) {
//省略查数据库等逻辑
ProductVO productVO = new ProductVO();
productVO.setId(1L);
productVO.setName("鼠标");
productVO.setStockQuantity(1200);
return productVO;
}
}
项目启动时报错

代码
此内容仅限VIP查看,请先登录

请先 !