• swagger的使用


    所需依赖:
    <dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
    </dependency>
    <dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.9.2</version>
    </dependency>

    <dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>28.0-jre</version>
    </dependency>

    加入配置:
    @EnableSwagger2
    @ComponentScan(basePackages = {"com.priusis.bmis.app.web.controller"})
    @Configuration
    public class SwaggerConfig extends WebMvcConfigurationSupport {

    @Bean
    public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
    .apiInfo(apiInfo())
    .select()
    .apis(RequestHandlerSelectors.any())
    .paths(Predicates.not(PathSelectors.regex("/error.*")))
    .paths(PathSelectors.any())
    .build();
    }

    private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
    .title("dr-erp接口文档")
    .build();
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/**").addResourceLocations(
    "classpath:/static/");
    registry.addResourceHandler("swagger-ui.html").addResourceLocations(
    "classpath:/META-INF/resources/");
    registry.addResourceHandler("/webjars/**").addResourceLocations(
    "classpath:/META-INF/resources/webjars/");
    super.addResourceHandlers(registry);
    }
    }


    controller:

    @RestController
    @RequestMapping("/app/home")
    @Api(value = "AppHomeController", description = "主页相关信息接口")
    public class AppHomeController {

    @Resource
    private IAppHomeService appHomeService;

    @GetMapping("/loadInfo")
    @ApiOperation(value = "", notes = "加载主页信息")
    public Result<HomeVo> loadHomeInfo() {
    return Result.success(appHomeService.loadHomeInfo());
    }

    /**
    * @ApiModelProperty("物料信息")
    * private List<ItemAppVo> items;
    * @param limit
    * @return
    */
    @GetMapping("/loadItem")
    @ApiOperation(value = "", notes = "加载热销商品信息")
    public Result<List<ItemAppVo>> loadItem(@ApiParam(required = false, value = "每页商品数量")
    @RequestParam(required = false, defaultValue = PageConstant.APP_PAGE_SIZE) Integer limit) {
    return Result.success(appHomeService.loadItem(limit));
    }
    }



    vo:
    @Data
    public class HomeVo {
    @ApiModelProperty("轮播图")
    private String[] images;
    @ApiModelProperty("公司名称")
    private String companyName;
    @ApiModelProperty("公司地址")
    private String companyAddress;
    @ApiModelProperty("公司邮箱")
    private String companyEmail;
    @ApiModelProperty("公司电话")
    private String companyTel;

    }


     
    
    
  • 相关阅读:
    050医疗项目-模块五:权限设置-第三方系统的接入
    049医疗项目-模块五:权限设置
    047医疗项目-模块四:采购单模块—采购单审核提交(Dao,Service,Action三层)
    046医疗项目-模块四:采购单模块—采购单审核(Dao,Service,Action三层)
    Netty原理分析
    Java集群优化——使用Dubbo对单一应用服务化改造
    知乎问答:现在程序员的工资是不是被高估了?
    一文理解 Java NIO 核心组件
    深入理解 Spring 事务原理
    完美主义对程序员的影响
  • 原文地址:https://www.cnblogs.com/But-you/p/12624986.html
Copyright © 2020-2023  润新知