创建common模块

在guli-parent下创建模块common

配置:

groupId:com.leon

artifactId:common

在common中引入相关依赖

<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><scope>provided </scope></dependency><!--mybatis-plus--><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><scope>provided </scope></dependency><!--lombok用来简化实体类:需要安装lombok插件--><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><scope>provided </scope></dependency><!--swagger--><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><scope>provided </scope></dependency><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><scope>provided </scope></dependency><!-- redis --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><!-- spring2.X集成redis所需common-pool2<dependency><groupId>org.apache.commons</groupId><artifactId>commons-pool2</artifactId><version>2.6.0</version></dependency>-->
</dependencies>

在common下面创建子模块service-base

在模块service-base中,创建swagger的配置类

创建包com.leon.servicebase.config,创建类SwaggerConfig

package com.leon.servicebase;import com.google.common.base.Predicates;
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.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;@Configuration//配置类
@EnableSwagger2 //swagger注解
public class SwaggerConfig {@Beanpublic Docket webApiConfig(){return new Docket(DocumentationType.SWAGGER_2).groupName("webApi").apiInfo(webApiInfo()).select().paths(Predicates.not(PathSelectors.regex("/admin/.*"))).paths(Predicates.not(PathSelectors.regex("/error.*"))).build();}private ApiInfo webApiInfo(){return new ApiInfoBuilder().title("网站-课程中心API文档").description("本文档描述了课程中心微服务接口定义").version("1.0").contact(new Contact("java", "http://leon.com", "1123@qq.com")).build();}
}

在模块service模块中引入service-base

<dependency><groupId>com.leon</groupId><artifactId>service-base</artifactId><version>0.0.1-SNAPSHOT</version>
</dependency>

在service-edu启动类上添加注解,进行测试

@SpringBootApplication
@ComponentScan(basePackages = {"com.leon"})
public class EduApplication {public static void main(String[] args) {SpringApplication.run(EduApplication.class, args);}
}

API模型

可以添加一些自定义设置,例如:

定义样例数据

@ApiModelProperty(value = "创建时间", example = "2019-01-01 8:00:00")
@TableField(fill = FieldFill.INSERT)
private Date gmtCreate;@ApiModelProperty(value = "更新时间", example = "2019-01-01 8:00:00")
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date gmtModified;

定义接口说明和参数说明

定义在类上:@Api

定义在方法上:@ApiOperation

定义在参数上:@ApiParam

@Api(description="讲师管理")
@RestController
@RequestMapping("/admin/edu/teacher")
public class TeacherAdminController {@Autowiredprivate TeacherService teacherService;@ApiOperation(value = "所有讲师列表")@GetMappingpublic List<Teacher> list(){return teacherService.list(null);}@ApiOperation(value = "根据ID删除讲师")@DeleteMapping("{id}")public boolean removeById(@ApiParam(name = "id", value = "讲师ID", required = true)@PathVariable String id){return teacherService.removeById(id);}}

配置Swagger2相关推荐

  1. JAVA入门[23]-SpringBoot配置Swagger2

    一.新建SpringBoot站点 1.新建module,然后引入pom依赖: <parent><groupId>org.springframework.boot</gro ...

  2. SpringBoot配置swagger2(亲测有效,如果没有配置成功,欢迎在下方留言)

    一.导包: <dependency><groupId>io.springfox</groupId><artifactId>springfox-swagg ...

  3. SSM 配置 Swagger2 接口文档引擎

    POM 增加 Swagger2 所需依赖,pom.xml 配置如下: <!-- Swagger2 Begin --> <dependency><groupId>io ...

  4. java:springboot1.x/springboot2.x配置swagger2登录密码/设置swagger访问权限

    需求描述 需要将springboot项目的swagger文档配置为输入用户名密码登录后才可访问,即: springboot1.x配置方法 首先需要在pom.xml中引入依赖包(需要确保只引入这一个se ...

  5. 项目配置Swagger2生成API接口文档

    一.Swagger2介绍 前后端分离开发模式中,api文档是最好的沟通方式. Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务. 及时性 (接 ...

  6. springboot细节挖掘(配置Swagger2)

    首先启动一个springboot的项目: 配置pow.xml,在maven里面添加依赖 <!--springboot之swaager的配置 start--><dependency&g ...

  7. 【swagger2】Spring Boot 配置swagger2

    说明:本文写作目的单纯是记录一次项目搭建,以便于以后查看. 开发工具:IDEA:操作系统:MacOS 文章目录 前言 一.引入依赖 二.修改配置文件 三.Docket编写 遇到的问题 前言 Swagg ...

  8. Springboot配置Swagger2

    方式:创建Java类来配置Swagger设置 1.在pom.xml添加依赖 <dependency><groupId>io.springfox</groupId>& ...

  9. springboot 中配置Swagger2

    1.引入依赖 <!--swagger2 依赖--><dependency><groupId>io.springfox</groupId><arti ...

最新文章

  1. 遇到的一些小的tips
  2. Python 学习笔记12 类 - 使用类和实例
  3. bugku-杂项 convert
  4. 干货 | Elasticsearch开发人员最佳实战指南
  5. Memcache存储大数据的问题
  6. 常见的js算法面试题收集,es6实现
  7. *【HDU - 4006】 The kth great number(优先队列 or 线段树)
  8. 站在智能路由的风口,他选择把传统OA放进盒子
  9. nginx分割日志管理
  10. 如何用java实现加减_用Java实现不用加减乘除做加法操作
  11. unity3d实现序列帧动画
  12. C语言学习笔记(零)
  13. Mad Libs游戏:熟悉python编程环境,基本输入输出
  14. swat模型_文献分享——欧洲大陆尺度水质模型高分辨率大尺度SWAT模型率定及不确定性分析...
  15. Pygame教程系列二:MoviePy视频播放篇
  16. ant-design-vue 动态主题 css前缀变更
  17. win7蓝屏报错:STOP:0x0000007E
  18. 视频压缩软件APP有哪些?让我来告诉你答案
  19. Qt中使用TCP和MC协议与三菱Q系列PLC通信
  20. 1.机器学习入门-初学者的机器学习

热门文章

  1. 学习c++的优秀博客(转)
  2. HDU 3123 GCC(同余模定理)
  3. 关于mobile中datagrid的使用
  4. sql server2008给数据表,字段,添加修改注释
  5. linux 网桥的管理和搭建
  6. 铜陵信息化建设和智慧城市发展成果惠及百姓
  7. HTML5学习笔记简明版(9):变化的元素和属性
  8. codeforces 356C Bear and Square Grid
  9. css3学习总结1--CSS3选择器
  10. paip.mysql 5.6 安装总结