mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
Merge branch 'main' of https://github.com/farukonfly/mybatis-flex
This commit is contained in:
commit
ab5a21a450
@ -7,7 +7,7 @@ body:
|
||||
attributes:
|
||||
label: 这个 Bug 是否已经存在:
|
||||
options:
|
||||
- label: 我确定已经把 MyBatis-Flex 升级到最新版本 v1.7.6,并已搜索过现有的问题 (https://gitee.com/mybatis-flex/mybatis-flex/issues)
|
||||
- label: 我确定已经把 MyBatis-Flex 升级到最新版本 v1.7.7,并已搜索过现有的问题 (https://gitee.com/mybatis-flex/mybatis-flex/issues)
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
|
||||
@ -13,7 +13,7 @@ body:
|
||||
attributes:
|
||||
label: 这个问题是否已经存在:
|
||||
options:
|
||||
- label: 我确定已经把 MyBatis-Flex 升级到最新版本 v1.7.6,并已搜索过现有的问题 (https://gitee.com/mybatis-flex/mybatis-flex/issues)
|
||||
- label: 我确定已经把 MyBatis-Flex 升级到最新版本 v1.7.7,并已搜索过现有的问题 (https://gitee.com/mybatis-flex/mybatis-flex/issues)
|
||||
required: true
|
||||
- type: textarea
|
||||
id: question-description
|
||||
|
||||
16
changes.md
16
changes.md
@ -2,6 +2,22 @@
|
||||
|
||||
查看 [全部代码贡献者](/zh/intro/what-is-mybatisflex.html#贡献者)。
|
||||
|
||||
|
||||
## v1.7.7 20240104:
|
||||
- 新增:添加 spring-boot3 新模块,用于 springboot v3 下使用,感谢 @Suomm
|
||||
- 新增:QueryMethods 添加 NOT (column) 函数,感谢 @wittplus
|
||||
- 优化:更新 Solon 下的 @ProxyComponent 为 @Component,感谢 @citysoft
|
||||
- 优化:修改 com.mybatisflex.annotation.SetListener 的注释错误,感谢 @whzzone
|
||||
- 优化:修改 GBase_8s 数据库类型 sql 语句无反义处理
|
||||
- 优化:升级 MyBatis 到 3.5.15 最新版本 #I8PQLC
|
||||
- 修复:IService.getOne 没有添加 limit 1 的问题
|
||||
- 修复:Db.updateEntitiesBatch 更新部分字段时报错的问题,感谢 @617054137
|
||||
- 文档:更新在 Kotlin 下使用的相关文档,感谢 @kamo-sama
|
||||
- 文档:优化示例代码提交语言标识,感谢 @bf109f
|
||||
- 文档:更新存在一个为 is_deleted 的字段中拼写错误,感谢 @shuangtao
|
||||
|
||||
|
||||
|
||||
## v1.7.6 20231223:
|
||||
- 新增:Db.selectFirstAndSecondColumnsAsMap 方法:查询结果的第一列作为 key,第二列作为 value,感谢 @617054137
|
||||
- 新增:方言添加添加权限处理统一入口 prepareAuth,感谢 @bf109f
|
||||
|
||||
@ -78,8 +78,8 @@ const {Layout} = DefaultTheme
|
||||
<!--docs: https://vitepress.dev/guide/extending-default-theme#layout-slots-->
|
||||
<template #doc-before>
|
||||
<div style="margin-bottom: 30px">
|
||||
<a href="https://aieditor.dev" target="_blank">
|
||||
<img src="/assets/images/ad/doc-banner.jpg">
|
||||
<a href="https://mp.weixin.qq.com/s/V34VkARgBCBKdytSlKhosg" target="_blank">
|
||||
<img src="/assets/images/ad/admin-banner.jpg">
|
||||
</a>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@ -1,12 +1,8 @@
|
||||
:root {
|
||||
--vp-c-brand: #F06C33;
|
||||
--vp-c-brand-light: #FFCC00;
|
||||
--vp-c-brand-lighter: #FFCC99;
|
||||
--vp-c-brand-dark: #FF9933;
|
||||
--vp-c-brand-darker: #CC6600;
|
||||
|
||||
--vp-custom-block-tip-border: #FFCC99;
|
||||
--vp-custom-block-tip-text: #F06C33;
|
||||
--vp-c-brand-1:#F06C33;
|
||||
--vp-home-hero-name-color:#F06C33;
|
||||
--vp-button-brand-bg:#F06C33;
|
||||
--vp-button-brand-hover-bg:#ff986b;
|
||||
}
|
||||
|
||||
.vp-doc .custom-block p {
|
||||
|
||||
BIN
docs/assets/images/ad/admin-banner.jpg
Normal file
BIN
docs/assets/images/ad/admin-banner.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 80 KiB |
@ -1,11 +1,11 @@
|
||||
{
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"docs:dev": "vitepress dev",
|
||||
"docs:build": "vitepress build",
|
||||
"docs:preview": "vitepress preview"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vitepress": "^1.0.0-beta.3 "
|
||||
}
|
||||
"scripts": {
|
||||
"docs:dev": "vitepress dev",
|
||||
"docs:build": "vitepress build",
|
||||
"docs:preview": "vitepress preview"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vitepress": "^1.0.0-rc.32"
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,10 +9,10 @@ MyBatis-Flex 展示的机会。
|
||||
|
||||
在本站对应的位置放置您的 LOGO 及跳转链接。
|
||||
|
||||
| 位置 | 素材 | 宽高 | 赞助费 | 名额 |
|
||||
| ---------------- | ---------------- | ------------- | ---------- |------------ |
|
||||
| 全站右侧边栏 1 | 图片+链接 | 105*50px | ¥200/月 | 8 |
|
||||
| 全站右侧边栏 2 | 图片+链接 | 122*50px | ¥400/月 |1 |
|
||||
| 位置 | 素材 | 宽高 | 赞助费 | 名额 |
|
||||
| ---------------- | ---------------- |----------| ---------- |----|
|
||||
| 全站右侧边栏 1 | 图片+链接 | 105*50px | ¥200/月 | 8 |
|
||||
| 全站右侧边栏 2 | 图片+链接 | 222*50px | ¥400/月 | 1 |
|
||||
|
||||
您可以联系微信 `fuh99888` 就展示位的详细事宜。
|
||||
|
||||
|
||||
@ -2,6 +2,22 @@
|
||||
|
||||
查看 [全部代码贡献者](/zh/intro/what-is-mybatisflex.html#贡献者)。
|
||||
|
||||
|
||||
## v1.7.7 20240104:
|
||||
- 新增:添加 spring-boot3 新模块,用于 springboot v3 下使用,感谢 @Suomm
|
||||
- 新增:QueryMethods 添加 NOT (column) 函数,感谢 @wittplus
|
||||
- 优化:更新 Solon 下的 @ProxyComponent 为 @Component,感谢 @citysoft
|
||||
- 优化:修改 com.mybatisflex.annotation.SetListener 的注释错误,感谢 @whzzone
|
||||
- 优化:修改 GBase_8s 数据库类型 sql 语句无反义处理
|
||||
- 优化:升级 MyBatis 到 3.5.15 最新版本 #I8PQLC
|
||||
- 修复:IService.getOne 没有添加 limit 1 的问题
|
||||
- 修复:Db.updateEntitiesBatch 更新部分字段时报错的问题,感谢 @617054137
|
||||
- 文档:更新在 Kotlin 下使用的相关文档,感谢 @kamo-sama
|
||||
- 文档:优化示例代码提交语言标识,感谢 @bf109f
|
||||
- 文档:更新存在一个为 is_deleted 的字段中拼写错误,感谢 @shuangtao
|
||||
|
||||
|
||||
|
||||
## v1.7.6 20231223:
|
||||
- 新增:Db.selectFirstAndSecondColumnsAsMap 方法:查询结果的第一列作为 key,第二列作为 value,感谢 @617054137
|
||||
- 新增:方言添加添加权限处理统一入口 prepareAuth,感谢 @bf109f
|
||||
|
||||
@ -119,7 +119,7 @@ public class AuthDialectImpl extends CommonsDialectImpl {
|
||||
对`QueryWrapper`的表做筛选可参考 **方式1**
|
||||
在项目启动时通过 `DialectFactory` 注册 `AuthDialectImpl`,以spring boot项目为例:
|
||||
|
||||
```
|
||||
```java
|
||||
@Configuration
|
||||
public class MybatisFlexConfig implements MyBatisFlexCustomizer {
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
|
||||
## MyBatis-Flex 逻辑删除示例
|
||||
|
||||
假设在 tb_account 表中,存在一个为 is_deleted 的字段,用来标识该数据的逻辑删除,那么 tb_account 表
|
||||
假设在 tb_account 表中,存在一个为 is_delete 的字段,用来标识该数据的逻辑删除,那么 tb_account 表
|
||||
对应的 "Account.java" 实体类应该配置如下:
|
||||
|
||||
```java
|
||||
|
||||
@ -57,12 +57,11 @@ VALUES (1, '张三', 18, '2020-01-11'),
|
||||
需要添加的 Maven 主要依赖示例:
|
||||
|
||||
```xml
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-spring-boot-starter</artifactId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
@ -82,6 +81,35 @@ VALUES (1, '张三', 18, '2020-01-11'),
|
||||
</dependencies>
|
||||
```
|
||||
|
||||
**注意**: 如果您当前使用的是 SpringBoot v3.x 版本,需要把依赖 `mybatis-flex-spring-boot-starter` 修改为:`mybatis-flex-spring-boot3-starter`,
|
||||
如下代码所示:
|
||||
|
||||
```xml 4
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-spring-boot3-starter</artifactId>
|
||||
<version>1.7.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
</dependency>
|
||||
<!-- for test only -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
|
||||
|
||||
**第 3 步:对 Spring Boot 项目进行配置**
|
||||
|
||||
在 application.yml 中配置数据源:
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
|
||||
```kotlin
|
||||
dependencies {
|
||||
implementation("com.mybatis-flex:mybatis-flex-core:1.7.6")
|
||||
implementation("com.mybatis-flex:mybatis-flex-core:1.7.7")
|
||||
}
|
||||
```
|
||||
|
||||
@ -18,7 +18,7 @@ dependencies {
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'com.mybatis-flex:mybatis-flex-core:1.7.6'
|
||||
implementation 'com.mybatis-flex:mybatis-flex-core:1.7.7'
|
||||
}
|
||||
```
|
||||
|
||||
@ -28,7 +28,7 @@ dependencies {
|
||||
|
||||
```kotlin
|
||||
dependencies {
|
||||
implementation("com.mybatis-flex:mybatis-flex-spring:1.7.6")
|
||||
implementation("com.mybatis-flex:mybatis-flex-spring:1.7.7")
|
||||
}
|
||||
```
|
||||
|
||||
@ -36,7 +36,7 @@ dependencies {
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'com.mybatis-flex:mybatis-flex-spring:1.7.6'
|
||||
implementation 'com.mybatis-flex:mybatis-flex-spring:1.7.7'
|
||||
}
|
||||
```
|
||||
|
||||
@ -46,7 +46,7 @@ dependencies {
|
||||
|
||||
```kotlin
|
||||
dependencies {
|
||||
implementation("com.mybatis-flex:mybatis-flex-spring-boot-starter:1.7.6")
|
||||
implementation("com.mybatis-flex:mybatis-flex-spring-boot-starter:1.7.7")
|
||||
}
|
||||
```
|
||||
|
||||
@ -54,7 +54,7 @@ dependencies {
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'com.mybatis-flex:mybatis-flex-spring-boot-starter:1.7.6'
|
||||
implementation 'com.mybatis-flex:mybatis-flex-spring-boot-starter:1.7.7'
|
||||
}
|
||||
```
|
||||
|
||||
@ -70,7 +70,7 @@ dependencies {
|
||||
|
||||
```kotlin
|
||||
dependencies {
|
||||
annotationProcessor("com.mybatis-flex:mybatis-flex-processor:1.7.6")
|
||||
annotationProcessor("com.mybatis-flex:mybatis-flex-processor:1.7.7")
|
||||
}
|
||||
```
|
||||
|
||||
@ -78,6 +78,6 @@ dependencies {
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
annotationProcessor 'com.mybatis-flex:mybatis-flex-processor:1.7.6'
|
||||
annotationProcessor 'com.mybatis-flex:mybatis-flex-processor:1.7.7'
|
||||
}
|
||||
```
|
||||
|
||||
@ -12,12 +12,12 @@
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-core</artifactId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-processor</artifactId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
```
|
||||
@ -28,33 +28,49 @@
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-spring</artifactId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-processor</artifactId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
``````
|
||||
|
||||
3、用到了 Spring Boot 的场景
|
||||
3、用到了 SpringBoot v2.x 的场景
|
||||
|
||||
```xml
|
||||
```xml 3
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-spring-boot-starter</artifactId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-processor</artifactId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
4、配置 annotationProcessor
|
||||
4、用到了 SpringBoot v3.x 的场景
|
||||
|
||||
```xml 3
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-spring-boot3-starter</artifactId>
|
||||
<version>1.7.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-processor</artifactId>
|
||||
<version>1.7.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
5、配置 annotationProcessor
|
||||
|
||||
`mybatis-flex-processor`提供APT服务,可以配置到annotationProcessorPaths,配置后,无需在依赖中声明`mybatis-flex-processor`依赖。
|
||||
|
||||
@ -72,14 +88,14 @@
|
||||
<path>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-processor</artifactId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
```
|
||||
|
||||
5、配置依赖管理
|
||||
6、配置依赖管理
|
||||
|
||||
MyBatis-Flex 提供了 `mybatis-flex-dependencies` 模块进行依赖管理,只需要在 `<dependencyManagement>` 标签下进行配置就可以了。
|
||||
|
||||
|
||||
@ -1,23 +1,28 @@
|
||||
| | | | | |
|
||||
|-----|-----|-----|-----|-----|
|
||||
|Michael Yang|王帅|丌冰|卡莫sama|life|
|
||||
|snyk-bot|lhzsdnu|西东|Font_C|pengpeng|
|
||||
|庄佳彬|Ice-samll|guanmengyuan|王超|笨小孩|
|
||||
|chenjh3|CloudPlayer|Jerry|snow|草语|
|
||||
|李楠|菜鸟3853|Jerry_Zheng|tangxin|wujl|
|
||||
|piggsoft|赤兮丷|黄沐鸿|loong0306|沈君锋|
|
||||
|英雄路|natsufumij|aqnghu|BQ60ziOxlFI0R0|tan90|
|
||||
|张继续|font-C|liibang|cainiao3853|barql|
|
||||
|yangs|Robot.L|落羽er|qixy|yuanbaolong|
|
||||
|handy|zhijieqing|Saoforest|bygkn|XiaoLin|
|
||||
|zhongyong|锟斤拷|Watcher.Wang|yang_zzu|锁力|
|
||||
|shaoerkuai|阿志同学|chenjian835|Haru|duxlei|
|
||||
|豌豆粉|matthew|凌尘|luy|gongzhongqiang|
|
||||
|Alex|EafonYoung|Pioneer-Sun|Q_Alex|wlf|
|
||||
|CrazyAirhead|winnerself|她出去赚钱了|数据小王子|XiaoLin|
|
||||
|Freeman Liu|大周|欢乐码农|2han9wen71an|Shark|
|
||||
|庄佳彬|hans|HunnyOvO|关梦园|lcxw|
|
||||
|dgmico|Ikko Eltociear Ashimine|wanggaoquan|Aohan-Zhang|老吉丶|
|
||||
|玩具猫|meng.liu3|yaochen4|zhy_black|ζั͡ ั͡ ั͡ ั͡Wm|
|
||||
|陈国正|ZhuHJay|zoufang162|乌鸦笑猪黑|wnp|
|
||||
|Michael Yang|王帅|卡莫sama|丌冰|life|
|
||||
|snyk-bot|lhzsdnu|西东|tangxin|Font_C|
|
||||
|pengpeng|庄佳彬|Ice-samll|guanmengyuan|王超|
|
||||
|笨小孩|bf109f|chenjh3|CloudPlayer|Jerry|
|
||||
|snow|草语|farukonfly|李楠|菜鸟3853|
|
||||
|mofan|Jerry_Zheng|wujl|Martin7-1|piggsoft|
|
||||
|赤兮丷|黄沐鸿|loong0306|沈君锋|英雄路|
|
||||
|natsufumij|BQ60ziOxlFI0R0|tan90|aqnghu|张继续|
|
||||
|font-C|liibang|cainiao3853|barql|yangs|
|
||||
|lcxw|Robot.L|落羽er|Faputa|qixy|
|
||||
|yuanbaolong|zhijieqing|handy|bygkn|Saoforest|
|
||||
|唐振超|Watcher.Wang|锟斤拷|zhongyong|XiaoLin|
|
||||
|yang_zzu|锁力|shaoerkuai|meichenhui|阿志同学|
|
||||
|chenjian835|Haru|duxlei|豌豆粉|涛声依旧|
|
||||
|matthew|gongzhongqiang|luy|凌尘|Alex|
|
||||
|EafonYoung|Pioneer-Sun|Q_Alex|wlf|1332987|
|
||||
|Lionel|winnerself|CrazyAirhead|她出去赚钱了|数据小王子|
|
||||
|XiaoLin|丿风轻灬云淡|张博|Freeman Liu|大周|
|
||||
|欢乐码农|2han9wen71an|shark771|庄佳彬|_FLOW__|
|
||||
|weihuazhou|hans|Ikko Eltociear Ashimine|guanmengyuan|dgmico|
|
||||
|HunnyOvO|wanggaoquan|Aohan-Zhang|老吉丶|玩具猫|
|
||||
|meng.liu3|yaochen4|zhy_black|ζั͡ ั͡ ั͡ ั͡Wm|陈国正|
|
||||
|ZhuHJay|zoufang162|乌鸦笑猪黑|wnp|MyronLi|
|
||||
|norkts|拓宇在思考|张春根|witt|xinjump|
|
||||
|疾浪|sppan|时间淡忘一切|
|
||||
|
||||
|
||||
@ -19,68 +19,70 @@
|
||||
|
||||
- 快速构建启动:通过DSL➕重载运算符,快速配置 MybatisFlexBootstrap 实例并启动:
|
||||
```kotlin
|
||||
buildBootstrap {
|
||||
runFlex {
|
||||
// 配置数据源 相当于 setDataSource(dataSource)
|
||||
+dataSource
|
||||
// 配置Mapper 相当于 addMapper(AccountMapper::class.java)
|
||||
+AccountMapper::class
|
||||
// 配置日志输出 相当于 setLogImpl(StdOutImpl::class.java)
|
||||
logImpl = StdOutImpl::class
|
||||
}.start()
|
||||
}
|
||||
```
|
||||
- 快速查询数据:通过DSL➕泛型快速编写查询语句并查询: (快速查询提供三个函数:all, filter 和 query )
|
||||
>- `all<实体类>()` 查泛型对应的表的所有数据
|
||||
>- `filter<实体类>(vararg KProperty<*>, ()->QueryCondition)` 按条件查泛型对应的表的数据
|
||||
>- `query<实体类>(QueryScope.()->Unit)` 较复杂查泛型对应的表的数据 (如: 分组,排序等)
|
||||
|
||||
>- `paginateWith(pageNumber: Number, pageSize: Number, totalRow: Number? = null, queryConditionGet: () -> QueryCondition): Page<实体类>`
|
||||
与 `paginate(pageNumber: Number, pageSize: Number, totalRow: Number? = null, init: QueryScope.() -> Unit): Page<实体类>` 使用分页的条件查询与较复杂查询
|
||||
- 简明地构建查询:通过中缀表达式➕扩展方法能更加简单明了的构建条件:
|
||||
* **【对比原生】**
|
||||
* **原生**
|
||||
```kotlin
|
||||
val queryWrapper = QueryWrapper.create()
|
||||
.select(Account::id.column(), Account::userName.column())
|
||||
.where(Account::age.column().isNotNull()).and(Account::age.column().ge(17))
|
||||
.orderBy(Account::id.column().desc())
|
||||
mapper<AccountMapper>().selectListByQuery(queryWrapper)
|
||||
```
|
||||
|
||||
* **扩展后**
|
||||
```kotlin
|
||||
query<Account> {
|
||||
select(Account::id, Account::userName)
|
||||
where(Account::age.isNotNull) and { Account::age ge 17 } orderBy -Account::id
|
||||
}
|
||||
```
|
||||
执行的SQL:
|
||||
```sql
|
||||
SELECT `id`, `user_name` FROM `tb_account` WHERE `age` IS NOT NULL AND `age` >= 17 ORDER BY `id` DESC
|
||||
```
|
||||
* **【对比原生】**
|
||||
* **原生**
|
||||
```kotlin
|
||||
val queryWrapper = QueryWrapper.create()
|
||||
.select(QueryColumn("id"), QueryColumn("user_name"))
|
||||
.where(QueryColumn("age").isNotNull()).and(QueryColumn("age").ge(17))
|
||||
.orderBy(QueryColumn("id").desc())
|
||||
mapper<AccountMapper>().selectListByQuery(queryWrapper)
|
||||
```
|
||||
|
||||
* **【条件优化】**
|
||||
- 例如: 查询属性是否在一个连续的区间时,会自动将 IN 转为 BETWEEN 调用
|
||||
```kotlin
|
||||
filter<Account> { Account::age `in` (17..19) }
|
||||
```
|
||||
* **扩展后**
|
||||
```kotlin
|
||||
// 无需注册Mapper与APT/KSP即可查询操作
|
||||
val accountList: List<Account> = query {
|
||||
select(Account::id, Account::userName)
|
||||
where(Account::age.isNotNull) and { Account::age ge 17 } orderBy -Account::id
|
||||
}
|
||||
```
|
||||
执行的SQL:
|
||||
```sql
|
||||
SELECT * FROM `tb_account` WHERE `age` BETWEEN 17 AND 19
|
||||
```
|
||||
- 例如: 构建多属性组合 IN (最多支持三个属性)
|
||||
```kotlin
|
||||
filter<Account> {
|
||||
(Account::id to Account::userName to Account::age).inTriple(
|
||||
1 to "张三" to 18,
|
||||
2 to "李四" to 19,
|
||||
)
|
||||
}
|
||||
```
|
||||
执行的SQL:
|
||||
```sql
|
||||
SELECT * FROM `tb_account`
|
||||
WHERE (`id` = 1 AND `user_name` = '张三' AND `age` = 18)
|
||||
OR (`id` = 2 AND `user_name` = '李四' AND `age` = 19)
|
||||
SELECT `id`, `user_name` FROM `tb_account` WHERE `age` IS NOT NULL AND `age` >= 17 ORDER BY `id` DESC
|
||||
```
|
||||
|
||||
* **【条件优化】**
|
||||
- 例如: 查询属性是否在一个连续的区间时,会自动将 IN 转为 BETWEEN 调用
|
||||
```kotlin
|
||||
filter<Account> { Account::age `in` (17..19) }
|
||||
```
|
||||
执行的SQL:
|
||||
```sql
|
||||
SELECT * FROM `tb_account` WHERE `age` BETWEEN 17 AND 19
|
||||
```
|
||||
- 例如: 构建多属性组合 IN (最多支持三个属性)
|
||||
```kotlin
|
||||
filter<Account> {
|
||||
(Account::id to Account::userName to Account::age).inTriple(
|
||||
1 to "张三" to 18,
|
||||
2 to "李四" to 19,
|
||||
)
|
||||
}
|
||||
```
|
||||
执行的SQL:
|
||||
```sql
|
||||
SELECT * FROM `tb_account`
|
||||
WHERE (`id` = 1 AND `user_name` = '张三' AND `age` = 18)
|
||||
OR (`id` = 2 AND `user_name` = '李四' AND `age` = 19)
|
||||
```
|
||||
- 摆脱APT: 使用扩展方法摆脱对 APT(注解处理器) 的使用,直接使用属性引用让代码更加灵活优雅:
|
||||
> 使用APT: `ACCOUNT.ID eq 1` ,使用属性引用: `Account::id eq 1`
|
||||
>
|
||||
|
||||
@ -220,7 +220,7 @@ pom.xml 添加 `annotationProcessorPaths` 配置,
|
||||
```
|
||||
dependencies {
|
||||
...
|
||||
annotationProcessor 'com.mybatis-flex:mybatis-flex-processor:1.7.6'
|
||||
annotationProcessor 'com.mybatis-flex:mybatis-flex-processor:1.7.7'
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-codegen</artifactId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ public interface SetListener extends Listener {
|
||||
* @param entity 实体类
|
||||
* @param property 属性名
|
||||
* @param value 属性值
|
||||
* @return 实体类
|
||||
* @return 属性值
|
||||
*/
|
||||
Object onSet(Object entity, String property, Object value);
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-core</artifactId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
|
||||
@ -4,7 +4,7 @@ import com.mybatisflex.solon.service.impl.ServiceImpl;
|
||||
import #(packageConfig.entityPackage).#(table.buildEntityClassName());
|
||||
import #(packageConfig.mapperPackage).#(table.buildMapperClassName());
|
||||
import #(packageConfig.servicePackage).#(table.buildServiceClassName());
|
||||
import org.noear.solon.annotation.ProxyComponent;
|
||||
import org.noear.solon.annotation.Component;
|
||||
|
||||
/**
|
||||
* #(table.getComment()) 服务层实现。
|
||||
@ -12,7 +12,7 @@ import org.noear.solon.annotation.ProxyComponent;
|
||||
* @author #(javadocConfig.getAuthor())
|
||||
* @since #(javadocConfig.getSince())
|
||||
*/
|
||||
@ProxyComponent
|
||||
@Component
|
||||
public class #(table.buildServiceImplClassName()) extends ServiceImpl<#(table.buildMapperClassName()), #(table.buildEntityClassName())> implements #(table.buildServiceClassName()) {
|
||||
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -101,7 +101,7 @@
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-annotation</artifactId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ public class FlexConsts {
|
||||
}
|
||||
|
||||
public static final String NAME = "MyBatis-Flex";
|
||||
public static final String VERSION = "1.7.6";
|
||||
public static final String VERSION = "1.7.7";
|
||||
|
||||
|
||||
public static final String SQL = "$$sql";
|
||||
|
||||
@ -127,6 +127,7 @@ public class DialectFactory {
|
||||
case DORIS:
|
||||
return new CommonsDialectImpl(KeywordWrap.BACK_QUOTE, LimitOffsetProcessor.MYSQL);
|
||||
case CLICK_HOUSE:
|
||||
case GBASE_8S:
|
||||
return new CommonsDialectImpl(KeywordWrap.NONE, LimitOffsetProcessor.MYSQL);
|
||||
case DM:
|
||||
return new DmDialect();
|
||||
|
||||
@ -479,7 +479,7 @@ public class FlexDefaultResultSetHandler extends DefaultResultSetHandler {
|
||||
|
||||
private boolean applyPropertyMappings(ResultSetWrapper rsw, ResultMap resultMap, MetaObject metaObject,
|
||||
ResultLoaderMap lazyLoader, String columnPrefix) throws SQLException {
|
||||
final List<String> mappedColumnNames = rsw.getMappedColumnNames(resultMap, columnPrefix);
|
||||
final Collection<String> mappedColumnNames = rsw.getMappedColumnNames(resultMap, columnPrefix);
|
||||
boolean foundValues = false;
|
||||
final List<ResultMapping> propertyMappings = resultMap.getPropertyResultMappings();
|
||||
for (ResultMapping propertyMapping : propertyMappings) {
|
||||
@ -1178,7 +1178,7 @@ public class FlexDefaultResultSetHandler extends DefaultResultSetHandler {
|
||||
if (resultMapping.isSimple()) {
|
||||
final String column = prependPrefix(resultMapping.getColumn(), columnPrefix);
|
||||
final TypeHandler<?> th = resultMapping.getTypeHandler();
|
||||
List<String> mappedColumnNames = rsw.getMappedColumnNames(resultMap, columnPrefix);
|
||||
Collection<String> mappedColumnNames = rsw.getMappedColumnNames(resultMap, columnPrefix);
|
||||
// Issue #114
|
||||
if (column != null && mappedColumnNames.contains(column.toUpperCase(Locale.ENGLISH))) {
|
||||
final Object value = th.getResult(rsw.getResultSet(), column);
|
||||
|
||||
@ -30,6 +30,7 @@ import org.apache.ibatis.type.TypeHandler;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@ -84,7 +85,7 @@ public class FlexResultSetHandler extends FlexDefaultResultSetHandler {
|
||||
String columnName = prependPrefix(mapping.getColumn(), columnPrefix);
|
||||
TypeHandler<?> typeHandler = mapping.getTypeHandler();
|
||||
|
||||
List<String> mappedColumnNames = rsw.getMappedColumnNames(resultMap, columnPrefix);
|
||||
Collection<String> mappedColumnNames = rsw.getMappedColumnNames(resultMap, columnPrefix);
|
||||
if (columnName != null && mappedColumnNames.contains(columnName.toUpperCase(Locale.ENGLISH))) {
|
||||
return typeHandler.getResult(rsw.getResultSet(), columnName);
|
||||
}
|
||||
|
||||
@ -247,8 +247,8 @@ public class RowSqlProvider {
|
||||
FlexAssert.notNull(entity, "entity can not be null");
|
||||
|
||||
// 该 Mapper 是通用 Mapper 无法通过 ProviderContext 获取,直接使用 TableInfoFactory
|
||||
TableInfo tableInfo = TableInfoFactory.ofEntityClass(ClassUtil.getUsefulClass(entity.getClass()));
|
||||
|
||||
TableInfo tableInfo = TableInfoFactory.ofEntityClass(ClassUtil.getUsefulClass(entity.getClass()));
|
||||
// 执行 onUpdate 监听器
|
||||
tableInfo.invokeOnUpdateListener(entity);
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@ import com.mybatisflex.core.util.LambdaGetter;
|
||||
import com.mybatisflex.core.util.LambdaUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mybatisflex.core.constant.FuncName.*;
|
||||
@ -2346,6 +2347,12 @@ public class QueryMethods {
|
||||
return new DistinctQueryColumn(columns);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> DistinctQueryColumn distinct(LambdaGetter<T>... columns) {
|
||||
return new DistinctQueryColumn(Arrays.stream(columns)
|
||||
.map(LambdaUtil::getQueryColumn).toArray(QueryColumn[]::new));
|
||||
}
|
||||
|
||||
// === CASE THEN ELSE ===
|
||||
|
||||
/**
|
||||
@ -2564,6 +2571,13 @@ public class QueryMethods {
|
||||
return new OperatorQueryCondition("NOT ", childCondition);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code NOT (column)} 或 {@code NOT column}
|
||||
*/
|
||||
public static <N> QueryColumn not(LambdaGetter<N> column) {
|
||||
return new FunctionQueryColumn("NOT", LambdaUtil.getQueryColumn(column));
|
||||
}
|
||||
|
||||
/**
|
||||
* 空条件。
|
||||
*/
|
||||
|
||||
@ -376,7 +376,7 @@ public interface IService<T> {
|
||||
* @return 查询结果数据
|
||||
*/
|
||||
default T getOne(QueryCondition condition) {
|
||||
return getOne(query().where(condition));
|
||||
return getOne(query().where(condition).limit(1));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -149,7 +149,9 @@ public class ColumnInfo {
|
||||
if (configuration == null) {
|
||||
configuration = FlexGlobalConfig.getDefaultConfig().getConfiguration();
|
||||
}
|
||||
buildTypeHandler = configuration.getTypeHandlerRegistry().getTypeHandler(propertyType);
|
||||
if (configuration != null) {
|
||||
buildTypeHandler = configuration.getTypeHandlerRegistry().getTypeHandler(propertyType);
|
||||
}
|
||||
}
|
||||
|
||||
return buildTypeHandler;
|
||||
|
||||
@ -70,14 +70,15 @@ public class ClassUtil {
|
||||
}
|
||||
|
||||
public static <T> Class<T> getUsefulClass(Class<T> clazz) {
|
||||
|
||||
if (ProxyObject.class.isAssignableFrom(clazz)) {
|
||||
return (Class<T>) clazz.getSuperclass();
|
||||
}
|
||||
|
||||
if (isProxy(clazz)) {
|
||||
return getJdkProxySuperClass(clazz);
|
||||
}
|
||||
|
||||
// if (ProxyObject.class.isAssignableFrom(clazz)){
|
||||
// return (Class<T>) clazz.getSuperclass();
|
||||
// }
|
||||
|
||||
//ControllerTest$ServiceTest$$EnhancerByGuice$$40471411#hello -------> Guice
|
||||
//com.demo.blog.Blog$$EnhancerByCGLIB$$69a17158 ----> CGLIB
|
||||
//io.jboot.test.app.TestAppListener_$$_jvstb9f_0 ------> javassist
|
||||
|
||||
@ -58,13 +58,9 @@ public class FieldWrapper {
|
||||
|
||||
String setterName = "set" + StringUtil.firstCharToUpperCase(fieldName);
|
||||
Method setter = ClassUtil.getFirstMethod(clazz, method ->
|
||||
method.getParameterCount() == 1
|
||||
&& Modifier.isPublic(method.getModifiers())
|
||||
&& method.getName().equals(setterName));
|
||||
|
||||
if (setter == null) {
|
||||
throw new IllegalStateException("Can not find method \"set" + StringUtil.firstCharToUpperCase(fieldName) + "\" in class: " + clazz);
|
||||
}
|
||||
method.getParameterCount() == 1
|
||||
&& Modifier.isPublic(method.getModifiers())
|
||||
&& method.getName().equals(setterName));
|
||||
|
||||
fieldWrapper = new FieldWrapper();
|
||||
fieldWrapper.field = findField;
|
||||
@ -80,8 +76,8 @@ public class FieldWrapper {
|
||||
|
||||
String[] getterNames = new String[]{"get" + StringUtil.firstCharToUpperCase(fieldName), "is" + StringUtil.firstCharToUpperCase(fieldName)};
|
||||
fieldWrapper.getterMethod = ClassUtil.getFirstMethod(clazz, method -> method.getParameterCount() == 0
|
||||
&& Modifier.isPublic(method.getModifiers())
|
||||
&& ArrayUtil.contains(getterNames, method.getName()));
|
||||
&& Modifier.isPublic(method.getModifiers())
|
||||
&& ArrayUtil.contains(getterNames, method.getName()));
|
||||
|
||||
wrapperMap.put(fieldName, fieldWrapper);
|
||||
}
|
||||
@ -120,6 +116,9 @@ public class FieldWrapper {
|
||||
|
||||
public void set(Object value, Object to) {
|
||||
try {
|
||||
if (setterMethod == null) {
|
||||
throw new IllegalStateException("Can not find method \"set" + StringUtil.firstCharToUpperCase(field.getName()) + "\" in class: " + to.getClass());
|
||||
}
|
||||
setterMethod.invoke(to, value);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
@ -128,6 +127,9 @@ public class FieldWrapper {
|
||||
|
||||
public Object get(Object target) {
|
||||
try {
|
||||
if (getterMethod == null) {
|
||||
throw new IllegalStateException("Can not find method \"get" + StringUtil.firstCharToUpperCase(field.getName()) + ", is" + StringUtil.firstCharToUpperCase(field.getName()) + "\" in class: " + target.getClass());
|
||||
}
|
||||
return getterMethod.invoke(target);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
@ -153,4 +155,4 @@ public class FieldWrapper {
|
||||
public boolean isIgnore() {
|
||||
return isIgnore;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>mybatis-flex-dependencies</artifactId>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-annotation</artifactId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-spring</artifactId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@ -104,7 +104,7 @@
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-core</artifactId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
38
mybatis-flex-spring-boot3-starter/pom.xml
Normal file
38
mybatis-flex-spring-boot3-starter/pom.xml
Normal file
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<version>1.7.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>mybatis-flex-spring-boot3-starter</artifactId>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-spring-boot-starter</artifactId>
|
||||
<version>1.7.7</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis-spring</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis-spring</artifactId>
|
||||
<version>3.0.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-core</artifactId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>mybatis-flex-test</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@ -30,6 +30,7 @@ public class ContributorsDocGen {
|
||||
List<String> urls = Arrays.asList(
|
||||
"https://gitee.com/mybatis-flex/mybatis-flex/contributors?ref=main"
|
||||
, "https://gitee.com/mybatis-flex/mybatis-flex/contributors?page=2&ref=main"
|
||||
, "https://gitee.com/mybatis-flex/mybatis-flex/contributors?page=3&ref=main"
|
||||
);
|
||||
StringBuilder markdown = new StringBuilder();
|
||||
markdown.append("| | | | | |\n" +
|
||||
@ -73,12 +74,16 @@ public class ContributorsDocGen {
|
||||
if (userName.contains("@")) {
|
||||
userName = userName.substring(0, userName.indexOf("@"));
|
||||
}
|
||||
if (StringUtil.isBlank(src)) {
|
||||
src = "https://api.dicebear.com/7.x/initials/svg?seed=" + userName;
|
||||
}
|
||||
// if (StringUtil.isBlank(src)) {
|
||||
// src = "https://api.dicebear.com/7.x/initials/svg?seed=" + userName;
|
||||
// }
|
||||
|
||||
markdown.append("|");
|
||||
markdown.append("");
|
||||
|
||||
if (StringUtil.isNotBlank(src)) {
|
||||
markdown.append("");
|
||||
}
|
||||
|
||||
markdown.append(userName);
|
||||
|
||||
startIndex++;
|
||||
|
||||
@ -82,19 +82,28 @@ public class DbTest {
|
||||
Map map2 = Db.selectFirstAndSecondColumnsAsMap("select * from tb_account");
|
||||
System.out.println(map);
|
||||
System.out.println(map2);
|
||||
assert map.equals(map2);
|
||||
|
||||
}
|
||||
@Test
|
||||
public void test03() {
|
||||
Account account = UpdateEntity.of(Account.class,1);
|
||||
account.setAge(1);
|
||||
List<Account> accounts = new ArrayList<>();
|
||||
accounts.add(account);
|
||||
Account account2 = UpdateEntity.of(Account.class,2);
|
||||
account2.setAge(2);
|
||||
UpdateWrapper updateWrapper = UpdateWrapper.of(account2);
|
||||
updateWrapper.setRaw("age","age+1");
|
||||
accounts.add(account2);
|
||||
Db.updateEntitiesBatch(accounts);
|
||||
try {
|
||||
Account account = UpdateEntity.of(Account.class, 1);
|
||||
account.setAge(1);
|
||||
List<Account> accounts = new ArrayList<>();
|
||||
accounts.add(account);
|
||||
Account account2 = UpdateEntity.of(Account.class, 2);
|
||||
account2.setAge(2);
|
||||
UpdateWrapper updateWrapper = UpdateWrapper.of(account2);
|
||||
updateWrapper.setRaw("age", "age+1");
|
||||
accounts.add(account2);
|
||||
Account account3 = new Account();
|
||||
account3.setId(3L);
|
||||
account3.setAge(4);
|
||||
accounts.add(account3);
|
||||
Db.updateEntitiesBatch(accounts);
|
||||
}catch (Exception e){
|
||||
assert false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>mybatis-flex-test</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>mybatis-flex-test</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -83,6 +83,24 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>testcontainers</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>mysql</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
package com.mybatisflex.test;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.testcontainers.containers.BindMode;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.MySQLContainer;
|
||||
import org.testcontainers.containers.wait.strategy.Wait;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class TestInfrastructure {
|
||||
|
||||
static final String FLEX_TEST_DDL = TestInfrastructure.class.getClassLoader().getResource("flex_test.sql").getPath();
|
||||
static final String FIELD_MAPPING_TEST_DDL = TestInfrastructure.class.getClassLoader().getResource("field_mapping_test.sql").getPath();
|
||||
static final String PATIENT_DATA_SPLIT_TEST_DDL = TestInfrastructure.class.getClassLoader().getResource("patient_data_split_test.sql").getPath();
|
||||
static final String DOCKER_INITDB_PATH = "/docker-entrypoint-initdb.d/";
|
||||
static GenericContainer<?> mysql = new MySQLContainer<>(DockerImageName.parse("mysql:8.2.0"))
|
||||
.waitingFor(Wait.forLogMessage(".*ready for connections.*\\n", 1))
|
||||
.withFileSystemBind(FLEX_TEST_DDL, DOCKER_INITDB_PATH + "flex_test.sql", BindMode.READ_ONLY)
|
||||
.withFileSystemBind(FIELD_MAPPING_TEST_DDL, DOCKER_INITDB_PATH + "field_mapping_test.sql", BindMode.READ_ONLY)
|
||||
.withFileSystemBind(PATIENT_DATA_SPLIT_TEST_DDL, DOCKER_INITDB_PATH + "patient_data_split_test.sql", BindMode.READ_ONLY)
|
||||
.withDatabaseName("flex_test")
|
||||
.withReuse(true)
|
||||
.withPassword("123456");
|
||||
|
||||
@BeforeAll
|
||||
public static void start() {
|
||||
mysql.setPortBindings(Collections.singletonList("3306:3306"));
|
||||
mysql.start();
|
||||
}
|
||||
}
|
||||
@ -19,6 +19,11 @@ package com.mybatisflex.test.common;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.mybatisflex.core.query.QueryCondition;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@ -71,4 +76,26 @@ public class SerialUtil {
|
||||
return parseObject(toJSONString(obj), tClass);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 使用jackson对QueryWrapper进行序列化反序列化操作,需要注意QueryCondition的protected属性以及prev和next的递归问题。
|
||||
*
|
||||
* @return Jackson序列化映射
|
||||
*/
|
||||
public static ObjectMapper jacksonMapper(){
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
// 为了将QueryWrapper里的protected属性可见
|
||||
mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC);
|
||||
// 避免QueryCondition里的prev和next在序列化时出现递归调用错误
|
||||
mapper.addMixIn(QueryCondition.class,QueryConditionMixIn.class);
|
||||
return mapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 因无法修改QueryCondition而添加的映射属性包装
|
||||
*/
|
||||
class QueryConditionMixIn{
|
||||
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||
protected QueryCondition prev;
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,18 +19,16 @@ package com.mybatisflex.test.mapper;
|
||||
import com.mybatisflex.core.logicdelete.LogicDeleteManager;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.row.Db;
|
||||
import com.mybatisflex.core.row.Row;
|
||||
import com.mybatisflex.test.TestInfrastructure;
|
||||
import com.mybatisflex.test.model.Account;
|
||||
import com.mybatisflex.test.model.AccountVO;
|
||||
import com.mybatisflex.test.model.AccountVO2;
|
||||
import lombok.val;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mybatisflex.core.query.QueryMethods.*;
|
||||
import static com.mybatisflex.test.model.table.AccountTableDef.ACCOUNT;
|
||||
@ -44,7 +42,7 @@ import static com.mybatisflex.test.model.table.UserTableDef.USER;
|
||||
*/
|
||||
@SpringBootTest
|
||||
@SuppressWarnings("all")
|
||||
class AccountMapperTest {
|
||||
class AccountMapperTest extends TestInfrastructure {
|
||||
|
||||
@Autowired
|
||||
private AccountMapper accountMapper;
|
||||
|
||||
@ -18,6 +18,7 @@ package com.mybatisflex.test.mapper;
|
||||
|
||||
import com.mybatisflex.core.mybatis.Mappers;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.test.TestInfrastructure;
|
||||
import com.mybatisflex.test.model.Good;
|
||||
import com.mybatisflex.test.model.User;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
@ -34,7 +35,7 @@ import static com.mybatisflex.test.model.table.UserTableDef.USER;
|
||||
* @since 2023-07-23
|
||||
*/
|
||||
@SpringBootTest
|
||||
class ActiveRecordTest {
|
||||
class ActiveRecordTest extends TestInfrastructure {
|
||||
|
||||
@Test
|
||||
void testMapper() {
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
package com.mybatisflex.test.mapper;
|
||||
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.test.TestInfrastructure;
|
||||
import com.mybatisflex.test.model.Account;
|
||||
import com.mybatisflex.test.model.Article;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -26,7 +27,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class CombinedMapperTest {
|
||||
public class CombinedMapperTest extends TestInfrastructure {
|
||||
|
||||
@Autowired
|
||||
private AccountMapper accountMapper;
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
|
||||
package com.mybatisflex.test.mapper;
|
||||
|
||||
import com.mybatisflex.test.TestInfrastructure;
|
||||
import com.mybatisflex.test.model.Account;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -32,7 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
* @since 2023/4/24 19:37
|
||||
*/
|
||||
@SpringBootTest
|
||||
class MyAccountMapperTest {
|
||||
class MyAccountMapperTest extends TestInfrastructure {
|
||||
|
||||
@Autowired
|
||||
private MyAccountMapper mapper;
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
package com.mybatisflex.test.mapper;
|
||||
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.test.entity.Inner;
|
||||
import com.mybatisflex.test.TestInfrastructure;
|
||||
import com.mybatisflex.test.entity.Outer;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -32,7 +32,7 @@ import static com.mybatisflex.test.entity.table.OuterTableDef.OUTER;
|
||||
* @since 2023-07-01
|
||||
*/
|
||||
@SpringBootTest
|
||||
class OuterMapperTest {
|
||||
class OuterMapperTest extends TestInfrastructure {
|
||||
|
||||
@Autowired
|
||||
private OuterMapper outerMapper;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.mybatisflex.test.mapper;
|
||||
|
||||
import com.mybatisflex.test.TestInfrastructure;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@ -13,7 +14,7 @@ import javax.annotation.Resource;
|
||||
*/
|
||||
@SpringBootTest
|
||||
@SuppressWarnings("all")
|
||||
public class PatientMapperTest {
|
||||
public class PatientMapperTest extends TestInfrastructure {
|
||||
|
||||
@Resource
|
||||
private PatientMapper patientMapper;
|
||||
|
||||
@ -20,6 +20,7 @@ import com.mybatisflex.core.field.QueryBuilder;
|
||||
import com.mybatisflex.core.query.QueryChain;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.update.UpdateChain;
|
||||
import com.mybatisflex.test.TestInfrastructure;
|
||||
import com.mybatisflex.test.model.Gender;
|
||||
import com.mybatisflex.test.model.User;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
@ -36,7 +37,7 @@ import static com.mybatisflex.test.model.table.UserTableDef.USER;
|
||||
* @since 2023-08-08
|
||||
*/
|
||||
@SpringBootTest
|
||||
class QueryChainTest {
|
||||
class QueryChainTest extends TestInfrastructure {
|
||||
|
||||
@Autowired
|
||||
UserMapper userMapper;
|
||||
|
||||
@ -18,6 +18,7 @@ package com.mybatisflex.test.mapper;
|
||||
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.test.TestInfrastructure;
|
||||
import com.mybatisflex.test.model.*;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -42,7 +43,7 @@ import static com.mybatisflex.test.model.table.UserTableDef.USER;
|
||||
*/
|
||||
@SpringBootTest
|
||||
@SuppressWarnings("all")
|
||||
class UserMapperTest {
|
||||
class UserMapperTest extends TestInfrastructure {
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
package com.mybatisflex.test.service;
|
||||
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.test.TestInfrastructure;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@ -28,7 +29,7 @@ import static com.mybatisflex.test.model.table.ArticleTableDef.ARTICLE;
|
||||
* @since 2023-07-22
|
||||
*/
|
||||
@SpringBootTest
|
||||
class ArticleServiceTest {
|
||||
class ArticleServiceTest extends TestInfrastructure {
|
||||
|
||||
@Autowired
|
||||
ArticleService articleService;
|
||||
|
||||
@ -2,6 +2,7 @@ package com.mybatisflex.test.service;
|
||||
|
||||
import com.mybatisflex.test.mapper.FieldMappingInnerMapper;
|
||||
import com.mybatisflex.test.mapper.FieldMappingMapper;
|
||||
import com.mybatisflex.test.TestInfrastructure;
|
||||
import com.mybatisflex.test.model.FieldMapping;
|
||||
import com.mybatisflex.test.model.FieldMappingInner;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -11,11 +12,12 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import java.util.Date;
|
||||
|
||||
@SpringBootTest
|
||||
public class FieldMappingTest {
|
||||
class FieldMappingTest extends TestInfrastructure {
|
||||
@Autowired
|
||||
FieldMappingMapper fieldMappingMapper;
|
||||
@Autowired
|
||||
FieldMappingInnerMapper fieldMappingInnerMapper;
|
||||
|
||||
@Test
|
||||
void testFieldMapping() {
|
||||
String fieldId = FieldMapping.create().saveOpt().get().getId();
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>mybatis-flex-test</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>mybatis-flex-test</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
16
pom.xml
16
pom.xml
@ -7,7 +7,7 @@
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
|
||||
<name>mybatis-flex</name>
|
||||
<url>https://mybatis-flex.com</url>
|
||||
@ -45,6 +45,7 @@
|
||||
<module>mybatis-flex-core</module>
|
||||
<module>mybatis-flex-spring</module>
|
||||
<module>mybatis-flex-spring-boot-starter</module>
|
||||
<module>mybatis-flex-spring-boot3-starter</module>
|
||||
<module>mybatis-flex-solon-plugin</module>
|
||||
<module>mybatis-flex-test</module>
|
||||
<module>mybatis-flex-processor</module>
|
||||
@ -55,9 +56,9 @@
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
|
||||
<mybatis-flex.version>1.7.6</mybatis-flex.version>
|
||||
<mybatis-flex.version>1.7.7</mybatis-flex.version>
|
||||
|
||||
<mybatis.version>3.5.14</mybatis.version>
|
||||
<mybatis.version>3.5.15</mybatis.version>
|
||||
<mybatis-spring.version>2.1.2</mybatis-spring.version>
|
||||
<mybatis-freemarker.version>1.2.4</mybatis-freemarker.version>
|
||||
<mybatis-velocity.version>2.1.2</mybatis-velocity.version>
|
||||
@ -71,6 +72,7 @@
|
||||
<solon.version>2.5.3</solon.version>
|
||||
|
||||
<junit.version>4.13.2</junit.version>
|
||||
<testcontainers.version>1.19.3</testcontainers.version>
|
||||
<maven-flatten.version>1.5.0</maven-flatten.version>
|
||||
</properties>
|
||||
|
||||
@ -188,6 +190,14 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>testcontainers-bom</artifactId>
|
||||
<version>${testcontainers.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user