API文档构建工具 -Swagger2

pom.xml

<!--    swagger2文档生产工具-->
   <dependency>
     <groupId>io.springfox</groupId>
     <artifactId>springfox-swagger2</artifactId>
     <version>3.0.0</version>
   </dependency>
   <dependency>
     <groupId>io.springfox</groupId>
     <artifactId>springfox-swagger-ui</artifactId>
     <version>3.0.0</version>
   </dependency>

Swagger2类

@Configuration
@EnableSwagger2
public class Swagger2 {
    @Bean
    public Docket creatRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.ky.springboot.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("用户管理接口API文档")
                .version("1.0")
                .build();
    }
}

controller类


```java
@Api(tags = "用户管理模块")
@RestController
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("user/name/{userName}")
    @ApiOperation(value = "通过用户名查询用户对象")
    @ApiImplicitParam(name = "userName",value = "用户名称",required =  true, paramType = "path")
//    @ResponseBody
    public User queryUserByName(@PathVariable String userName){
        return userService.queryUserByName(userName);
    }

    @GetMapping("user/id/{userId}")
    @ApiOperation(value = "通过用户id查询用户对象")
    @ApiImplicitParam(name = "userId",value = "用户id", required = true, paramType = "path")
    public User queryUserById(@PathVariable Integer userId){
        return userService.queryUserById(userId);
    }

    @PostMapping("user")
    @ApiOperation(value = "添加用户")
    @ApiImplicitParam(name = "user",value = "用户对象")
    public Map<String,Object> addUser(User user){

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值