一,引入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> <context id="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat"> <property name="javaFileEncoding" value="UTF-8"/> <plugin type="tk.mybatis.mapper.generator.MapperPlugin"> <property name="mappers" value="com.example.ordersystem.common.mapper.SchoolBaseMapper"/> </plugin> <!-- 生成注释配置 --> <commentGenerator> <!-- 是否取消注释 --> <property name="suppressAllComments" value="false"/> <!-- 数据库注释支持 --> <property name="addRemarkComments" value="false"/> <!-- 时间格式设置 --> <property name="dateFormat" value="yyyy-MM-dd HH:mm:ss"/> </commentGenerator> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://ip地址:3306/order_system?serverTimezone=GMT%2B8" userId="root" password="root"> </jdbcConnection> <javaModelGenerator targetPackage="com.example.ordersystem.common.entity" targetProject="src/main/java"/> <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources"/> <javaClientGenerator targetPackage="com.example.ordersystem.common.mapper" targetProject="src/main/java" type="XMLMAPPER"/> <!-- <table tableName="t%" > <generatedKey column="id" sqlStatement="MySql" identity="true" /> <domainObjectRenamingRule searchString="^T" replaceString="" /> <columnRenamingRule searchString="^T" replaceString=""/> </table>--> <table tableName="order_detail"> <generatedKey column="detail_id" sqlStatement="MySql" identity="true"/> <domainObjectRenamingRule searchString="^T" replaceString=""/> <columnRenamingRule searchString="^T" replaceString=""/> </table> <table tableName="order_master"> <generatedKey column="order_id" sqlStatement="MySql" identity="true"/> <domainObjectRenamingRule searchString="^T" replaceString=""/> <columnRenamingRule searchString="^T" replaceString=""/> </table> <table tableName="product_category"> <generatedKey column="category_id" sqlStatement="MySql" identity="true"/> <domainObjectRenamingRule searchString="^T" replaceString=""/> <columnRenamingRule searchString="^T" replaceString=""/> </table> <table tableName="product_info"> <generatedKey column="product_id" sqlStatement="MySql" identity="true"/> <domainObjectRenamingRule searchString="^T" replaceString=""/> <columnRenamingRule searchString="^T" replaceString=""/> </table> </context> </generatorConfiguration>
这个配置文件中可以去除添加去除创建的T
在pom文件中引入插件:
<plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version> 1.36</version> <configuration> <configurationFile>${basedir}/src/main/resources/generator/generatorConfiglocal.xml </configurationFile> <overwrite>true</overwrite> <verbose>true</verbose> </configuration> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>runtime</version> </dependency> <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper</artifactId> <version>3.4.6</version> </dependency> </dependencies> </plugin>
然后再使用maven上个的插件,就可以直接生成dao,mapper,mapper.xml文件