博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MyBatis 之逆向工程生成MyBatis的mapper、xml、pojo
阅读量:2455 次
发布时间:2019-05-10

本文共 3230 字,大约阅读时间需要 10 分钟。

文章目录

mybatis-generator 概述

MyBatis官方提供了逆向工程 mybatis-generator,可以针对数据库表自动生成MyBatis执行所需要的代码(如Mapper.java、Mapper.xml、POJO)。mybatis-generator 有三种用法:命令行、eclipse插件、maven插件。

pom.xml中配置plugin

org.mybatis.generator
mybatis-generator-maven-plugin
1.3.2
src/main/resources/generatorConfig.xml
true
true
Generate MyBatis Artifacts
generate
org.mybatis.generator
mybatis-generator-core
1.3.2
mysql
mysql-connector-java
5.1.40

generatorConfig.xml配置文件

使用插件生成代码

在这里插入图片描述

生成Example类

这些参数改成true。

enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"

使用Example

案例1:

TestTableExample example = new TestTableExample();example.or().andField1EqualTo(5).andField2IsNull();example.or().andField3NotEqualTo(9).andField4IsNotNull();List field5Values = new ArrayList();field5Values.add(8);field5Values.add(11);field5Values.add(14);field5Values.add(22);example.or().andField5In(field5Values);example.or().andField6Between(3, 7);

在上面的例子中,,动态生成的where子句是:

where (field1 = 5 and field2 is null) or (field3 <> 9 and field4 is not null) or (field5 in (8, 11, 14, 22)) or (field6 between 3 and 7)

案例2:

PsbcDiscountQualificationGpExample example = new PsbcDiscountQualificationGpExample();example.setOrderByClause("id asc");PsbcDiscountQualificationGpExample.Criteria criteria = example.createCriteria();criteria.andAreaIdEqualTo(new BigDecimal("333")).andAreaIdIsNotNull();psbcDiscountQualificationGpMapper.selectByExample(example);

动态生成的where子句是:

WHERE ( area_id = 333 and area_id is not null ) order by id asc

案例3:

PsbcDiscountQualificationGpExample example = new PsbcDiscountQualificationGpExample();PsbcDiscountQualificationGpExample.Criteria criteria1 = example.createCriteria();PsbcDiscountQualificationGpExample.Criteria criteria2 = example.createCriteria();criteria1.andAreaIdIsNotNull();criteria2.andIdEqualTo(new BigDecimal("111"));example.or(criteria2);psbcDiscountQualificationGpMapper.selectByExample(example);

动态生成的where子句是:

WHERE ( area_id is not null ) or( id = 111 )

在这里插入图片描述

参考:

https://www.cnblogs.com/liaojie970/p/7058543.html
https://blog.csdn.net/weixin_42231507/article/details/80714719
https://www.cnblogs.com/deng-cc/p/9340748.html

你可能感兴趣的文章
linkedin开源列表_Google的新容器项目,LinkedIn上的开源代码,Raspberry Pi B +,等等
查看>>
openstack项目_软件定义的经济,OpenStack的新孵化项目等
查看>>
git项目中的子git项目_使用子模块和子树管理Git项目
查看>>
sh脚本和bash脚本_使用此简单的Bash脚本在家打印双面文档
查看>>
raspberry pi_使用Raspberry Pi构建感知假肢
查看>>
raspberry pi_一个方便的实用程序,用于创建Raspberry Pi SD卡图像
查看>>
盲打每分钟资源10几个字_每个系统管理员应了解的10个资源
查看>>
横向扩展基础架构_您应该使用的7种基础架构性能和扩展工具
查看>>
bbc 王超_BBC Microbit入门
查看>>
sysadmin默认密码_Sysadmin感谢日的礼物想法
查看>>
如何在Kubernetes上找到您的Jenkins管理员密码
查看>>
c++编写音乐播放器_为什么此开发人员编写了快速响应的音乐播放器
查看>>
github pages_使用此HTTP hack重定向GitHub Pages网站
查看>>
python tox_使用tox自动化Python代码测试
查看>>
python cython_使用Cython为Python编写更快的C扩展
查看>>
flake8变量未使用_使用flake8确保Python代码的一致性
查看>>
ssh与gpg区别_如何使用GPG密钥启用SSH访问进行身份验证
查看>>
apm 韩国开源项目_韩国的开源状态
查看>>
mac上将视频变小_在Mac上将Python 3设置为默认的正确和错误方法
查看>>
java jnlp_Java SE 11删除JNLP的更好解决方案
查看>>