Springboot集成MybatisGenerator插件相关数据源配置
Database:win64_11gR2_database(oracle11g)/JDBC Driver(ojdbc6)
JDK:java version "1.8.0_181"(jdk1.8.0_181)
Springboot:2.x(2.1.2.RELEASE)
pom.xml引用本地oracle驱动包依赖(注意jdk版本支持),tk.mybatis等依赖加入
<!--oracle驱动包依赖-->
<dependency>
<groupId>oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4.0</version>
<scope>system</scope>
<systemPath>${pom.basedir}/lib/ojdbc6.jar</systemPath>
</dependency>
<!--通用mapper依赖开始-->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.5</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/tk.mybatis/mapper -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>4.1.5</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.2</version>
</dependency>
<!--通用mapper依赖结束-->
Mybatis代码生成插件
<build>
<finalName>sample-java-springboot</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- springboot项目打jar包运行 插件版本只能是1.4.2.RELEASE -->
<version>1.4.2.RELEASE</version>
<configuration>
<!--入口类-->
<mainClass>com.sample.Application</mainClass>
<!-- Springboot通过jar打包部署引入本地jar包 -->
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<!-- Springboot通过war打包部署引入本地jar包 -->
<webResources>
<resource>
<directory>${basedir}/lib</directory>
<targetPath>WEB-INF/lib</targetPath>
<filtering>false</filtering>
</resource>
</webResources>
</configuration>
</plugin>
<!-- mybatis generator自动生成代码插件 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
<dependencies>
<!--oracle驱动包-->
<dependency>
<groupId>oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4.0</version>
<scope>system</scope>
<systemPath>${pom.basedir}/lib/ojdbc6.jar</systemPath>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/tk.mybatis/mapper -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>4.1.5</version>
</dependency>
<!-- pagehelper-spring-boot-starter -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.10</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<phase>package</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<!--允许移动生成的文件 -->
<verbose>true</verbose>
<!-- 是否覆盖 -->
<overwrite>true</overwrite>
<!-- 自动生成的配置 -->
<configurationFile>src/main/resources/mybatisgenerator.xml
</configurationFile>
</configuration>
</plugin>
</plugins>
</build>
Mybatis Generator的实体model生成中文注释,针对oracle配置
<!--数据库连接 -->
<jdbcConnection driverClass="${spring.datasource.driver-class-name}"
connectionURL="${spring.datasource.url}"
userId="${spring.datasource.username}"
password="${spring.datasource.password}">
<!-- 针对oracle数据库 -->
<property name="remarksReporting" value="true"></property>
</jdbcConnection>
application-datasource.properties
#外部数据源配置-oracle
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@127.0.0.1:1521:ORCL
spring.datasource.username=LT2019
spring.datasource.password=LT2019#mybatisGenerator插件配置
##POJO对象实体对应包路径
mybatis.javaModel.location=com.sample.entity
##mapper.xml对应client,即接口dao对应包路径
mybatis.javaClient.location=com.sample.mapper
##mapper.xml文件,并放到resources下的此文件夹下
mybatis.sqlMapper.location=mapper#设置mybatis
##允许使用别名代替列名
##mapper文件扫描
#mybatis mybatis.type-aliases-package=com.sample.mapper
mybatis.mapper-locations=classpath:mapper/*Mapper.xml
#开启驼峰命名
mybatis.configuration.mapUnderscoreToCamelCase=true
mybatis-generator.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"><generatorConfiguration>
<properties resource="application-datasource.properties"/>
<context id="oracleCtx" targetRuntime="MyBatis3">
<!--去除注释 -->
<!--<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>--><property name="javaFileEncoding" value="UTF-8"/>
<plugin type="tk.mybatis.mapper.generator.MapperPlugin">
<property name="mappers" value="tk.mybatis.mapper.common.Mapper"/>
<!-- caseSensitive默认false,当数据库表名区分大小写时,可以将该属性设置为true -->
<property name="caseSensitive" value="true"/>
</plugin><!--数据库连接 -->
<jdbcConnection driverClass="${spring.datasource.driver-class-name}"
connectionURL="${spring.datasource.url}"
userId="${spring.datasource.username}"
password="${spring.datasource.password}">
<!-- 针对oracle数据库 -->
<property name="remarksReporting" value="true"></property>
</jdbcConnection>
<!--默认false Java type resolver will always use java.math.BigDecimal if
the database column is of type DECIMAL or NUMERIC. -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver><!--生成实体类 指定包名 以及生成的地址 (可以自定义地址,但是路径不存在不会自动创建 使用Maven生成在target目录下,会自动创建) -->
<javaModelGenerator targetPackage="${mybatis.javaModel.location}" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!--生成SQLMAP文件 -->
<sqlMapGenerator targetPackage="${mybatis.sqlMapper.location}" targetProject="src/main/resources">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!--生成Dao文件 可以配置 type="XMLMAPPER"生成xml的dao实现 context id="DB2Tables" 修改targetRuntime="MyBatis3" -->
<javaClientGenerator type="XMLMAPPER" targetPackage="${mybatis.javaClient.location}"
targetProject="src/main/java">
<property name="enableSubPackages" value="false" />
</javaClientGenerator><!--对应数据库表 oracle可以加入主键自增 字段命名 忽略某字段等 -->
<table tableName="USER_DET" domainObjectName="UserDet"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false" /></context>
</generatorConfiguration>