mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
a41aec3605
34
changes.md
34
changes.md
@ -1,6 +1,40 @@
|
||||
# MyBatis-Flex ChangeLog
|
||||
|
||||
|
||||
|
||||
## v1.5.5 20230801:
|
||||
- 新增:添加对 xml 分页查询的支持
|
||||
- 新增:逻辑删除添加列默认值为 null 值时的构建功能,感谢 @Suomm
|
||||
- 新增:QueryWrapper 添加 `clear()` 方法以复用,感谢 @yuanbaolong
|
||||
- 优化:添加更多的 QueryWrapper.select() 方法
|
||||
- 优化:添加全表更新或全部删除时的异常信息国际化
|
||||
- 优化:移除 Mappers.java 一些无用的代码
|
||||
- 优化:重构 ModifyAttrsRecordProxyFactory 以提升性能
|
||||
- 优化:重构 Page.java,默认使用 long 统一相关参数
|
||||
- 优化:对 ClassUtil/ConvertUtil 等一些工具类进行优化,感谢 @xinjump
|
||||
- 优化:代码生成器 ignoreColumns 变更为只对Entity生成有效果,感谢 @jerryzhengsz1
|
||||
- 优化:完善 Gitee 的 issue 模板配置,感谢 @Suomm
|
||||
- 优化:Relations 附加条件参数值修改为 Object 类型,感谢 @Suomm
|
||||
- 优化:重构 ActiveRecord 的关于关联查询的链式操作方法,感谢 @Suomm
|
||||
- 修复:修复游标查询时,配置 `@Column(typeHandler =xxx)` 不生生效的问题 #I7PNUL
|
||||
- 修复:修复达梦数据库数据大小写敏感的问题 #I7OYMN
|
||||
- 修复:UpdateChain.toSQL() 在某些情况下出错的问题
|
||||
- 修复:动态表名在 updateByQuery 中无效的问题
|
||||
- 修复:多数据源、且数据源加密的情况下,无法正确解析 jdbcUrl 的问题
|
||||
- 修复:数据解密器在某些场景下会多次触发解密的问题
|
||||
- 修复:逻辑删除配置为字符串时,多添加单引号的问题,感谢 @Suomm
|
||||
- 文档:添加自动映射的相关文档描述
|
||||
- 文档:打印 SQL 的相关文档添加 MyBatis 原生配置的方式
|
||||
- 文档:优化逻辑删除文档的一些代码展示示例有误的问题
|
||||
- 文档:添加 xml 分页查询的相关文档和示例
|
||||
- 文档:添加补充 Active Record 多种方式关联查询的文档,感谢 @Suomm
|
||||
- 文档:优化多数据源的代码配置展示,感谢 @lhzsdnu
|
||||
- 文档:修改链式操作的代码示例错误,感谢 @eltociear
|
||||
- 文档:修改 SQL 审计的相关错别字,感谢 @cijie
|
||||
- 文档:修改 MyBatisFlexCustomizer 文档的一些错别字,感谢 @q-alex
|
||||
|
||||
|
||||
|
||||
## v1.5.4 20230729:
|
||||
- 新增:UpdateChain.of(entity) 方法,方便直接传入 entity
|
||||
- 新增:TableInfo.buildQueryColumn() 方法,用于在泛型下构建 QueryColumn
|
||||
|
||||
@ -91,7 +91,7 @@ const {Layout} = DefaultTheme
|
||||
<div class="content">
|
||||
|
||||
<div class="banner">
|
||||
<a href="https://dromara.gitee.io/fast-request/" target="_blank"><img src="/assets/images/ad/fast-request-20230828.svg" style="width: 120px;height: 60px"></a>
|
||||
<a href="https://dromara.gitee.io/fast-request/" target="_blank"><img src="/assets/images/ad/fast-request-20230828.svg" style="width: 120px;height: 50px"></a>
|
||||
</div>
|
||||
<div class="banner">
|
||||
<a href="http://www.jpress.cn" target="_blank" style="height:50px;
|
||||
@ -105,6 +105,9 @@ const {Layout} = DefaultTheme
|
||||
<div class="banner">
|
||||
<a href="https://aigc.zijiantty.com" target="_blank"><img src="/assets/images/ad/zijiantty_20230827.png" style="width: 105px;height: 50px"></a>
|
||||
</div>
|
||||
<div class="banner">
|
||||
<a href="http://www.haorentech.com" target="_blank"><img src="/assets/images/ad/haorentech_20230901.png" style="width: 105px;height: 50px"></a>
|
||||
</div>
|
||||
<div class="banner">
|
||||
<a href="http://www.codeformat.cn" target="_blank"><img src="/assets/images/ad/code-format.png"></a>
|
||||
</div>
|
||||
@ -114,9 +117,6 @@ const {Layout} = DefaultTheme
|
||||
<div class="banner">
|
||||
虚以待位
|
||||
</div>
|
||||
<div class="banner">
|
||||
虚以待位
|
||||
</div>
|
||||
</div>
|
||||
<div class="banner-bottom">
|
||||
虚以待位
|
||||
|
||||
BIN
docs/assets/images/ad/haorentech_20230901.png
Normal file
BIN
docs/assets/images/ad/haorentech_20230901.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
@ -7,6 +7,7 @@
|
||||
| hh-vue | 这是基于ruoyi-vue改造的项目,对flex完整封装可以参考此项项目 | https://gitee.com/min290/hh-vue |
|
||||
| youcan-solon | 基于 solon 框架做的一个类似 Ruoyi 的项目,使用flex自带的 mybatis-flex-solon-plugin 插件做集成,集成方式非常简单,属于即拿即用 | https://gitee.com/gollyhu/youcan-solon |
|
||||
| Ruoyi-Flex | Ruoyi-Flex是基于RuoYi-Vue v3.8.6进行的扩展,集成MyBatis-Flex、JDK17、lombok、Sa-Token、PowerJob、Hutool、OSS、ureport-keep、Flowable、vue3、TypeScript等优秀开源软件。 | https://gitee.com/dataprince/ruoyi-flex |
|
||||
| 小鸣助手 |「小鸣助手」是一个生活服务类小程序,主要为用户的日常生活提供一些便捷工具,例如天气查询、时间规划、生活记录等。目前该小程序已稳定运行近4年,为近10万用户提供了生活帮助。主要技术栈:Spring Boot + Spring Security + JWT + MyBatis-Flex + MySQL + Redis + Docker | https://github.com/inlym/life-helper-server |
|
||||
|
||||
## 开发插件
|
||||
|
||||
|
||||
@ -1,21 +1,64 @@
|
||||
# 成为赞助者
|
||||
|
||||
MyBatis-Flex 是一个优雅的 MyBatis 增强框架,其开源于 2023 年,由于其友好的 API 设计和出色的性能,在极短的时间内被大众所知。
|
||||
我们为此投入了大量的时间和无限的热爱。
|
||||
MyBatis-Flex 是一个优雅的 MyBatis 增强框架,其开源于 2023 年,由于其友好的 API 设计和出色的性能,在极短的时间内被大众所知。 我们为此投入了大量的时间和无限的热爱。
|
||||
|
||||
由于 MyBatis-Flex 基于 Apache 开源协议,任何个人、企业和机构免费商用,但 MyBatis-Flex 的开发、维护和网站服务器的开支,对于我们的热爱造成了许多阻碍, 为此,我们寻求赞助,也为您的产品或品牌提供一个通过
|
||||
MyBatis-Flex 展示的机会。
|
||||
|
||||
由于 MyBatis-Flex 基于 Apache 开源协议,任何个人、企业和机构免费商用,但 MyBatis-Flex 的开发、维护和网站服务器的开支,对于我们的热爱造成了许多阻碍,
|
||||
为此,我们寻求赞助,也为您的产品或品牌提供一个通过 MyBatis-Flex 展示的机会。
|
||||
|
||||
**展示位赞助**
|
||||
|
||||
## 展示位赞助
|
||||
|
||||
在本站对应的位置放置您的 LOGO 及跳转链接。
|
||||
|
||||
| 位置 | 素材 | 宽高 | 赞助费 | 名额 |
|
||||
| 位置 | 素材 | 宽高 | 赞助费 | 名额 |
|
||||
| ---------------- | ---------------- | ------------- | ---------- |------------ |
|
||||
| 全站右侧边栏 1 | 图片+链接 | 105*50px | ¥200/月 | 8 |
|
||||
| 全站右侧边栏 2 | 图片+链接 | 122*50px | ¥400/月 |1 |
|
||||
|
||||
|
||||
您可以联系微信 `fuh99888` 就展示位的详细事宜。
|
||||
|
||||
## 无偿捐赠
|
||||
|
||||
您也可以通过 Gitee 平台为 MyBatis-Flex 提供无偿捐赠(请量力而行):
|
||||
|
||||
<a href="https://gitee.com/mybatis-flex/mybatis-flex?donate=true" class="VPButton medium brand" target="_blank">
|
||||
<img src="https://gitee.com/static/images/logo.svg" style="width: 80px;margin: 10px 0 -5px 6px" />
|
||||
通过 Gitee 捐赠
|
||||
</a>
|
||||
|
||||
|
||||
<style>
|
||||
|
||||
.VPButton {
|
||||
display: inline-block;
|
||||
border: 1px solid transparent;
|
||||
text-align: center;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
transition: color 0.25s, border-color 0.25s, background-color 0.25s;
|
||||
}
|
||||
|
||||
.VPButton.medium {
|
||||
border-radius: 20px;
|
||||
padding: 0 20px;
|
||||
line-height: 38px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.VPButton.brand {
|
||||
border-color: var(--vp-button-brand-border);
|
||||
color: var(--vp-button-brand-text);
|
||||
background-color: var(--vp-button-brand-bg);
|
||||
}
|
||||
|
||||
.VPButton.brand:hover {
|
||||
border-color: var(--vp-button-brand-hover-border);
|
||||
color: var(--vp-button-brand-hover-text);
|
||||
background-color: var(--vp-button-brand-hover-bg);
|
||||
text-decoration: inherit;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,6 +1,40 @@
|
||||
# MyBatis-Flex ChangeLog
|
||||
|
||||
|
||||
|
||||
## v1.5.5 20230801:
|
||||
- 新增:添加对 xml 分页查询的支持
|
||||
- 新增:逻辑删除添加列默认值为 null 值时的构建功能,感谢 @Suomm
|
||||
- 新增:QueryWrapper 添加 `clear()` 方法以复用,感谢 @yuanbaolong
|
||||
- 优化:添加更多的 QueryWrapper.select() 方法
|
||||
- 优化:添加全表更新或全部删除时的异常信息国际化
|
||||
- 优化:移除 Mappers.java 一些无用的代码
|
||||
- 优化:重构 ModifyAttrsRecordProxyFactory 以提升性能
|
||||
- 优化:重构 Page.java,默认使用 long 统一相关参数
|
||||
- 优化:对 ClassUtil/ConvertUtil 等一些工具类进行优化,感谢 @xinjump
|
||||
- 优化:代码生成器 ignoreColumns 变更为只对Entity生成有效果,感谢 @jerryzhengsz1
|
||||
- 优化:完善 Gitee 的 issue 模板配置,感谢 @Suomm
|
||||
- 优化:Relations 附加条件参数值修改为 Object 类型,感谢 @Suomm
|
||||
- 优化:重构 ActiveRecord 的关于关联查询的链式操作方法,感谢 @Suomm
|
||||
- 修复:修复游标查询时,配置 `@Column(typeHandler =xxx)` 不生生效的问题 #I7PNUL
|
||||
- 修复:修复达梦数据库数据大小写敏感的问题 #I7OYMN
|
||||
- 修复:UpdateChain.toSQL() 在某些情况下出错的问题
|
||||
- 修复:动态表名在 updateByQuery 中无效的问题
|
||||
- 修复:多数据源、且数据源加密的情况下,无法正确解析 jdbcUrl 的问题
|
||||
- 修复:数据解密器在某些场景下会多次触发解密的问题
|
||||
- 修复:逻辑删除配置为字符串时,多添加单引号的问题,感谢 @Suomm
|
||||
- 文档:添加自动映射的相关文档描述
|
||||
- 文档:打印 SQL 的相关文档添加 MyBatis 原生配置的方式
|
||||
- 文档:优化逻辑删除文档的一些代码展示示例有误的问题
|
||||
- 文档:添加 xml 分页查询的相关文档和示例
|
||||
- 文档:添加补充 Active Record 多种方式关联查询的文档,感谢 @Suomm
|
||||
- 文档:优化多数据源的代码配置展示,感谢 @lhzsdnu
|
||||
- 文档:修改链式操作的代码示例错误,感谢 @eltociear
|
||||
- 文档:修改 SQL 审计的相关错别字,感谢 @cijie
|
||||
- 文档:修改 MyBatisFlexCustomizer 文档的一些错别字,感谢 @q-alex
|
||||
|
||||
|
||||
|
||||
## v1.5.4 20230729:
|
||||
- 新增:UpdateChain.of(entity) 方法,方便直接传入 entity
|
||||
- 新增:TableInfo.buildQueryColumn() 方法,用于在泛型下构建 QueryColumn
|
||||
|
||||
@ -39,7 +39,7 @@ VALUES (1, '张三', 18, '2020-01-11'),
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-spring-boot-starter</artifactId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
|
||||
@ -12,12 +12,12 @@
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-core</artifactId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-processor</artifactId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
```
|
||||
@ -28,12 +28,12 @@
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-spring</artifactId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-processor</artifactId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
``````
|
||||
@ -44,12 +44,12 @@
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-spring-boot-starter</artifactId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-processor</artifactId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
```
|
||||
@ -70,7 +70,7 @@
|
||||
<path>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-processor</artifactId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# 使用 MyBatis 原生功能
|
||||
|
||||
我们使用 MyBatis-Flex 作为 MyBatis 的增强框架进行代码开发,并不会影响原有的 MyBatis 的任何功能。
|
||||
我们使用 MyBatis-Flex 作为 MyBatis 的增强框架进行代码开发,并不会影响原有的 MyBatis 的任何功能。
|
||||
|
||||
## 使用 `@Select` 等 MyBatis 原生注解
|
||||
|
||||
@ -43,7 +43,7 @@ public interface MyAccountMapper extends BaseMapper<Account> {
|
||||
xml:
|
||||
```xml
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.test.mapper.MyAccountMapper">
|
||||
|
||||
@ -53,4 +53,98 @@ xml:
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
```
|
||||
```
|
||||
|
||||
## XML 分页<Badge type="tip" text="^ v1.5.5" />
|
||||
|
||||
XML 分页是 MyBatis-Flex 在 v1.5.5 开始提供的一个 XML 分页解决方案,方便用户在使用 XML 时,对数据进行分页查询。
|
||||
|
||||
示例代码如下:
|
||||
|
||||
```java
|
||||
QueryWrapper qw = QueryWrapper.create()
|
||||
.where(Account::getAge).eq(18)
|
||||
.and(Account::getId).ge(0);
|
||||
|
||||
Page<Account> accountPage = ccountMapper
|
||||
.xmlPaginate("selectByName", Page.of(1, 10), qw);
|
||||
```
|
||||
|
||||
> 参数 `selectByName` 指的是在 XML 里定义的 select 节点的 id 的名称。`selectByName` 也可以全写为: `com.mybatisflex.test.mapper.AccountMapper.selectByName`。
|
||||
>
|
||||
> 此时,需要也在 XML 里定义名称为 `selectByName_COUNT` 的 select 节点,用于查询数据量。
|
||||
|
||||
XML 代码如下:
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.mybatisflex.test.mapper.AccountMapper">
|
||||
|
||||
<!-- selectByName -->
|
||||
<select id="selectByName" resultType="com.mybatisflex.test.model.Account">
|
||||
select * from `tb_account` ${qwSql} limit ${pageOffset}, ${pageSize}
|
||||
</select>
|
||||
|
||||
<select id="selectByName_COUNT" resultType="long">
|
||||
select count(*) from `tb_account` ${qwSql}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
```
|
||||
|
||||
其执行的 SQL 如下:
|
||||
|
||||
```sql
|
||||
-- 查询数据量
|
||||
select count(*) from `tb_account` WHERE `age` = 18 AND `id` >= 0
|
||||
|
||||
-- 查询数据
|
||||
select * from `tb_account` WHERE `age` = 18 AND `id` >= 0 limit 0, 10
|
||||
```
|
||||
|
||||
|
||||
**XML 参数解释:**
|
||||
|
||||
- **${qwSql}**: 传入的 QueryWrapper 生成的 where 部分的 SQL,带有 "`where`" 关键字
|
||||
- **${pageOffset}**: sql offset 的值
|
||||
- **${pageSize}**: 需要查询的数据量
|
||||
- **${pageNumber}**: 当前的页码
|
||||
- **${dbType}**: 当前用户配置的数据库类型,用户切换数据源也有可能造成数据库类型发生变化。我们可以通过不同的 dbType 来编写不同的 SQL,以适配不同的数据库类型。
|
||||
|
||||
**其他自定义参数:**
|
||||
|
||||
```java 6,7
|
||||
QueryWrapper qw = QueryWrapper.create()
|
||||
.where(Account::getAge).eq(18)
|
||||
.and(Account::getId).ge(0);
|
||||
|
||||
//设置其他参数
|
||||
Map<String,Object> otherParams = new HashMap<>();
|
||||
otherParams.put("otherName", "michael");
|
||||
|
||||
Page<Account> accountPage = ccountMapper
|
||||
.xmlPaginate("selectByName", Page.of(1, 10), qw, otherParams);
|
||||
```
|
||||
|
||||
此时,我们在 XML 中可以直接使用自定义的参数,例如:
|
||||
|
||||
```xml 8,14
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.mybatisflex.test.mapper.AccountMapper">
|
||||
|
||||
<!-- selectByName -->
|
||||
<select id="selectByName" resultType="com.mybatisflex.test.model.Account">
|
||||
select * from `tb_account` ${qwSql}
|
||||
and user_name = #{otherName}
|
||||
limit ${pageOffset}, ${pageSize}
|
||||
</select>
|
||||
|
||||
<select id="selectByName_COUNT" resultType="long">
|
||||
select count(*) from `tb_account` ${qwSql}
|
||||
and user_name = #{otherName}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
```
|
||||
|
||||
@ -220,7 +220,7 @@ pom.xml 添加 `annotationProcessorPaths` 配置,
|
||||
```
|
||||
dependencies {
|
||||
...
|
||||
annotationProcessor 'com.mybatis-flex:mybatis-flex-processor:<version>1.5.4</version>'
|
||||
annotationProcessor 'com.mybatis-flex:mybatis-flex-processor:<version>1.5.5</version>'
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-codegen</artifactId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@ -29,6 +29,9 @@ import com.mybatisflex.core.util.*;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import org.apache.ibatis.builder.annotation.ProviderContext;
|
||||
import org.apache.ibatis.cursor.Cursor;
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
@ -364,6 +367,7 @@ public interface BaseMapper<T> {
|
||||
/**
|
||||
* 执行类似 {@code update table set field = field + 1 where ... } 的场景。
|
||||
* TODO: 2023/7/27 该方法将在 v1.6.0 被删除
|
||||
*
|
||||
* @param fieldName 字段名
|
||||
* @param value 值(大于等于 0 加,小于 0 减)
|
||||
* @param queryWrapper 条件
|
||||
@ -377,6 +381,7 @@ public interface BaseMapper<T> {
|
||||
/**
|
||||
* 执行类似 {@code update table set field = field + 1 where ... } 的场景。
|
||||
* TODO: 该方法将在 v1.6.0 被删除
|
||||
*
|
||||
* @param column 字段名
|
||||
* @param value 值(大于等于 0 加,小于 0 减)
|
||||
* @param queryWrapper 条件
|
||||
@ -392,6 +397,7 @@ public interface BaseMapper<T> {
|
||||
/**
|
||||
* 执行类似 {@code update table set field = field + 1 where ... } 的场景。
|
||||
* TODO: 该方法将在 v1.6.0 被删除
|
||||
*
|
||||
* @param fn 字段名
|
||||
* @param value 值(大于等于 0 加,小于 0 减)
|
||||
* @param queryWrapper 条件
|
||||
@ -505,7 +511,8 @@ public interface BaseMapper<T> {
|
||||
|
||||
/**
|
||||
* 根据主表主键来查询 1 条数据。
|
||||
* @param id 表主键
|
||||
*
|
||||
* @param id 表主键
|
||||
* @param asType 接收数据类型
|
||||
* @return 实体类数据
|
||||
*/
|
||||
@ -517,6 +524,7 @@ public interface BaseMapper<T> {
|
||||
MappedStatementTypes.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据查询条件来查询 1 条数据。
|
||||
*
|
||||
@ -1117,4 +1125,44 @@ public interface BaseMapper<T> {
|
||||
return MapperUtil.doPaginate(this, page, queryWrapper, asType, true, consumers);
|
||||
}
|
||||
|
||||
|
||||
default <E> Page<E> xmlPaginate(String dataSelectId, Page<E> page, QueryWrapper queryWrapper) {
|
||||
return xmlPaginate(dataSelectId, dataSelectId + "_COUNT", page, queryWrapper, null);
|
||||
}
|
||||
|
||||
default <E> Page<E> xmlPaginate(String dataSelectId, Page<E> page, Map<String, Object> otherParams) {
|
||||
return xmlPaginate(dataSelectId, dataSelectId + "_COUNT", page, null, otherParams);
|
||||
}
|
||||
|
||||
default <E> Page<E> xmlPaginate(String dataSelectId, Page<E> page, QueryWrapper queryWrapper, Map<String, Object> otherParams) {
|
||||
return xmlPaginate(dataSelectId, dataSelectId + "_COUNT", page, queryWrapper, otherParams);
|
||||
}
|
||||
|
||||
default <E> Page<E> xmlPaginate(String dataSelectId, String countSelectId, Page<E> page, QueryWrapper queryWrapper, Map<String, Object> otherParams) {
|
||||
SqlSessionFactory sqlSessionFactory = FlexGlobalConfig.getDefaultConfig().getSqlSessionFactory();
|
||||
ExecutorType executorType = FlexGlobalConfig.getDefaultConfig().getConfiguration().getDefaultExecutorType();
|
||||
String mapperClassName = ClassUtil.getUsefulClass(this.getClass()).getName();
|
||||
|
||||
Map<String, Object> preparedParams = MapperUtil.preparedParams(page, queryWrapper, otherParams);
|
||||
if (!dataSelectId.contains(".")) {
|
||||
dataSelectId = mapperClassName + "." + dataSelectId;
|
||||
}
|
||||
|
||||
try (SqlSession sqlSession = sqlSessionFactory.openSession(executorType, false)) {
|
||||
if (page.getTotalRow() < 0) {
|
||||
if (!countSelectId.contains(".")) {
|
||||
countSelectId = mapperClassName + "." + countSelectId;
|
||||
}
|
||||
Number number = sqlSession.selectOne(countSelectId, preparedParams);
|
||||
page.setTotalRow(number);
|
||||
}
|
||||
|
||||
if (!page.isEmpty()) {
|
||||
List<E> entities = sqlSession.selectList(dataSelectId, preparedParams);
|
||||
page.setRecords(entities);
|
||||
}
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ public class FlexConsts {
|
||||
}
|
||||
|
||||
public static final String NAME = "MyBatis-Flex";
|
||||
public static final String VERSION = "1.5.4";
|
||||
public static final String VERSION = "1.5.5";
|
||||
|
||||
public static final String DEFAULT_PRIMARY_FIELD = "id";
|
||||
|
||||
|
||||
@ -196,5 +196,7 @@ public enum DbType {
|
||||
this.remarks = remarks;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,7 +171,7 @@ public class FlexConfiguration extends Configuration {
|
||||
}
|
||||
//entity select
|
||||
else if (StringUtil.endsWithAny(ms.getId(), "selectOneById", "selectListByIds"
|
||||
, "selectListByQuery")) {
|
||||
, "selectListByQuery", "selectCursorByQuery")) {
|
||||
ms = replaceResultMap(ms, getTableInfo(ms));
|
||||
}
|
||||
|
||||
|
||||
@ -193,7 +193,7 @@ public class Page<T> implements Serializable {
|
||||
* @param pageSize 每页数据数量
|
||||
*/
|
||||
public void setPageSize(Number pageSize) {
|
||||
if (pageSize.longValue() < 0) {
|
||||
if (pageSize == null || pageSize.longValue() < 0) {
|
||||
throw new IllegalArgumentException("pageSize must greater than or equal 0,current value is: " + pageSize);
|
||||
}
|
||||
this.pageSize = pageSize.longValue();
|
||||
@ -233,7 +233,7 @@ public class Page<T> implements Serializable {
|
||||
* @param totalRow 数据总数
|
||||
*/
|
||||
public void setTotalRow(Number totalRow) {
|
||||
this.totalRow = totalRow.longValue();
|
||||
this.totalRow = totalRow == null ? INIT_VALUE : totalRow.longValue();
|
||||
this.calcTotalPage();
|
||||
}
|
||||
|
||||
|
||||
@ -49,6 +49,30 @@ public class BaseQueryWrapper<T extends BaseQueryWrapper<T>> implements CloneSup
|
||||
|
||||
// protected boolean ignoreBlankStrings = false;
|
||||
|
||||
/**
|
||||
* <p>Title: clear. </p>
|
||||
* <p>Description: Default QueryWrapper values. </p>
|
||||
* <p>Notice: When adding new attributes, it is necessary to supplement here. </p>
|
||||
* @author dragon
|
||||
*/
|
||||
public void clear() {
|
||||
this.with = null;
|
||||
this.queryTables = null;
|
||||
this.dataSource = null;
|
||||
this.hint = null;
|
||||
this.selectColumns = null;
|
||||
this.joins = null;
|
||||
this.joinTables = null;
|
||||
this.whereQueryCondition = null;
|
||||
this.groupByColumns = null;
|
||||
this.havingQueryCondition = null;
|
||||
this.orderBys = null;
|
||||
this.unions = null;
|
||||
this.limitOffset = null;
|
||||
this.limitRows = null;
|
||||
this.endFragments = null;
|
||||
this.context = null;
|
||||
}
|
||||
|
||||
protected T addSelectColumn(QueryColumn queryColumn) {
|
||||
if (selectColumns == null) {
|
||||
|
||||
@ -16,7 +16,10 @@
|
||||
package com.mybatisflex.core.util;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.mybatisflex.core.FlexGlobalConfig;
|
||||
import com.mybatisflex.core.constant.SqlConsts;
|
||||
import com.mybatisflex.core.dialect.DbType;
|
||||
import com.mybatisflex.core.dialect.DialectFactory;
|
||||
import com.mybatisflex.core.exception.FlexExceptions;
|
||||
import com.mybatisflex.core.field.FieldQuery;
|
||||
import com.mybatisflex.core.field.FieldQueryBuilder;
|
||||
@ -254,4 +257,60 @@ public class MapperUtil {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Map<String, Object> preparedParams(Page<?> page, QueryWrapper queryWrapper, Map<String, Object> params) {
|
||||
Map<String, Object> newParams = new HashMap<>();
|
||||
|
||||
if (params != null) {
|
||||
newParams.putAll(params);
|
||||
}
|
||||
|
||||
newParams.put("pageOffset", page.offset());
|
||||
newParams.put("pageNumber", page.getPageNumber());
|
||||
newParams.put("pageSize", page.getPageSize());
|
||||
|
||||
DbType dbType = DialectFactory.getHintDbType();
|
||||
newParams.put("dbType", dbType != null ? dbType : FlexGlobalConfig.getDefaultConfig().getDbType());
|
||||
|
||||
if (queryWrapper != null) {
|
||||
preparedQueryWrapper(newParams, queryWrapper);
|
||||
}
|
||||
|
||||
return newParams;
|
||||
}
|
||||
|
||||
|
||||
private static void preparedQueryWrapper(Map<String, Object> params, QueryWrapper queryWrapper) {
|
||||
String sql = DialectFactory.getDialect().buildNoSelectSql(queryWrapper);
|
||||
StringBuilder sqlBuilder = new StringBuilder();
|
||||
char quote = 0;
|
||||
int index = 0;
|
||||
for (int i = 0; i < sql.length(); ++i) {
|
||||
char ch = sql.charAt(i);
|
||||
if (ch == '\'') {
|
||||
if (quote == 0) {
|
||||
quote = ch;
|
||||
} else if (quote == '\'') {
|
||||
quote = 0;
|
||||
}
|
||||
} else if (ch == '"') {
|
||||
if (quote == 0) {
|
||||
quote = ch;
|
||||
} else if (quote == '"') {
|
||||
quote = 0;
|
||||
}
|
||||
}
|
||||
if (quote == 0 && ch == '?') {
|
||||
sqlBuilder.append("#{qwParams_").append(index++).append("}");
|
||||
} else {
|
||||
sqlBuilder.append(ch);
|
||||
}
|
||||
}
|
||||
params.put("qwSql", sqlBuilder.toString());
|
||||
Object[] valueArray = CPI.getValueArray(queryWrapper);
|
||||
for (int i = 0; i < valueArray.length; i++) {
|
||||
params.put("qwParams_" + i, valueArray[i]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>mybatis-flex-test</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@ public class Account extends BaseEntity implements Serializable, AgeAware {
|
||||
@NotBlank
|
||||
private Date birthday;
|
||||
|
||||
@Column(typeHandler = Fastjson2TypeHandler.class, isLarge = true)
|
||||
@Column(typeHandler = Fastjson2TypeHandler.class)
|
||||
private Map<String, Object> options;
|
||||
|
||||
@Column(isLogicDelete = true)
|
||||
|
||||
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mybatisflex.test;
|
||||
|
||||
import com.mybatisflex.core.MybatisFlexBootstrap;
|
||||
import com.mybatisflex.core.audit.AuditManager;
|
||||
import com.mybatisflex.core.audit.ConsoleMessageCollector;
|
||||
import com.mybatisflex.core.audit.MessageCollector;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.row.Db;
|
||||
import com.mybatisflex.core.row.RowUtil;
|
||||
import org.apache.ibatis.cursor.Cursor;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mybatisflex.test.table.AccountTableDef.ACCOUNT;
|
||||
import static com.mybatisflex.test.table.ArticleTableDef.ARTICLE;
|
||||
|
||||
public class CursorTestStarter {
|
||||
|
||||
public static void main(String[] args) {
|
||||
DataSource dataSource = new EmbeddedDatabaseBuilder()
|
||||
.setType(EmbeddedDatabaseType.H2)
|
||||
.addScript("schema.sql")
|
||||
.addScript("data.sql")
|
||||
.build();
|
||||
|
||||
MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance()
|
||||
.setDataSource(dataSource)
|
||||
.addMapper(AccountMapper.class)
|
||||
.addMapper(MyAccountMapper.class)
|
||||
.start();
|
||||
|
||||
//开启审计功能
|
||||
AuditManager.setAuditEnable(true);
|
||||
|
||||
//设置 SQL 审计收集器
|
||||
MessageCollector collector = new ConsoleMessageCollector();
|
||||
AuditManager.setMessageCollector(collector);
|
||||
|
||||
|
||||
AccountMapper accountMapper = bootstrap.getMapper(AccountMapper.class);
|
||||
|
||||
List<Account> accounts = accountMapper.selectAll();
|
||||
System.out.println(accounts);
|
||||
|
||||
QueryWrapper asWrapper = QueryWrapper.create()
|
||||
.select(ARTICLE.ALL_COLUMNS, ACCOUNT.ALL_COLUMNS)
|
||||
.from(ARTICLE)
|
||||
.leftJoin(ACCOUNT).on(ARTICLE.ACCOUNT_ID.eq(ACCOUNT.ID))
|
||||
.where(ARTICLE.ID.ge(0).or(ACCOUNT.ID.ge(0)));
|
||||
|
||||
RowUtil.printPretty(Db.selectListByQuery(asWrapper));
|
||||
|
||||
Db.tx(() -> {
|
||||
Cursor<Account> accountCursor = accountMapper.selectCursorByQuery(asWrapper);
|
||||
for (Account account : accountCursor) {
|
||||
System.out.println(account);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
INSERT INTO tb_account
|
||||
VALUES (1, '张三', 18, 0,'2020-01-11', null,0),
|
||||
(2, '王麻子叔叔', 19, 1, '2021-03-21', null,0);
|
||||
VALUES (1, '张三', 18, 0,'2020-01-11', '{"key":"value1"}',0),
|
||||
(2, '王麻子叔叔', 19, 1, '2021-03-21', '{"key":"value2"}',0);
|
||||
|
||||
|
||||
INSERT INTO tb_article
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>mybatis-flex-test</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@ -56,8 +56,15 @@ public class AccountController {
|
||||
|
||||
|
||||
@GetMapping("/account/byName/{name}")
|
||||
AccountDto selectName(@PathVariable("name") String name) {
|
||||
return myAccountMapper.selectByName(name);
|
||||
Page<AccountDto> selectName(@PathVariable("name") String name) {
|
||||
// return myAccountMapper.selectByName(name);
|
||||
|
||||
QueryWrapper qw = QueryWrapper.create()
|
||||
.where(Account::getAge).eq(18)
|
||||
.and(Account::getId).ge(0);
|
||||
|
||||
Page<AccountDto> accountPage = myAccountMapper.xmlPaginate("selectByName", Page.of(1, 10), qw);
|
||||
return accountPage;
|
||||
}
|
||||
|
||||
|
||||
@ -106,7 +113,6 @@ public class AccountController {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/ds")
|
||||
@UseDataSource("ds2222")
|
||||
public String ds() {
|
||||
|
||||
@ -17,14 +17,13 @@
|
||||
package com.mybatisflex.test.mapper;
|
||||
|
||||
import com.mybatisflex.test.model.Account;
|
||||
import com.mybatisflex.test.model.AccountDto;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
public interface MyAccountMapper extends AccountMapper {
|
||||
|
||||
|
||||
AccountDto selectByName(@Param("name") String name);
|
||||
// AccountDto selectByName(@Param("name") String name);
|
||||
|
||||
@Select("select * from tb_account where id = #{id} and id =#{id}")
|
||||
Account selectById(@Param("id") Object id);
|
||||
|
||||
@ -7,7 +7,7 @@ spring:
|
||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/flex_test
|
||||
username: root
|
||||
password: 12345678
|
||||
password: 123456
|
||||
# driver-class-name:
|
||||
# datasource:
|
||||
# driver-class-name: org.h2.Driver
|
||||
|
||||
@ -19,7 +19,11 @@
|
||||
|
||||
<!-- selectByName -->
|
||||
<select id="selectByName" resultType="com.mybatisflex.test.model.AccountDto">
|
||||
select * from `tb_account` where `user_name` = #{name}
|
||||
select * from `tb_account` ${qwSql} limit ${pageOffset}, ${pageSize}
|
||||
</select>
|
||||
|
||||
<select id="selectByName_COUNT" resultType="long">
|
||||
select count(*) from `tb_account` ${qwSql}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>mybatis-flex-test</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>mybatis-flex-test</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
4
pom.xml
4
pom.xml
@ -7,7 +7,7 @@
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.5</version>
|
||||
|
||||
<name>mybatis-flex</name>
|
||||
<url>https://mybatis-flex.com</url>
|
||||
@ -54,7 +54,7 @@
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
|
||||
<mybatis-flex.version>1.5.4</mybatis-flex.version>
|
||||
<mybatis-flex.version>1.5.5</mybatis-flex.version>
|
||||
|
||||
<mybatis.version>3.5.13</mybatis.version>
|
||||
<mybatis-spring.version>2.1.0</mybatis-spring.version>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user