mybatis generator一对一映射,一对多映射,批量插入,批量更新
来源:互联网 发布:eve mac 国服 编辑:程序博客网 时间:2024/05/19 04:27
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"><!--生成mapper命令java -jar mybatis.jar -configfile generatorConfig.xml -overwrite--><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> <!-- 在ibatis2 中是dao层,但在mybatis3中,其实就是mapper接口 --> <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--> </table> </context></generatorConfiguration>
值得注意的是,如果使用批量更新功能需要在连接的配置上添加allowMultiQueries=true
如果你比较懒,不想编译代码也可以直接下载,但是需要一个积分
如果需要进一步添加插件,请fork郗瑞强MybatisGenerator工具
如果有问题或者BUG请发邮件到:bandaotixi@hotmail.com
感谢
阅读全文
4 0
- mybatis generator一对一映射,一对多映射,批量插入,批量更新
- mybatis generator一对一映射,一对多映射,批量插入,批量更新
- Mybatis一对一、一对多关联映射
- myBatis 一对一 和一对多映射
- MyBatis关联映射:一对一、一对多
- mybatis映射 一对一、一对多、多对多高级映射
- MyBatis高级映射之-一对一(一对多)关联映射
- 【Mybatis高级映射】一对一映射、一对多映射、多对多映射
- Mybatis 批量插入、批量更新
- myBatis级联一对一,一对多及批量操作
- mybatis中的高级映射一对一、一对多、多对多
- Mybatis(2、关系映射一对一、一对多、多对多)
- mybatis高级映射(一对一,一对多,多对多)
- 【Mybatis】一对一,一对多,多对多映射
- Mybatis高级结果映射一对一或一对多
- [MyBatis日记](6)一对一与一对多映射
- MyBatis映射文件的resultMap一对一一对多关联
- Mybatis高级映射(一对一的查询以及一对多)
- IOS 改变键盘颜色代码
- shell 计时
- linux下vi命令大全
- STM32定时器---正交编码器模式详解
- C++中拷贝构造函数的调用与C++返回值优化
- mybatis generator一对一映射,一对多映射,批量插入,批量更新
- [leetcode: Python]492.Construct the Rectangle
- Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 文件提前结束。
- js灵活性
- squid设置
- Android系统App中使用Leakcanary
- PHP阿里大于发短信教程
- 测试shell中使用map的小demo
- Redis系列(四)--内存淘汰机制(含单机版内存优化建议)