本次学习结合了swagger,swagger配置教程看【spring-boot】swagger配置
1. 创建子模块zxw-mybatis,添加必要的依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<!--添加lombok依赖-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- mybatis以及mysql依赖-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
2. 在resources文件夹下创建文件application.properties,并在此配置数据源信息
spring.datasource.url=jdbc:mysql://localhost:3306/xxxxx?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false
spring.datasource.username= 数据库名
spring.datasource.password= 数据库密码
spring.datasource.driverClassName=com.mysql.jdbc.Driver
此配置与数据库相对应
3. 为了让mybatis自动生成mapper等文件,需要引入mybatis-generator插件。回到父模块zhangxianwen-test的pom文件中添加插件依赖(在父模块中添加后,所有子模块不用重新写依赖直接使用了)
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<verbose>true</verbose> //打印详细信息
<overwrite>true</overwrite>
</configuration>
</plugin