# SpringBootBase **Repository Path**: suhaojava/spring-boot-base ## Basic Information - **Project Name**: SpringBootBase - **Description**: spring-boot整合mybatis-plus、swagger2 项目使用SpringBoot版本2.5.6,swagger2版本2.9.2。 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-12-31 - **Last Updated**: 2023-09-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### spring-boot整合mybatis-plus、swagger2 #### application.yml中的配置 ``` #服务配置 server: port: 9002 #spring配置 spring: #1.应用配置 application: name: interfaces #指定服务名 #2.数据库连接池 datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/interfaces?useUnicode=true&characterEncoding=utf8 username: root password: root #mybatis-plus 设置 mybatis-plus: mapper-locations: classpath*:com/inter/interfaces/**/xml/*Mapper.xml global-config: # 关闭MP3.0自带的banner banner: false db-config: #主键类型 0:"数据库ID自增",1:"该类型为未设置主键类型", 2:"用户输入ID",3:"全局唯一ID (数字类型唯一ID)", 4:"全局唯一ID UUID",5:"字符串全局唯一ID (idWorker 的字符串表示)"; id-type: ID_WORKER # 默认数据库表下划线命名 table-underline: true configuration: # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用 #log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 返回类型为Map,显示null对应的字段 call-setters-on-nulls: true ``` #### Mybatis-plus的配置类MybatisPlusConfig ``` @Configuration @MapperScan(value={"com.inter.interfaces.**.mapper"}) //扫描配置路径下的Mapper public class MybatisPlusConfig { /** *增加配置后分页才会生效 */ @Bean public PaginationInterceptor paginationInterceptor(){ return new PaginationInterceptor(); } } ``` #### swagger的配置类SwaggerConfig ``` /** * SwaggerConfig * @desc: Swagger配置 * @version: * @createTime: 2020/8/06 14:36 * @author: */ @Configuration public class SwaggerConfig { @Bean public Docket createH5RestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("swagger文档") .description("restful 风格接口") .version("1.0") .build(); } } ``` #### pom.xml文件中的依赖包和属性配置 ``` org.springframework.boot spring-boot-starter-parent 2.5.6 1.8 5.7.18 2.9.2 2.9.2 1.8.5 org.springframework.boot spring-boot-starter-web mysql mysql-connector-java runtime org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test com.baomidou mybatis-plus-boot-starter 3.1.0 cn.hutool hutool-all 5.7.18 net.java.dev.jna jna 5.3.1 net.java.dev.jna jna-platform 5.3.1 io.springfox springfox-swagger-ui ${swagger-ui.version} io.springfox springfox-swagger2 ${swagger2.version} com.github.xiaoymin swagger-bootstrap-ui ${swagger-bootstrap-ui.version} ``` mysql5.7版本,创建数据库interfaces。运行脚本init.sql。 #### 启动项目 - 运行com.inter.interfaces.InterfacesApplication 项目使用springboot版本2.5.6,swagger2版本2.9.2。 启动后在浏览器输入 http://localhost:9002/doc.html 会看到swagger界面 ![](swagger.png)