004-按照指定功能模块名称分组

发布于:2024-10-17 ⋅ 阅读:(9) ⋅ 点赞:(0)

一、说明

1.现在有一个需求:

需要把一个功能模块的几个功能点放在同一个文档目录下,这几个功能点分布在不同的 Controller

2.具体做法

需要把他们单独分组,方便前端对接。在@ApiOperation 里面增加属性 tags 赋值

注意:接口可以在同一个Controller,也可以不在同一个Controller

二、代码案例

@Api(tags = "测试日期格式化")
@Slf4j
@RequestMapping("/test8Controller")
@RestController
public class Test8Controller {

    @ApiOperation(value = "查询8实体信息",tags = {"查询API"})
    @GetMapping("/test1")
    public TestDateTimeFormat test1(){
        TestDateTimeFormat testDateTimeFormat = new TestDateTimeFormat();
        testDateTimeFormat.setName("xiaogang");
        testDateTimeFormat.setPhoneNumber("111111111111");
        testDateTimeFormat.setAddress("beijing");
        testDateTimeFormat.setBirthday(new Date());
        return testDateTimeFormat;
    }

    @ApiOperation(value = "新增实体信息")
    @PostMapping("/test2")
    public void test2(@RequestBody TestDateTimeFormat testDateTimeFormat){
        log.info("实体类:{}",testDateTimeFormat);
        // 实体类:TestJsonFormat(name=小明, address=北京市, phoneNumber=123456789, birthday=Thu Oct 10 14:42:20 CST 2024)
    }

}
@Api(tags = "测试TestJsonFormat日期格式化")
@Slf4j
@RequestMapping("/test7Controller")
@RestController
public class Test7Controller {

    @ApiOperation(value = "查询7实体信息",tags = {"查询API"})
    @GetMapping("/test1")
    public TestJsonFormat test1(){
        TestJsonFormat testJsonFiled = new TestJsonFormat();
        testJsonFiled.setName("xiaogang");
        testJsonFiled.setPhoneNumber("111111111111");
        testJsonFiled.setAddress("beijing");
        testJsonFiled.setBirthday(new Date());
        return testJsonFiled;
    }

    @RequestMapping("/test2")
    public void test2(@RequestBody TestJsonFormat testJsonFormat){
        log.info("实体类:{}",testJsonFormat);
        // 实体类:TestJsonFormat(name=小明, address=北京市, phoneNumber=123456789, birthday=Thu Oct 10 14:42:20 CST 2024)
    }

}

三、效果展示

在这里插入图片描述