mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 17:48:25 +08:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
d6dcf29f59
@ -63,7 +63,7 @@ export default defineConfig({
|
|||||||
{text: '链式操作🔥🔥', link: '/zh/base/chain'},
|
{text: '链式操作🔥🔥', link: '/zh/base/chain'},
|
||||||
{text: 'QueryWrapper', link: '/zh/base/querywrapper'},
|
{text: 'QueryWrapper', link: '/zh/base/querywrapper'},
|
||||||
{text: 'Db + Row', link: '/zh/base/db-row'},
|
{text: 'Db + Row', link: '/zh/base/db-row'},
|
||||||
{text: 'Active Record', link: '/zh/base/active-record'},
|
{text: 'ActiveRecord', link: '/zh/base/active-record'},
|
||||||
{text: 'IService', link: '/zh/base/service'},
|
{text: 'IService', link: '/zh/base/service'},
|
||||||
{text: 'SpringBoot 配置文件', link: '/zh/base/configuration'},
|
{text: 'SpringBoot 配置文件', link: '/zh/base/configuration'},
|
||||||
{text: 'MyBatisFlexCustomizer', link: '/zh/base/mybatis-flex-customizer'},
|
{text: 'MyBatisFlexCustomizer', link: '/zh/base/mybatis-flex-customizer'},
|
||||||
|
|||||||
@ -141,7 +141,7 @@ Account.create()
|
|||||||
|
|
||||||
`Model` 提供了 `joins` 与 `@Relation` 两种方式实现多表关联查询,例如:用户与角色的关系:
|
`Model` 提供了 `joins` 与 `@Relation` 两种方式实现多表关联查询,例如:用户与角色的关系:
|
||||||
|
|
||||||
- 通过 [joins](./relations-query.md#方案-3join-query) 联表方式查询数据:
|
- 通过 [joins](./relations-query.md#方案-3-join-query) 联表方式查询数据:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
User.create()
|
User.create()
|
||||||
@ -151,6 +151,9 @@ User.create()
|
|||||||
.where(USER.USER_ID.eq(2))
|
.where(USER.USER_ID.eq(2))
|
||||||
.one();
|
.one();
|
||||||
```
|
```
|
||||||
|
> 更多关于 `left join` 等 join 查询,请请点击 [这里](./relations-query.md#方案-3-join-query);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- 通过 [@Relation](./relations-query.md#方案-1relations-注解) 相关注解查询数据:
|
- 通过 [@Relation](./relations-query.md#方案-1relations-注解) 相关注解查询数据:
|
||||||
|
|
||||||
@ -159,3 +162,5 @@ User.create()
|
|||||||
.where(USER.USER_ID.eq(2))
|
.where(USER.USER_ID.eq(2))
|
||||||
.oneWithRelations();
|
.oneWithRelations();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> 以上是用于查询 `一对多`、`多对多` 等场景,更多信息请点击 [这里](./relations-query.md#方案-1-relations-注解);
|
||||||
|
|||||||
@ -206,7 +206,7 @@ paginate 的返回值为 Page 对象,Page 类的定义如下:
|
|||||||
|
|
||||||
```java
|
```java
|
||||||
public class Page<T> implements Serializable {
|
public class Page<T> implements Serializable {
|
||||||
private List<T> list; // list result of this page
|
private List<T> records; // list result of this page
|
||||||
private int pageNumber; // page number
|
private int pageNumber; // page number
|
||||||
private int pageSize; // result amount of this page
|
private int pageSize; // result amount of this page
|
||||||
private long totalPage; // total page
|
private long totalPage; // total page
|
||||||
|
|||||||
@ -29,7 +29,7 @@ MyBatis-Flex 主要是和 `MyBatis-Plus` 与 `Fluent-MyBatis` 对比,内容来
|
|||||||
| 逻辑删除 | ✅ | ✅ | ✅ |
|
| 逻辑删除 | ✅ | ✅ | ✅ |
|
||||||
| 乐观锁 | ✅ | ✅ | ✅ |
|
| 乐观锁 | ✅ | ✅ | ✅ |
|
||||||
| SQL 审计 | ✅ | ❌ | ❌ |
|
| SQL 审计 | ✅ | ❌ | ❌ |
|
||||||
| 数据填充 | ✅ | ✔️ **(收费)** | ✅ |
|
| 数据填充 | ✅ | ✅ | ✅ |
|
||||||
| 数据脱敏 | ✅ | ✔️ **(收费)** | ❌ |
|
| 数据脱敏 | ✅ | ✔️ **(收费)** | ❌ |
|
||||||
| 字段权限 | ✅ | ✔️ **(收费)** | ❌ |
|
| 字段权限 | ✅ | ✔️ **(收费)** | ❌ |
|
||||||
| 字段加密 | ✅ | ✔️ **(收费)** | ❌ |
|
| 字段加密 | ✅ | ✔️ **(收费)** | ❌ |
|
||||||
@ -270,7 +270,7 @@ QueryWrapper query = new QueryWrapper()
|
|||||||
|
|
||||||
```sql
|
```sql
|
||||||
update tb_account
|
update tb_account
|
||||||
set user_name = "michael", age = 18, birthday = null
|
set user_name = "michael", age = 18, birthday = null
|
||||||
where id = 100
|
where id = 100
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -288,7 +288,7 @@ accountMapper.update(account);
|
|||||||
|
|
||||||
**MyBatis-Plus** 代码如下(或可使用 MyBatis-Plus 的 `LambdaUpdateWrapper`,但性能没有 `UpdateWrapper` 好):
|
**MyBatis-Plus** 代码如下(或可使用 MyBatis-Plus 的 `LambdaUpdateWrapper`,但性能没有 `UpdateWrapper` 好):
|
||||||
|
|
||||||
```java
|
```java
|
||||||
UpdateWrapper<Account> updateWrapper = new UpdateWrapper<>();
|
UpdateWrapper<Account> updateWrapper = new UpdateWrapper<>();
|
||||||
updateWrapper.eq("id", 100);
|
updateWrapper.eq("id", 100);
|
||||||
updateWrapper.set("user_name", "michael");
|
updateWrapper.set("user_name", "michael");
|
||||||
@ -300,7 +300,7 @@ accountMapper.update(null, updateWrapper);
|
|||||||
|
|
||||||
**Fluent-MyBatis** 代码如下:
|
**Fluent-MyBatis** 代码如下:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
AccountUpdate update = new AccountUpdate()
|
AccountUpdate update = new AccountUpdate()
|
||||||
.update.userName().is("michael")
|
.update.userName().is("michael")
|
||||||
.age().is(18)
|
.age().is(18)
|
||||||
@ -309,4 +309,4 @@ AccountUpdate update = new AccountUpdate()
|
|||||||
.where.id().eq(100)
|
.where.id().eq(100)
|
||||||
.end();
|
.end();
|
||||||
accountMapper.updateBy(update);
|
accountMapper.updateBy(update);
|
||||||
```
|
```
|
||||||
|
|||||||
@ -25,8 +25,8 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>com.mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
<version>8.0.32</version>
|
<version>8.0.32</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|||||||
@ -43,8 +43,8 @@
|
|||||||
|
|
||||||
<!-- for test only-->
|
<!-- for test only-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>com.mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
<version>8.0.33</version>
|
<version>8.0.33</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
|
|||||||
@ -73,8 +73,8 @@
|
|||||||
<!--optional end-->
|
<!--optional end-->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>com.mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|||||||
@ -89,6 +89,13 @@ import java.util.stream.Stream;
|
|||||||
* 1、替换配置为 mybatis-flex 的配置前缀<br>
|
* 1、替换配置为 mybatis-flex 的配置前缀<br>
|
||||||
* 2、修改 SqlSessionFactory 为 FlexSqlSessionFactoryBean<br>
|
* 2、修改 SqlSessionFactory 为 FlexSqlSessionFactoryBean<br>
|
||||||
* 3、修改 Configuration 为 FlexConfiguration<br>
|
* 3、修改 Configuration 为 FlexConfiguration<br>
|
||||||
|
*
|
||||||
|
* @author Eddú Meléndez
|
||||||
|
* @author Josh Long
|
||||||
|
* @author Kazuki Shimizu
|
||||||
|
* @author Eduardo Macarrón
|
||||||
|
* @author michael
|
||||||
|
* @author 王帅
|
||||||
*/
|
*/
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass({SqlSessionFactory.class, SqlSessionFactoryBean.class})
|
@ConditionalOnClass({SqlSessionFactory.class, SqlSessionFactoryBean.class})
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import java.util.Collections;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 参考:https://github.com/mybatis/spring-boot-starter/blob/master/mybatis-spring-boot-autoconfigure/src/main/java/org/mybatis/spring/boot/autoconfigure/MybatisDependsOnDatabaseInitializationDetector.java
|
||||||
* {@link DependsOnDatabaseInitializationDetector} for Mybatis-Flex.
|
* {@link DependsOnDatabaseInitializationDetector} for Mybatis-Flex.
|
||||||
*/
|
*/
|
||||||
class MybatisFlexDependsOnDatabaseInitializationDetector
|
class MybatisFlexDependsOnDatabaseInitializationDetector
|
||||||
|
|||||||
@ -40,6 +40,11 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Mybatis-Flex 的配置属性。
|
* Mybatis-Flex 的配置属性。
|
||||||
|
* 参考:https://github.com/mybatis/spring-boot-starter/blob/master/mybatis-spring-boot-autoconfigure/src/main/java/org/mybatis/spring/boot/autoconfigure/MybatisProperties.java
|
||||||
|
* @author Eddú Meléndez
|
||||||
|
* @author Kazuki Shimizu
|
||||||
|
* @author micahel
|
||||||
|
* @author 王帅
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties(prefix = "mybatis-flex")
|
@ConfigurationProperties(prefix = "mybatis-flex")
|
||||||
public class MybatisFlexProperties {
|
public class MybatisFlexProperties {
|
||||||
|
|||||||
@ -31,6 +31,9 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 脚本语言驱动的自动配置,平常一般项目用不到,只为了同步 MyBatis 自带的 MybatisLanguageDriverAutoConfiguration。
|
* 脚本语言驱动的自动配置,平常一般项目用不到,只为了同步 MyBatis 自带的 MybatisLanguageDriverAutoConfiguration。
|
||||||
|
* 参考:https://github.com/mybatis/spring-boot-starter/blob/master/mybatis-spring-boot-autoconfigure/src/main/java/org/mybatis/spring/boot/autoconfigure/MybatisLanguageDriverAutoConfiguration.java
|
||||||
|
* @author Kazuki Shimizu
|
||||||
|
* @author michael
|
||||||
*/
|
*/
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass(LanguageDriver.class)
|
@ConditionalOnClass(LanguageDriver.class)
|
||||||
|
|||||||
@ -32,6 +32,11 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* MyBatis 的 VFS 支持。
|
* MyBatis 的 VFS 支持。
|
||||||
|
* 参考:https://github.com/mybatis/spring-boot-starter/blob/master/mybatis-spring-boot-autoconfigure/src/main/java/org/mybatis/spring/boot/autoconfigure/SpringBootVFS.java
|
||||||
|
* @author Hans Westerbeek
|
||||||
|
* @author Eddú Meléndez
|
||||||
|
* @author Kazuki Shimizu
|
||||||
|
* @author Michael
|
||||||
*/
|
*/
|
||||||
public class SpringBootVFS extends VFS {
|
public class SpringBootVFS extends VFS {
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,8 @@ package com.mybatisflex.spring.boot;
|
|||||||
import org.mybatis.spring.SqlSessionFactoryBean;
|
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 参考:https://github.com/mybatis/spring-boot-starter/blob/master/mybatis-spring-boot-autoconfigure/src/main/java/org/mybatis/spring/boot/autoconfigure/SqlSessionFactoryBeanCustomizer.java
|
||||||
|
*
|
||||||
* 为 FlexSqlSessionFactoryBean 做自定义的配置支持。
|
* 为 FlexSqlSessionFactoryBean 做自定义的配置支持。
|
||||||
*
|
*
|
||||||
* @see com.mybatisflex.spring.FlexSqlSessionFactoryBean
|
* @see com.mybatisflex.spring.FlexSqlSessionFactoryBean
|
||||||
|
|||||||
@ -73,11 +73,22 @@ import static org.springframework.util.StringUtils.hasLength;
|
|||||||
import static org.springframework.util.StringUtils.tokenizeToStringArray;
|
import static org.springframework.util.StringUtils.tokenizeToStringArray;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Spring 在定义 SqlSessionFactoryBean 的时候,需要替换为 FlexSqlSessionFactoryBean。
|
* 参考:https://github.com/mybatis/spring/blob/master/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java
|
||||||
|
*
|
||||||
|
* <p>在 MyBatis 官方的 SqlSessionFactoryBean 基础上,替换le FlexSqlSessionFactoryBean。
|
||||||
*
|
*
|
||||||
* <p>源于 {@link SqlSessionFactoryBean},主要是用于构建 {@link com.mybatisflex.core.mybatis.FlexConfiguration },而不是使用原生的 {@link Configuration}。
|
* <p>源于 {@link SqlSessionFactoryBean},主要是用于构建 {@link com.mybatisflex.core.mybatis.FlexConfiguration },而不是使用原生的 {@link Configuration}。
|
||||||
*
|
*
|
||||||
* <p>此代码主要是用于修改 {@link FlexSqlSessionFactoryBean#buildSqlSessionFactory()} 部分。
|
* <p>此代码主要是用于修改 {@link FlexSqlSessionFactoryBean#buildSqlSessionFactory()} 部分。
|
||||||
|
*
|
||||||
|
* @author Putthiphong Boonphong
|
||||||
|
* @author Hunter Presnall
|
||||||
|
* @author Eduardo Macarron
|
||||||
|
* @author Eddú Meléndez
|
||||||
|
* @author Kazuki Shimizu
|
||||||
|
* @author Jens Schauder
|
||||||
|
* @author 王帅
|
||||||
|
* @author miachel
|
||||||
*/
|
*/
|
||||||
public class FlexSqlSessionFactoryBean extends SqlSessionFactoryBean
|
public class FlexSqlSessionFactoryBean extends SqlSessionFactoryBean
|
||||||
implements FactoryBean<SqlSessionFactory>, InitializingBean, ApplicationListener<ApplicationEvent> {
|
implements FactoryBean<SqlSessionFactory>, InitializingBean, ApplicationListener<ApplicationEvent> {
|
||||||
|
|||||||
@ -43,8 +43,8 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>com.mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@ -91,7 +91,7 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate.validator</groupId>
|
||||||
<artifactId>hibernate-validator</artifactId>
|
<artifactId>hibernate-validator</artifactId>
|
||||||
<version>7.0.5.Final</version>
|
<version>7.0.5.Final</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|||||||
@ -59,8 +59,8 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>com.mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -70,8 +70,8 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>com.mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
4
pom.xml
4
pom.xml
@ -174,8 +174,8 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>com.mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
<version>${mysql.version}</version>
|
<version>${mysql.version}</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user