mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 17:21:53 +08:00
切换 Mybatis-plus-join 依赖
This commit is contained in:
parent
95159b0257
commit
f9569f910f
@ -26,7 +26,7 @@
|
|||||||
<mybatis-plus.version>3.5.3.1</mybatis-plus.version>
|
<mybatis-plus.version>3.5.3.1</mybatis-plus.version>
|
||||||
<mybatis-plus-generator.version>3.5.3.1</mybatis-plus-generator.version>
|
<mybatis-plus-generator.version>3.5.3.1</mybatis-plus-generator.version>
|
||||||
<dynamic-datasource.version>3.6.1</dynamic-datasource.version>
|
<dynamic-datasource.version>3.6.1</dynamic-datasource.version>
|
||||||
<mybatis-plus-join.version>1.3.4</mybatis-plus-join.version>
|
<mybatis-plus-join-boot-starter.version>1.4.3.1</mybatis-plus-join-boot-starter.version>
|
||||||
<redisson.version>3.18.0</redisson.version>
|
<redisson.version>3.18.0</redisson.version>
|
||||||
<!-- 服务保障相关 -->
|
<!-- 服务保障相关 -->
|
||||||
<lock4j.version>2.2.3</lock4j.version>
|
<lock4j.version>2.2.3</lock4j.version>
|
||||||
@ -211,9 +211,9 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>icu.mhb</groupId>
|
<groupId>com.github.yulichang</groupId>
|
||||||
<artifactId>mybatis-plus-join</artifactId>
|
<artifactId>mybatis-plus-join-boot-starter</artifactId>
|
||||||
<version>${mybatis-plus-join.version}</version>
|
<version>${mybatis-plus-join-boot-starter.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -60,8 +60,8 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>icu.mhb</groupId>
|
<groupId>com.github.yulichang</groupId>
|
||||||
<artifactId>mybatis-plus-join</artifactId>
|
<artifactId>mybatis-plus-join-boot-starter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -5,14 +5,12 @@ import cn.iocoder.yudao.framework.mybatis.core.handler.DefaultDBFieldHandler;
|
|||||||
import com.baomidou.mybatisplus.annotation.DbType;
|
import com.baomidou.mybatisplus.annotation.DbType;
|
||||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||||
import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator;
|
import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator;
|
||||||
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
|
|
||||||
import com.baomidou.mybatisplus.extension.incrementer.H2KeyGenerator;
|
import com.baomidou.mybatisplus.extension.incrementer.H2KeyGenerator;
|
||||||
import com.baomidou.mybatisplus.extension.incrementer.KingbaseKeyGenerator;
|
import com.baomidou.mybatisplus.extension.incrementer.KingbaseKeyGenerator;
|
||||||
import com.baomidou.mybatisplus.extension.incrementer.OracleKeyGenerator;
|
import com.baomidou.mybatisplus.extension.incrementer.OracleKeyGenerator;
|
||||||
import com.baomidou.mybatisplus.extension.incrementer.PostgreKeyGenerator;
|
import com.baomidou.mybatisplus.extension.incrementer.PostgreKeyGenerator;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||||
import icu.mhb.mybatisplus.plugln.injector.JoinDefaultSqlInjector;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
@ -42,11 +40,6 @@ public class YudaoMybatisAutoConfiguration {
|
|||||||
return new DefaultDBFieldHandler(); // 自动填充参数类
|
return new DefaultDBFieldHandler(); // 自动填充参数类
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
public DefaultSqlInjector defaultSqlInjector() {
|
|
||||||
return new JoinDefaultSqlInjector(); // 使用Mybaits Plus Join定义的SQL注入器
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnProperty(prefix = "mybatis-plus.global-config.db-config", name = "id-type", havingValue = "INPUT")
|
@ConditionalOnProperty(prefix = "mybatis-plus.global-config.db-config", name = "id-type", havingValue = "INPUT")
|
||||||
public IKeyGenerator keyGenerator(ConfigurableEnvironment environment) {
|
public IKeyGenerator keyGenerator(ConfigurableEnvironment environment) {
|
||||||
|
@ -9,7 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||||
import com.baomidou.mybatisplus.extension.toolkit.Db;
|
import com.baomidou.mybatisplus.extension.toolkit.Db;
|
||||||
import icu.mhb.mybatisplus.plugln.base.mapper.JoinBaseMapper;
|
import com.github.yulichang.base.MPJBaseMapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -17,10 +17,10 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 在 MyBatis Plus 的 BaseMapper 的基础上拓展,提供更多的能力
|
* 在 MyBatis Plus 的 BaseMapper 的基础上拓展,提供更多的能力
|
||||||
*
|
* <p>
|
||||||
* 为什么继承 JoinBaseMapper 接口?支持 MyBatis Plus 多表 Join 的能力。
|
* 为什么继承 MPJBaseMapper 接口?支持 MyBatis Plus 多表 Join 的能力。
|
||||||
*/
|
*/
|
||||||
public interface BaseMapperX<T> extends JoinBaseMapper<T> {
|
public interface BaseMapperX<T> extends MPJBaseMapper<T> {
|
||||||
|
|
||||||
default PageResult<T> selectPage(PageParam pageParam, @Param("ew") Wrapper<T> queryWrapper) {
|
default PageResult<T> selectPage(PageParam pageParam, @Param("ew") Wrapper<T> queryWrapper) {
|
||||||
// MyBatis Plus 查询
|
// MyBatis Plus 查询
|
||||||
|
@ -5,8 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.config.YudaoMybatisAutoConfiguration;
|
|||||||
import cn.iocoder.yudao.framework.test.config.SqlInitializationTestConfiguration;
|
import cn.iocoder.yudao.framework.test.config.SqlInitializationTestConfiguration;
|
||||||
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
|
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
|
||||||
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
|
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
|
||||||
import icu.mhb.mybatisplus.plugln.interceptor.JoinInterceptor;
|
import com.github.yulichang.autoconfigure.MybatisPlusJoinAutoConfiguration;
|
||||||
import icu.mhb.mybatisplus.plugln.interceptor.JoinInterceptorConfig;
|
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
@ -36,9 +35,7 @@ public class BaseDbUnitTest {
|
|||||||
// MyBatis 配置类
|
// MyBatis 配置类
|
||||||
YudaoMybatisAutoConfiguration.class, // 自己的 MyBatis 配置类
|
YudaoMybatisAutoConfiguration.class, // 自己的 MyBatis 配置类
|
||||||
MybatisPlusAutoConfiguration.class, // MyBatis 的自动配置类
|
MybatisPlusAutoConfiguration.class, // MyBatis 的自动配置类
|
||||||
// TODO @升平:看看有没可能去掉下面两个类
|
MybatisPlusJoinAutoConfiguration.class, // MyBatis 的Join配置类
|
||||||
JoinInterceptor.class, // MyBatis 的Join配置类
|
|
||||||
JoinInterceptorConfig.class, // MyBatis 的Join配置类
|
|
||||||
})
|
})
|
||||||
public static class Application {
|
public static class Application {
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,6 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
|
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
|
||||||
import icu.mhb.mybatisplus.plugln.annotations.JoinField;
|
|
||||||
import icu.mhb.mybatisplus.plugln.constant.RelevancyType;
|
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
|
||||||
@ -100,9 +98,6 @@ public class AdminUserDO extends TenantBaseDO {
|
|||||||
/**
|
/**
|
||||||
* 用户所属部门
|
* 用户所属部门
|
||||||
*/
|
*/
|
||||||
@JoinField(masterModelClass = AdminUserDO.class, masterModelField = "deptId",
|
|
||||||
sunModelClass = DeptDO.class, sunModelField = "id",
|
|
||||||
relevancyType = RelevancyType.ONT_TO_ONE, sunAlias = "d")
|
|
||||||
@TableField(exist = false, typeHandler = FastjsonTypeHandler.class)
|
@TableField(exist = false, typeHandler = FastjsonTypeHandler.class)
|
||||||
private DeptDO dept;
|
private DeptDO dept;
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
|||||||
import cn.iocoder.yudao.module.system.service.dept.PostService;
|
import cn.iocoder.yudao.module.system.service.dept.PostService;
|
||||||
import cn.iocoder.yudao.module.system.service.permission.PermissionService;
|
import cn.iocoder.yudao.module.system.service.permission.PermissionService;
|
||||||
import cn.iocoder.yudao.module.system.service.tenant.TenantService;
|
import cn.iocoder.yudao.module.system.service.tenant.TenantService;
|
||||||
import icu.mhb.mybatisplus.plugln.extend.Joins;
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
@ -776,7 +776,6 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSelectUserIncludeDept_success() {
|
public void testSelectUserIncludeDept_success() {
|
||||||
// 需设置 application-unit-test.yaml 文件中 spring.main.lazy-initialization: false
|
|
||||||
|
|
||||||
// 准备部门数据
|
// 准备部门数据
|
||||||
DeptDO dept = new DeptDO();
|
DeptDO dept = new DeptDO();
|
||||||
@ -795,13 +794,13 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest {
|
|||||||
// 调用
|
// 调用
|
||||||
Long userId = userService.createUser(reqVO);
|
Long userId = userService.createUser(reqVO);
|
||||||
|
|
||||||
// 断言
|
MPJLambdaWrapper<AdminUserDO> wrapper = new MPJLambdaWrapper<>(AdminUserDO.class)
|
||||||
AdminUserDO user = Joins.of(AdminUserDO.class)
|
.selectAll(AdminUserDO.class)
|
||||||
|
.selectAssociation(DeptDO.class, AdminUserDO::getDept)
|
||||||
.leftJoin(DeptDO.class, DeptDO::getId, AdminUserDO::getDeptId)
|
.leftJoin(DeptDO.class, DeptDO::getId, AdminUserDO::getDeptId)
|
||||||
.oneToOneSelect(AdminUserDO::getDept, DeptDO.class)
|
.eq(AdminUserDO::getId, userId);
|
||||||
.end()
|
AdminUserDO user = userMapper.selectJoinOne(AdminUserDO.class, wrapper);
|
||||||
.eq(AdminUserDO::getId, userId)
|
|
||||||
.joinGetOne(AdminUserDO.class);
|
|
||||||
System.out.println("=========>" + user);
|
System.out.println("=========>" + user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user