mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
This commit is contained in:
parent
543c987983
commit
52a0eb3cc9
@ -105,14 +105,14 @@ public class SelectCache implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class Cache {
|
public static class Cache {
|
||||||
private static final Map<Class<?>, Map<Class<?>, TypeHandler<?>>> CACHE = new ConcurrentHashMap<>();
|
private static final Map<Class<?>, Map<String, TypeHandler<?>>> CACHE = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public static TypeHandler<?> getTypeHandlerCache(Class<?> table, Class<? extends TypeHandler<?>> typeHandler, Class<?> propertyType, String columProperty) {
|
public static TypeHandler<?> getTypeHandlerCache(Class<?> table, Class<? extends TypeHandler<?>> typeHandler, Class<?> propertyType, String columProperty) {
|
||||||
if (table == null || typeHandler == null) {
|
if (table == null || typeHandler == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Map<Class<?>, TypeHandler<?>> map = CACHE.computeIfAbsent(table, k -> new ConcurrentHashMap<>());
|
Map<String, TypeHandler<?>> map = CACHE.computeIfAbsent(table, k -> new ConcurrentHashMap<>());
|
||||||
return map.computeIfAbsent(typeHandler, k -> {
|
return map.computeIfAbsent(columProperty, k -> {
|
||||||
TableInfo info = TableHelper.getAssert(table);
|
TableInfo info = TableHelper.getAssert(table);
|
||||||
@SuppressWarnings("OptionalGetWithoutIsPresent")
|
@SuppressWarnings("OptionalGetWithoutIsPresent")
|
||||||
TableFieldInfo fieldInfo = info.getFieldList().stream().filter(f -> f.getProperty().equals(columProperty)).findFirst().get();
|
TableFieldInfo fieldInfo = info.getFieldList().stream().filter(f -> f.getProperty().equals(columProperty)).findFirst().get();
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.github.yulichang.test.join.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||||
|
import com.github.yulichang.annotation.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.ToString;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Table
|
||||||
|
@Data
|
||||||
|
@ToString
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@TableName(value = "tablea", autoResultMap = true)
|
||||||
|
public class TableA {
|
||||||
|
|
||||||
|
@TableId
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||||
|
private Map<String, Integer> mapCol;
|
||||||
|
|
||||||
|
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||||
|
private Inner entryCol;
|
||||||
|
|
||||||
|
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||||
|
private List<String> listCol;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@ToString
|
||||||
|
public static class Inner{
|
||||||
|
private String name;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.github.yulichang.test.join.mapper;
|
||||||
|
|
||||||
|
import com.github.yulichang.test.join.entity.TableA;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public interface TableAMapper extends MyBaseMapper<TableA> {
|
||||||
|
|
||||||
|
}
|
@ -122,3 +122,15 @@ INSERT INTO user_tenanta (id,user_id, tenant_id, 中文字段) VALUES
|
|||||||
(6, 6, 2, '中文字段6'),
|
(6, 6, 2, '中文字段6'),
|
||||||
(7, 7, 2, '中文字段7'),
|
(7, 7, 2, '中文字段7'),
|
||||||
(8, 8, 2, '中文字段8');
|
(8, 8, 2, '中文字段8');
|
||||||
|
|
||||||
|
|
||||||
|
DELETE FROM tablea;
|
||||||
|
INSERT INTO tablea (id,map_col, entry_col,list_col) VALUES
|
||||||
|
(1, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]'),
|
||||||
|
(2, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]'),
|
||||||
|
(3, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]'),
|
||||||
|
(4, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]'),
|
||||||
|
(5, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]'),
|
||||||
|
(6, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]'),
|
||||||
|
(7, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]'),
|
||||||
|
(8, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]');
|
@ -117,3 +117,14 @@ INSERT INTO user_tenanta (id,user_id, tenant_id, 中文字段) VALUES (5, 5, 1,
|
|||||||
INSERT INTO user_tenanta (id,user_id, tenant_id, 中文字段) VALUES (6, 6, 2, '中文字段6');
|
INSERT INTO user_tenanta (id,user_id, tenant_id, 中文字段) VALUES (6, 6, 2, '中文字段6');
|
||||||
INSERT INTO user_tenanta (id,user_id, tenant_id, 中文字段) VALUES (7, 7, 2, '中文字段7');
|
INSERT INTO user_tenanta (id,user_id, tenant_id, 中文字段) VALUES (7, 7, 2, '中文字段7');
|
||||||
INSERT INTO user_tenanta (id,user_id, tenant_id, 中文字段) VALUES (8, 8, 2, '中文字段8');
|
INSERT INTO user_tenanta (id,user_id, tenant_id, 中文字段) VALUES (8, 8, 2, '中文字段8');
|
||||||
|
|
||||||
|
DELETE FROM tablea;
|
||||||
|
INSERT INTO tablea (id,map_col, entry_col,list_col) VALUES
|
||||||
|
(1, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]'),
|
||||||
|
(2, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]'),
|
||||||
|
(3, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]'),
|
||||||
|
(4, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]'),
|
||||||
|
(5, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]'),
|
||||||
|
(6, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]'),
|
||||||
|
(7, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]'),
|
||||||
|
(8, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]');
|
@ -83,3 +83,13 @@ create table user_tenanta
|
|||||||
tenant_id int null,
|
tenant_id int null,
|
||||||
中文字段 varchar(255) null
|
中文字段 varchar(255) null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS tablea;
|
||||||
|
create table tablea
|
||||||
|
(
|
||||||
|
id int
|
||||||
|
primary key,
|
||||||
|
map_col varchar(255) null,
|
||||||
|
entry_col varchar(255) null,
|
||||||
|
list_col varchar(255) null
|
||||||
|
);
|
@ -117,3 +117,14 @@ INSERT INTO user_tenanta (id,user_id, tenant_id, 中文字段) VALUES (5, 5, 1,
|
|||||||
INSERT INTO user_tenanta (id,user_id, tenant_id, 中文字段) VALUES (6, 6, 2, '中文字段6');
|
INSERT INTO user_tenanta (id,user_id, tenant_id, 中文字段) VALUES (6, 6, 2, '中文字段6');
|
||||||
INSERT INTO user_tenanta (id,user_id, tenant_id, 中文字段) VALUES (7, 7, 2, '中文字段7');
|
INSERT INTO user_tenanta (id,user_id, tenant_id, 中文字段) VALUES (7, 7, 2, '中文字段7');
|
||||||
INSERT INTO user_tenanta (id,user_id, tenant_id, 中文字段) VALUES (8, 8, 2, '中文字段8');
|
INSERT INTO user_tenanta (id,user_id, tenant_id, 中文字段) VALUES (8, 8, 2, '中文字段8');
|
||||||
|
|
||||||
|
DELETE FROM tablea;
|
||||||
|
INSERT INTO tablea (id,map_col, entry_col,list_col) VALUES
|
||||||
|
(1, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]'),
|
||||||
|
(2, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]'),
|
||||||
|
(3, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]'),
|
||||||
|
(4, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]'),
|
||||||
|
(5, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]'),
|
||||||
|
(6, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]'),
|
||||||
|
(7, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]'),
|
||||||
|
(8, '{"id":1}', '{"name":"Tom"}', '["jerry","Spike"]');
|
@ -83,3 +83,13 @@ create table user_tenanta
|
|||||||
tenant_id int null,
|
tenant_id int null,
|
||||||
中文字段 varchar(255) null
|
中文字段 varchar(255) null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS tablea;
|
||||||
|
create table tablea
|
||||||
|
(
|
||||||
|
id int
|
||||||
|
primary key,
|
||||||
|
map_col varchar(255) null,
|
||||||
|
entry_col varchar(255) null,
|
||||||
|
list_col varchar(255) null
|
||||||
|
);
|
||||||
|
@ -83,3 +83,13 @@ create table user_tenanta
|
|||||||
tenant_id int null,
|
tenant_id int null,
|
||||||
中文字段 varchar(255) null
|
中文字段 varchar(255) null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS tablea;
|
||||||
|
create table tablea
|
||||||
|
(
|
||||||
|
id int
|
||||||
|
primary key,
|
||||||
|
map_col varchar(255) null,
|
||||||
|
entry_col varchar(255) null,
|
||||||
|
list_col varchar(255) null
|
||||||
|
);
|
@ -1,5 +1,6 @@
|
|||||||
package com.github.yulichang.test.join.unit;
|
package com.github.yulichang.test.join.unit;
|
||||||
|
|
||||||
|
import com.github.yulichang.test.join.entity.TableA;
|
||||||
import com.github.yulichang.test.join.entity.UserDO;
|
import com.github.yulichang.test.join.entity.UserDO;
|
||||||
import com.github.yulichang.test.util.Reset;
|
import com.github.yulichang.test.util.Reset;
|
||||||
import com.github.yulichang.toolkit.JoinWrappers;
|
import com.github.yulichang.toolkit.JoinWrappers;
|
||||||
@ -19,7 +20,7 @@ public class TypeHandlerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void typeHandler(){
|
void typeHandler() {
|
||||||
MPJLambdaWrapper<UserDO> wrapper = JoinWrappers.lambda(UserDO.class);
|
MPJLambdaWrapper<UserDO> wrapper = JoinWrappers.lambda(UserDO.class);
|
||||||
|
|
||||||
List<UserDO> list = wrapper.list();
|
List<UserDO> list = wrapper.list();
|
||||||
@ -28,4 +29,17 @@ public class TypeHandlerTest {
|
|||||||
|
|
||||||
list.forEach(System.out::println);
|
list.forEach(System.out::println);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void typeHandler1() {
|
||||||
|
MPJLambdaWrapper<TableA> wrapper = JoinWrappers.lambda(TableA.class);
|
||||||
|
|
||||||
|
List<TableA> list = wrapper.list();
|
||||||
|
|
||||||
|
assert list.get(0).getListCol() != null;
|
||||||
|
assert list.get(0).getEntryCol() != null;
|
||||||
|
assert list.get(0).getMapCol() != null;
|
||||||
|
|
||||||
|
list.forEach(System.out::println);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user