|
@@ -50,31 +50,31 @@ import java.util.Map;
|
|
@MapperScan(value = "com.baomidou.mybatisplus.test.h2")
|
|
@MapperScan(value = "com.baomidou.mybatisplus.test.h2")
|
|
@ContextConfiguration(classes = {MybatisMapperRegistryTest.class, DBConfig.class})
|
|
@ContextConfiguration(classes = {MybatisMapperRegistryTest.class, DBConfig.class})
|
|
class MybatisMapperRegistryTest extends BaseTest {
|
|
class MybatisMapperRegistryTest extends BaseTest {
|
|
-
|
|
|
|
|
|
+
|
|
private interface H2StudentChildrenMapper extends H2StudentMapper {
|
|
private interface H2StudentChildrenMapper extends H2StudentMapper {
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Bean
|
|
@Bean
|
|
DBConfig dbConfig() {
|
|
DBConfig dbConfig() {
|
|
return new DBConfig();
|
|
return new DBConfig();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Bean
|
|
@Bean
|
|
MybatisPlusConfig mybatisPlusConfig() {
|
|
MybatisPlusConfig mybatisPlusConfig() {
|
|
return new MybatisPlusConfig();
|
|
return new MybatisPlusConfig();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Bean
|
|
@Bean
|
|
SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
|
|
SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
|
|
MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
|
|
MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
|
|
sqlSessionFactory.setDataSource(dataSource);
|
|
sqlSessionFactory.setDataSource(dataSource);
|
|
return sqlSessionFactory.getObject();
|
|
return sqlSessionFactory.getObject();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private SqlSessionFactory sqlSessionFactory;
|
|
private SqlSessionFactory sqlSessionFactory;
|
|
-
|
|
|
|
|
|
+
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
@Test
|
|
@Test
|
|
void test() throws ReflectiveOperationException {
|
|
void test() throws ReflectiveOperationException {
|
|
@@ -84,21 +84,21 @@ class MybatisMapperRegistryTest extends BaseTest {
|
|
Assertions.assertTrue(mapperRegistry.hasMapper(H2UserMapper.class));
|
|
Assertions.assertTrue(mapperRegistry.hasMapper(H2UserMapper.class));
|
|
Assertions.assertTrue(mapperRegistry.hasMapper(H2StudentChildrenMapper.class));
|
|
Assertions.assertTrue(mapperRegistry.hasMapper(H2StudentChildrenMapper.class));
|
|
H2StudentMapper studentMapper = mapperRegistry.getMapper(H2StudentMapper.class, sqlSession);
|
|
H2StudentMapper studentMapper = mapperRegistry.getMapper(H2StudentMapper.class, sqlSession);
|
|
-
|
|
|
|
|
|
+
|
|
Assertions.assertTrue(configuration.hasStatement(H2StudentMapper.class.getName() + ".selectById"));
|
|
Assertions.assertTrue(configuration.hasStatement(H2StudentMapper.class.getName() + ".selectById"));
|
|
studentMapper.selectById(1);
|
|
studentMapper.selectById(1);
|
|
-
|
|
|
|
|
|
+
|
|
Field field = mapperRegistry.getClass().getDeclaredField("knownMappers");
|
|
Field field = mapperRegistry.getClass().getDeclaredField("knownMappers");
|
|
field.setAccessible(true);
|
|
field.setAccessible(true);
|
|
Map<Class<?>, MybatisMapperProxyFactory<?>> knownMappers = (Map<Class<?>, MybatisMapperProxyFactory<?>>) field.get(mapperRegistry);
|
|
Map<Class<?>, MybatisMapperProxyFactory<?>> knownMappers = (Map<Class<?>, MybatisMapperProxyFactory<?>>) field.get(mapperRegistry);
|
|
MybatisMapperProxyFactory<?> mybatisMapperProxyFactory = knownMappers.get(H2StudentChildrenMapper.class);
|
|
MybatisMapperProxyFactory<?> mybatisMapperProxyFactory = knownMappers.get(H2StudentChildrenMapper.class);
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
H2StudentChildrenMapper h2StudentChildrenMapper = mapperRegistry.getMapper(H2StudentChildrenMapper.class, sqlSession);
|
|
H2StudentChildrenMapper h2StudentChildrenMapper = mapperRegistry.getMapper(H2StudentChildrenMapper.class, sqlSession);
|
|
- Assertions.assertFalse(configuration.hasStatement(H2StudentChildrenMapper.class.getName() + ".selectById"));
|
|
|
|
|
|
+ Assertions.assertTrue(configuration.hasStatement(H2StudentChildrenMapper.class.getName() + ".selectById"));
|
|
Map<Method, ?> methodCache = mybatisMapperProxyFactory.getMethodCache();
|
|
Map<Method, ?> methodCache = mybatisMapperProxyFactory.getMethodCache();
|
|
Assertions.assertTrue(methodCache.isEmpty());
|
|
Assertions.assertTrue(methodCache.isEmpty());
|
|
-
|
|
|
|
|
|
+
|
|
h2StudentChildrenMapper.selectById(2);
|
|
h2StudentChildrenMapper.selectById(2);
|
|
methodCache = mybatisMapperProxyFactory.getMethodCache();
|
|
methodCache = mybatisMapperProxyFactory.getMethodCache();
|
|
Assertions.assertFalse(methodCache.isEmpty());
|
|
Assertions.assertFalse(methodCache.isEmpty());
|