mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-06 16:48:24 +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: 'QueryWrapper', link: '/zh/base/querywrapper'},
|
||||
{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: 'SpringBoot 配置文件', link: '/zh/base/configuration'},
|
||||
{text: 'MyBatisFlexCustomizer', link: '/zh/base/mybatis-flex-customizer'},
|
||||
|
||||
@ -141,7 +141,7 @@ Account.create()
|
||||
|
||||
`Model` 提供了 `joins` 与 `@Relation` 两种方式实现多表关联查询,例如:用户与角色的关系:
|
||||
|
||||
- 通过 [joins](./relations-query.md#方案-3join-query) 联表方式查询数据:
|
||||
- 通过 [joins](./relations-query.md#方案-3-join-query) 联表方式查询数据:
|
||||
|
||||
```java
|
||||
User.create()
|
||||
@ -151,6 +151,9 @@ User.create()
|
||||
.where(USER.USER_ID.eq(2))
|
||||
.one();
|
||||
```
|
||||
> 更多关于 `left join` 等 join 查询,请请点击 [这里](./relations-query.md#方案-3-join-query);
|
||||
|
||||
|
||||
|
||||
- 通过 [@Relation](./relations-query.md#方案-1relations-注解) 相关注解查询数据:
|
||||
|
||||
@ -159,3 +162,5 @@ User.create()
|
||||
.where(USER.USER_ID.eq(2))
|
||||
.oneWithRelations();
|
||||
```
|
||||
|
||||
> 以上是用于查询 `一对多`、`多对多` 等场景,更多信息请点击 [这里](./relations-query.md#方案-1-relations-注解);
|
||||
|
||||
@ -206,7 +206,7 @@ paginate 的返回值为 Page 对象,Page 类的定义如下:
|
||||
|
||||
```java
|
||||
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 pageSize; // result amount of this page
|
||||
private long totalPage; // total page
|
||||
|
||||
@ -29,7 +29,7 @@ MyBatis-Flex 主要是和 `MyBatis-Plus` 与 `Fluent-MyBatis` 对比,内容来
|
||||
| 逻辑删除 | ✅ | ✅ | ✅ |
|
||||
| 乐观锁 | ✅ | ✅ | ✅ |
|
||||
| SQL 审计 | ✅ | ❌ | ❌ |
|
||||
| 数据填充 | ✅ | ✔️ **(收费)** | ✅ |
|
||||
| 数据填充 | ✅ | ✅ | ✅ |
|
||||
| 数据脱敏 | ✅ | ✔️ **(收费)** | ❌ |
|
||||
| 字段权限 | ✅ | ✔️ **(收费)** | ❌ |
|
||||
| 字段加密 | ✅ | ✔️ **(收费)** | ❌ |
|
||||
@ -270,7 +270,7 @@ QueryWrapper query = new QueryWrapper()
|
||||
|
||||
```sql
|
||||
update tb_account
|
||||
set user_name = "michael", age = 18, birthday = null
|
||||
set user_name = "michael", age = 18, birthday = null
|
||||
where id = 100
|
||||
```
|
||||
|
||||
@ -288,7 +288,7 @@ accountMapper.update(account);
|
||||
|
||||
**MyBatis-Plus** 代码如下(或可使用 MyBatis-Plus 的 `LambdaUpdateWrapper`,但性能没有 `UpdateWrapper` 好):
|
||||
|
||||
```java
|
||||
```java
|
||||
UpdateWrapper<Account> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", 100);
|
||||
updateWrapper.set("user_name", "michael");
|
||||
@ -300,7 +300,7 @@ accountMapper.update(null, updateWrapper);
|
||||
|
||||
**Fluent-MyBatis** 代码如下:
|
||||
|
||||
```java
|
||||
```java
|
||||
AccountUpdate update = new AccountUpdate()
|
||||
.update.userName().is("michael")
|
||||
.age().is(18)
|
||||
@ -309,4 +309,4 @@ AccountUpdate update = new AccountUpdate()
|
||||
.where.id().eq(100)
|
||||
.end();
|
||||
accountMapper.updateBy(update);
|
||||
```
|
||||
```
|
||||
|
||||
@ -25,8 +25,8 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<version>8.0.32</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@ -43,8 +43,8 @@
|
||||
|
||||
<!-- for test only-->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<version>8.0.33</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
|
||||
@ -73,8 +73,8 @@
|
||||
<!--optional end-->
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@ -89,6 +89,13 @@ import java.util.stream.Stream;
|
||||
* 1、替换配置为 mybatis-flex 的配置前缀<br>
|
||||
* 2、修改 SqlSessionFactory 为 FlexSqlSessionFactoryBean<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)
|
||||
@ConditionalOnClass({SqlSessionFactory.class, SqlSessionFactoryBean.class})
|
||||
|
||||
@ -23,6 +23,7 @@ import java.util.Collections;
|
||||
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.
|
||||
*/
|
||||
class MybatisFlexDependsOnDatabaseInitializationDetector
|
||||
|
||||
@ -40,6 +40,11 @@ import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 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")
|
||||
public class MybatisFlexProperties {
|
||||
|
||||
@ -31,6 +31,9 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 脚本语言驱动的自动配置,平常一般项目用不到,只为了同步 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)
|
||||
@ConditionalOnClass(LanguageDriver.class)
|
||||
|
||||
@ -32,6 +32,11 @@ import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
|
||||
|
||||
@ -18,6 +18,8 @@ package com.mybatisflex.spring.boot;
|
||||
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 做自定义的配置支持。
|
||||
*
|
||||
* @see com.mybatisflex.spring.FlexSqlSessionFactoryBean
|
||||
|
||||
@ -73,11 +73,22 @@ import static org.springframework.util.StringUtils.hasLength;
|
||||
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 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
|
||||
implements FactoryBean<SqlSessionFactory>, InitializingBean, ApplicationListener<ApplicationEvent> {
|
||||
|
||||
@ -43,8 +43,8 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@ -91,7 +91,7 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<groupId>org.hibernate.validator</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<version>7.0.5.Final</version>
|
||||
</dependency>
|
||||
|
||||
@ -59,8 +59,8 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
@ -70,8 +70,8 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user