From 2af3e6b7ba3fcca698d8b726e0abf7a35ab8e086 Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Thu, 10 Nov 2022 18:11:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=8C=96=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mybatis-plus-join-boot-starter/pom.xml | 2 +- mybatis-plus-join-core/pom.xml | 2 +- .../yulichang/interceptor/MPJInterceptor.java | 21 ++++++++++++------- pom.xml | 4 +++- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/mybatis-plus-join-boot-starter/pom.xml b/mybatis-plus-join-boot-starter/pom.xml index f5de497..d4fbc88 100644 --- a/mybatis-plus-join-boot-starter/pom.xml +++ b/mybatis-plus-join-boot-starter/pom.xml @@ -42,7 +42,7 @@ com.github.yulichang mybatis-plus-join-core - 1.3.0 + ${mybaits-plus-join.version} diff --git a/mybatis-plus-join-core/pom.xml b/mybatis-plus-join-core/pom.xml index cc6a216..164d398 100644 --- a/mybatis-plus-join-core/pom.xml +++ b/mybatis-plus-join-core/pom.xml @@ -43,7 +43,7 @@ com.github.yulichang mybatis-plus-join-annotation - 1.3.0 + ${mybaits-plus-join.version} \ No newline at end of file diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java index d2f5363..18c4e81 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java @@ -161,7 +161,7 @@ public class MPJInterceptor implements Interceptor { //移除对多查询列,为了可重复使用wrapper columnList.removeIf(SelectColumn::isLabel); List resultMappings = new ArrayList<>(columnList.size()); - columnList.forEach(i -> { + for (SelectColumn i : columnList) { TableFieldInfo info = i.getTableFieldInfo(); if (StringUtils.isNotBlank(i.getAlias())) { //优先别名查询 selectFunc selectAs @@ -180,23 +180,27 @@ public class MPJInterceptor implements Interceptor { // select selectAll selectAsClass if (i.getFuncEnum() == null || StringUtils.isBlank(i.getFuncEnum().getSql())) { ResultMapping.Builder builder = new ResultMapping.Builder(ms.getConfiguration(), info.getProperty(), - info.getColumn(), info.getPropertyType()); + StringUtils.getTargetColumn(info.getColumn()), info.getPropertyType()); if (info.getTypeHandler() != null && info.getTypeHandler() != UnknownTypeHandler.class) { Field f = fieldMap.get(info.getProperty()); - if (f != null && f.getType() == info.getField().getType()) { + if (f == null) { + continue; + } + if (f.getType() == info.getField().getType()) { builder.typeHandler(getTypeHandler(ms, info)); } } resultMappings.add(builder.build()); } else { - resultMappings.add(new ResultMapping.Builder(ms.getConfiguration(), info.getProperty(), info.getColumn(), info.getPropertyType()).build()); + resultMappings.add(new ResultMapping.Builder(ms.getConfiguration(), info.getProperty(), + StringUtils.getTargetColumn(info.getColumn()), info.getPropertyType()).build()); } } else { // 主键列 - resultMappings.add(new ResultMapping.Builder(ms.getConfiguration(), i.getTagProperty(), i.getColumnName(), - i.getKeyType()).build()); + resultMappings.add(new ResultMapping.Builder(ms.getConfiguration(), i.getTagProperty(), + StringUtils.getTargetColumn(i.getColumnName()), i.getKeyType()).build()); } - }); + } Set columnSet = resultMappings.stream().map(ResultMapping::getColumn).collect(Collectors.toSet()); //移除result中不存在的标签 resultMappings.removeIf(i -> !fieldMap.containsKey(i.getProperty())); @@ -214,7 +218,8 @@ public class MPJInterceptor implements Interceptor { columnName = getColumn(columnSet, columnName); columnList.add(SelectColumn.of(mpjColl.getEntityClass(), r.getColumn(), null, Objects.equals(columnName, r.getColumn()) ? null : columnName, null, null, true, null)); - ResultMapping.Builder builder = new ResultMapping.Builder(ms.getConfiguration(), r.getProperty(), columnName, r.getJavaType()); + ResultMapping.Builder builder = new ResultMapping.Builder(ms.getConfiguration(), r.getProperty(), + StringUtils.getTargetColumn(columnName), r.getJavaType()); if (r.isId()) {//主键标记为id标签 builder.flags(Collections.singletonList(ResultFlag.ID)); } diff --git a/pom.xml b/pom.xml index 41cc966..c76f495 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.github.yulichang mybatis-plus-join-root pom - 1.3.0 + ${mybaits-plus-join.version} mybatis-plus-join-root An enhanced toolkit of Mybatis-Plus to simplify development. @@ -37,6 +37,8 @@ + 1.3.0 + UTF-8 github 1.8