喵喵中台-SpringBoot 整合了swagger2

第一步:引入jar (version->2.9.2)

        
            io.springfox
            springfox-swagger2
        
        
            io.springfox
            springfox-swagger-ui
        

第二步:建配置

package com.miaomiao.user.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * SwaggerConfig
 *
 * @author lzy
 * @date 2020/10/15
 */
@EnableSwagger2
@Configuration
public class SwaggerConfig {
    private static final String TITLE = "喵喵用户中心";
    private static final String DESCRIPTION = "提供用户信息服务";
    private static final String SERVICE_URL = "";
    private static final String VERSION = "1.0.0";

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.miaomiao.user.domain.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(TITLE)
                .description(DESCRIPTION)
                .termsOfServiceUrl(SERVICE_URL)
                .version(VERSION)
                .build();
    }


}

第三步:在控制器contraller加注解

package com.miaomiao.resume.api;

import com.miaomiao.common.rest.RestResponse;
import com.miaomiao.resume.api.dto.request.CategoryReqDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;

/**
* 简历分类服务接口
*
* @author lzy
* @since 2020-10-24
*/
@Api(tags = {"简历中心:简历分类服务"})
@FeignClient(name = "${miaomiao.resume.center.name:miaomiao-resume-center}", path = "/v1/category", contextId = "miaomiao-resume-center-ICategoryApi")
public interface ICategoryApi {

    /**
    * 新增简历分类
    *
    * @param addReqDto 简历分类请求对象
    * @return 处理结果
    */
    @PostMapping("")
    @ApiOperation(value = "新增简历分类", notes = "新增简历分类")
    RestResponse addCategory(@RequestBody CategoryReqDto addReqDto);

    /**
    * 修改简历分类
    *
    * @param modifyReqDto 简历分类请求对象
    * @return 处理结果
    */
    @PutMapping("")
    @ApiOperation(value = "修改简历分类", notes = "修改简历分类")
    RestResponse modifyCategory(@RequestBody CategoryReqDto modifyReqDto);

    /**
    * 删除简历分类
    *
    * @param ids        简历分类删除数据ID
    * @param instanceId 实例ID
    * @return 处理结果
    */
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除简历分类", notes = "删除简历分类")
    RestResponse removeCategory(@PathVariable("ids") String ids, @RequestParam("instanceId") Long instanceId);
}

第四步:看效果

喵喵中台-SpringBoot 整合了swagger2_第1张图片

你可能感兴趣的:(喵喵中台建设,swagger2)