mybatis-generator这是原来的github地址
现在在此基础上添加了一对一和一对多映射配置,配置在table标签上
如果需要一对一配置生成,需要添加插件配置
在context中添加如下配置
<plugin type="cc.bandaotixi.plugins.OneToOnePlugin"></plugin>
一对多配置如下
<plugin type="cc.bandaotixi.plugins.OneToManyPlugin"></plugin>
批量插入和批量更新
<plugin type="cc.bandaotixi.plugins.BatchInsertPlugin"></plugin><plugin type="cc.bandaotixi.plugins.BatchUpdatePlugin"></plugin>
如果需要把数据库注释添加到Java文件中,配置如下
<commentGenerator type="cc.bandaotixi.plugins.BDTCommentGenerator"> <property name="javaFileEncoding" value="UTF-8"/> <property name="suppressDate" value="true"/> <property name="suppressAllComments" value="false" /></commentGenerator>
那么配置一对一表时应这么配置
<table tableName="t_test" domainObjectName="TEst"> <generatedKey column="test_id" sqlStatement="MySql" identity="true" /> <oneToOne mappingTable="t_test" column="test_id" joinColumn="parent_test_id" where="t_test.is_deleted=0" /> </table>
配置一对多表时
<table tableName="t_test" domainObjectName="Test"> <generatedKey column="test_id" sqlStatement="MySql" identity="true" /> <oneToMany mappingTable="t_test" column="test_id" joinColumn="parent_test_id" where="t_test.is_deleted=0" /> </table>
下面补上全部配置
<?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> <classPathEntry location="C:\Users\administrator\.m2\repository\mysql\mysql-connector-java\5.1.39\mysql-connector-java-5.1.39.jar" /> <context id="appInfo" targetRuntime="MyBatis3"> <property name="javaFileEncoding" value="UTF-8"/> <plugin type="cc.bandaotixi.plugins.OneToOnePlugin"></plugin> <plugin type="cc.bandaotixi.plugins.OneToManyPlugin"></plugin> <plugin type="cc.bandaotixi.plugins.BatchInsertPlugin"></plugin> <plugin type="cc.bandaotixi.plugins.BatchUpdatePlugin"></plugin> <commentGenerator type="cc.bandaotixi.plugins.BDTCommentGenerator"> <property name="suppressDate" value="true"/> <property name="suppressAllComments" value="false" /> </commentGenerator> <jdbcConnection connectionURL="jdbc:mysql://localhost:3307/test?useUnicode=true&characterEncoding=utf-8&useSSL=true" driverClass="com.mysql.jdbc.Driver" password="test" userId="root" /> <javaModelGenerator targetPackage="com.entity" targetProject="src/main/java"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources"> <property name="enableSubPackages" value="true" /> <property name="isMergeable" value="false"/> </sqlMapGenerator> <javaClientGenerator type="XMLMAPPER" targetPackage="com.dao" targetProject="src/main/java"> <property name="enableSubPackages" value="true" /> </javaClientGenerator> <table tableName="t_test" domainObjectName="Test"> <generatedKey column="test_id" sqlStatement="MySql" identity="true" /> <oneToMany mappingTable="t_test" column="parent_est_id" joinColumn="test_id" where="t_test.is_deleted=0" /> </table> </context></generatorConfiguration>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
值得注意的是,如果使用批量更新功能需要在连接的配置上添加allowMultiQueries=true
如果你比较懒,不想编译代码也可以直接下载,但是需要一个积分
如果需要进一步添加插件,请fork郗瑞强MybatisGenerator工具
如果有问题或者BUG请发邮件到:bandaotixi@hotmail.com
感谢