From 540641abaf7edc3de2b51b7ef99b7cf4df95c2e4 Mon Sep 17 00:00:00 2001 From: wuy <1311695042@qq.com> Date: Fri, 3 Jul 2020 13:43:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=80=BC=E6=8F=90=E5=8F=96=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/diboot/core/binding/QueryBuilder.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java b/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java index 4c039a7..b2d90b5 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java @@ -38,6 +38,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.*; @@ -331,8 +333,10 @@ public class QueryBuilder { */ private static LinkedHashMap extractNotNullValues(DTO dto, Collection fields){ LinkedHashMap resultMap = new LinkedHashMap<>(); + Class dtoClass = dto.getClass(); + // 转换 - List declaredFields = BeanUtils.extractAllFields(dto.getClass()); + List declaredFields = BeanUtils.extractAllFields(dtoClass); for (Field field : declaredFields) { // 非指定属性,非逻辑删除字段,跳过 if (fields != null && !fields.contains(field.getName())) { @@ -350,8 +354,17 @@ public class QueryBuilder { Object value = null; try { value = field.get(dto); + if (V.isEmpty(value)) { + String prefix = V.equals("boolean", field.getType().getName()) ? "is" : "get"; + Method method = dtoClass.getMethod(prefix + S.capFirst(field.getName())); + value = method.invoke(dto); + } } catch (IllegalAccessException e) { log.error("通过反射获取属性值出错:{}", e.getMessage()); + } catch (NoSuchMethodException e) { + log.warn("通过反射获取属性方法不存在:{}", e.getMessage()); + } catch (InvocationTargetException e) { + log.warn("通过反射执行属性方法出错:{}", e.getMessage()); } // 忽略逻辑删除字段 if(Cons.FieldName.deleted.name().equals(field.getName())