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
4d1ad0d26e
commit
08e4b70a02
@ -42,7 +42,7 @@ public class JSqlParserHelperV46 {
|
||||
col = selectExpressionItem.getAlias().getName();
|
||||
}
|
||||
if (StringUtils.isNotBlank(col)) {
|
||||
columConsumer.accept(StringUtils.getTargetColumn(col));
|
||||
columConsumer.accept(col);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public class JSqlParserHelper {
|
||||
col = item.getAlias().getName();
|
||||
}
|
||||
if (StringUtils.isNotBlank(col)) {
|
||||
columConsumer.accept(StringUtils.getTargetColumn(col));
|
||||
columConsumer.accept(col);
|
||||
}
|
||||
}
|
||||
parser = true;
|
||||
|
@ -3,15 +3,13 @@ package com.github.yulichang.interceptor;
|
||||
import com.baomidou.mybatisplus.core.MybatisPlusVersion;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.*;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
|
||||
import com.github.yulichang.adapter.AdapterHelper;
|
||||
import com.github.yulichang.adapter.base.tookit.VersionUtils;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
import com.github.yulichang.query.MPJQueryWrapper;
|
||||
import com.github.yulichang.toolkit.Constant;
|
||||
import com.github.yulichang.toolkit.MPJReflectionKit;
|
||||
import com.github.yulichang.toolkit.MPJTableMapperHelper;
|
||||
import com.github.yulichang.toolkit.TableHelper;
|
||||
import com.github.yulichang.toolkit.*;
|
||||
import com.github.yulichang.toolkit.support.FieldCache;
|
||||
import com.github.yulichang.wrapper.interfaces.SelectWrapper;
|
||||
import com.github.yulichang.wrapper.resultmap.IResult;
|
||||
@ -209,11 +207,12 @@ public class MPJInterceptor implements Interceptor {
|
||||
}
|
||||
} else if (wrapper.isResultMap()) {
|
||||
AdapterHelper.getAdapter().parserColum(wrapper.getAlias(), wrapper.getFrom(), i.getColumn(), col -> {
|
||||
FieldCache strField = fieldMap.get(col);
|
||||
columnSet.add(col);
|
||||
String tagCol = MPJStringUtils.getTargetColumn(col);
|
||||
FieldCache strField = fieldMap.get(tagCol);
|
||||
columnSet.add(tagCol);
|
||||
if (Objects.nonNull(strField)) {
|
||||
ResultMapping.Builder builder = new ResultMapping.Builder(ms.getConfiguration(), col,
|
||||
col, strField.getType());
|
||||
ResultMapping.Builder builder = new ResultMapping.Builder(ms.getConfiguration(), tagCol,
|
||||
tagCol, strField.getType());
|
||||
resultMappings.add(selectToResult(wrapper.getEntityClass(), i, strField.getType(), builder));
|
||||
}
|
||||
});
|
||||
@ -262,7 +261,7 @@ public class MPJInterceptor implements Interceptor {
|
||||
childId.append("(");
|
||||
Map<String, FieldCache> ofTypeField = MPJReflectionKit.getFieldMap(mybatisLabel.getOfType());
|
||||
//列名去重
|
||||
String columnName = StringUtils.getTargetColumn(r.getSelectNormal().getColumn());
|
||||
String columnName = r.getSelectNormal().getTagColumn();
|
||||
SelectLabel label;
|
||||
FieldCache field = ofTypeField.get(r.getProperty());
|
||||
String index = r.getIndex();
|
||||
|
@ -36,6 +36,18 @@ import static java.util.stream.Collectors.joining;
|
||||
@SuppressWarnings("ALL")
|
||||
public final class MPJStringUtils {
|
||||
|
||||
/**
|
||||
* 判断是否是中文
|
||||
*/
|
||||
public static boolean isChinese(String str) {
|
||||
if(isBlank(str))
|
||||
return false;
|
||||
char c = str.charAt(0);
|
||||
return c >= 0x4E00 && c <= 0x9FA5;
|
||||
}
|
||||
|
||||
/* *************************** 以下为拷贝内容 **************************** */
|
||||
|
||||
/**
|
||||
* 字符串 is
|
||||
*/
|
||||
@ -138,6 +150,9 @@ public final class MPJStringUtils {
|
||||
* @return 字段名
|
||||
*/
|
||||
public static String getTargetColumn(String column) {
|
||||
if(isChinese(column)){
|
||||
return column;
|
||||
}
|
||||
if (isNotColumnName(column)) {
|
||||
return column.substring(1, column.length() - 1);
|
||||
}
|
||||
@ -303,7 +318,7 @@ public final class MPJStringUtils {
|
||||
*/
|
||||
public static String quotaMarkList(Collection<?> coll) {
|
||||
return coll.stream().map(MPJStringUtils::quotaMark)
|
||||
.collect(joining(StringPool.COMMA, StringPool.LEFT_BRACKET, StringPool.RIGHT_BRACKET));
|
||||
.collect(joining(StringPool.COMMA, StringPool.LEFT_BRACKET, StringPool.RIGHT_BRACKET));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -522,8 +537,8 @@ public final class MPJStringUtils {
|
||||
char lastChar = 'a';
|
||||
for (char c : s.toCharArray()) {
|
||||
if ((Character.isWhitespace(lastChar)) && (!Character.isWhitespace(c))
|
||||
&& ('-' != c) && (buf.length() > 0)
|
||||
&& (buf.charAt(buf.length() - 1) != '-')) {
|
||||
&& ('-' != c) && (buf.length() > 0)
|
||||
&& (buf.charAt(buf.length() - 1) != '-')) {
|
||||
buf.append(StringPool.DASH);
|
||||
}
|
||||
if ('_' == c) {
|
||||
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.toolkit.MPJStringUtils;
|
||||
import com.github.yulichang.toolkit.TableHelper;
|
||||
import lombok.Getter;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
@ -75,7 +76,7 @@ public class SelectCache {
|
||||
this.column = column;
|
||||
this.columnType = columnType;
|
||||
this.columProperty = columProperty;
|
||||
this.tagColumn = StringUtils.getTargetColumn(column);
|
||||
this.tagColumn = MPJStringUtils.getTargetColumn(column);
|
||||
this.tableFieldInfo = tableFieldInfo;
|
||||
if (Objects.isNull(tableFieldInfo)) {
|
||||
this.hasTypeHandle = false;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.github.yulichang.wrapper.segments;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
|
||||
import org.apache.ibatis.type.TypeHandler;
|
||||
|
||||
@ -18,7 +17,7 @@ public class SelectString implements Select {
|
||||
|
||||
public SelectString(String column, String tagProperty) {
|
||||
this.column = column;
|
||||
this.tagProperty = null == tagProperty ? null : StringUtils.getTargetColumn(tagProperty);
|
||||
this.tagProperty = tagProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,7 +2,6 @@ package com.github.yulichang.wrapper.segments;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
|
||||
import org.apache.ibatis.type.TypeHandler;
|
||||
|
||||
@ -29,7 +28,7 @@ public class SelectSub implements Select {
|
||||
this.column = column;
|
||||
this.hasTableAlias = hasTableAlias;
|
||||
this.tableAlias = tableAlias;
|
||||
this.tagProperty = null == tagProperty ? null : StringUtils.getTargetColumn(tagProperty);
|
||||
this.tagProperty = tagProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,6 +59,9 @@
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<github.global.server>github</github.global.server>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
<argLine>-Dfile.encoding=UTF-8</argLine>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -0,0 +1,27 @@
|
||||
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 lombok.Data;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@FieldNameConstants
|
||||
@TableName(value = "user_tenanta",autoResultMap = true)
|
||||
public class UserTenantaDO {
|
||||
|
||||
@TableId("id")
|
||||
private Integer idea;
|
||||
|
||||
@TableField("user_id")
|
||||
private Integer uuid;
|
||||
|
||||
private Integer tenantId;
|
||||
|
||||
@TableField("中文字段")
|
||||
private String detail;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.github.yulichang.test.join.mapper;
|
||||
|
||||
import com.github.yulichang.test.join.entity.UserTenantaDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
@SuppressWarnings("unused")
|
||||
public interface UserTenantaMapper extends MyBaseMapper<UserTenantaDO> {
|
||||
|
||||
|
||||
}
|
@ -110,4 +110,15 @@ INSERT INTO user_tenant (id,user_id, tenant_id) VALUES
|
||||
(5, 5, 1),
|
||||
(6, 6, 2),
|
||||
(7, 7, 2),
|
||||
(8, 8, 2);
|
||||
(8, 8, 2);
|
||||
|
||||
DELETE FROM user_tenanta;
|
||||
INSERT INTO user_tenanta (id,user_id, tenant_id, 中文字段) VALUES
|
||||
(1, 1, 1, '中文字段1'),
|
||||
(2, 2, 1, '中文字段2'),
|
||||
(3, 3, 1, '中文字段3'),
|
||||
(4, 4, 1, '中文字段4'),
|
||||
(5, 5, 1, '中文字段5'),
|
||||
(6, 6, 2, '中文字段6'),
|
||||
(7, 7, 2, '中文字段7'),
|
||||
(8, 8, 2, '中文字段8');
|
@ -19,16 +19,16 @@ create table `user`
|
||||
(
|
||||
id int auto_increment
|
||||
primary key,
|
||||
`pid` int null,
|
||||
`name` varchar(255) null,
|
||||
`json` varchar(255) null,
|
||||
`address_id` int null,
|
||||
`address_id2` int null,
|
||||
sex tinyint null,
|
||||
head_img varchar(255) null,
|
||||
create_time datetime null,
|
||||
create_by int null,
|
||||
update_by int null,
|
||||
`pid` int null,
|
||||
`name` varchar(255) null,
|
||||
`json` varchar(255) null,
|
||||
`address_id` int null,
|
||||
`address_id2` int null,
|
||||
sex tinyint null,
|
||||
head_img varchar(255) null,
|
||||
create_time datetime null,
|
||||
create_by int null,
|
||||
update_by int null,
|
||||
del bit
|
||||
);
|
||||
|
||||
@ -49,9 +49,9 @@ create table user_dto
|
||||
(
|
||||
id int auto_increment
|
||||
primary key,
|
||||
user_id int null,
|
||||
create_by int null,
|
||||
update_by int null,
|
||||
user_id int null,
|
||||
create_by int null,
|
||||
update_by int null,
|
||||
del bit null
|
||||
);
|
||||
|
||||
@ -60,16 +60,26 @@ create table order_t
|
||||
(
|
||||
id int auto_increment
|
||||
primary key,
|
||||
user_id int null,
|
||||
age int null,
|
||||
name varchar(255) null
|
||||
user_id int null,
|
||||
age int null,
|
||||
name varchar(255) null
|
||||
);
|
||||
|
||||
DROP TABLE IF EXISTS user_tenant;
|
||||
create table user_tenant
|
||||
(
|
||||
id int auto_increment
|
||||
id int auto_increment
|
||||
primary key,
|
||||
user_id int null,
|
||||
tenant_id int null
|
||||
user_id int null,
|
||||
tenant_id int null
|
||||
);
|
||||
|
||||
DROP TABLE IF EXISTS user_tenanta;
|
||||
create table user_tenanta
|
||||
(
|
||||
id int auto_increment
|
||||
primary key,
|
||||
user_id int null,
|
||||
tenant_id int null,
|
||||
中文字段 varchar(255) null
|
||||
);
|
@ -0,0 +1,19 @@
|
||||
package com.github.yulichang.test.join.m;
|
||||
|
||||
import com.github.yulichang.test.join.entity.UserTenantaDO;
|
||||
import com.github.yulichang.toolkit.JoinWrappers;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class ChineseFieldTest {
|
||||
|
||||
@Test
|
||||
void chineseField() {
|
||||
List<UserTenantaDO> list = JoinWrappers.lambda(UserTenantaDO.class).list();
|
||||
assert list.get(0).getDetail() != null;
|
||||
list.forEach(System.out::println);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user