mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 09:08:24 +08:00
滞后FieldWrapper的setter的空判断,添加getter的空判断
因为部分情况下,构建FieldWrapper后,并不需要用到setter方法,所以通常字段上就不声明对应的setter了,但是此时会报错。把错误滞后到调用的时候,可以兼顾的解决问题
This commit is contained in:
parent
f2b9688eea
commit
b47bcbfbc7
@ -62,10 +62,6 @@ public class FieldWrapper {
|
||||
&& Modifier.isPublic(method.getModifiers())
|
||||
&& method.getName().equals(setterName));
|
||||
|
||||
if (setter == null) {
|
||||
throw new IllegalStateException("Can not find method \"set" + StringUtil.firstCharToUpperCase(fieldName) + "\" in class: " + clazz);
|
||||
}
|
||||
|
||||
fieldWrapper = new FieldWrapper();
|
||||
fieldWrapper.field = findField;
|
||||
fieldWrapper.fieldType = findField.getType();
|
||||
@ -120,6 +116,9 @@ public class FieldWrapper {
|
||||
|
||||
public void set(Object value, Object to) {
|
||||
try {
|
||||
if (setterMethod == null) {
|
||||
throw new IllegalStateException("Can not find method \"set" + StringUtil.firstCharToUpperCase(field.getName()) + "\" in class: " + to.getClass());
|
||||
}
|
||||
setterMethod.invoke(to, value);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
@ -128,6 +127,9 @@ public class FieldWrapper {
|
||||
|
||||
public Object get(Object target) {
|
||||
try {
|
||||
if (getterMethod == null) {
|
||||
throw new IllegalStateException("Can not find method \"get" + StringUtil.firstCharToUpperCase(field.getName()) + ", is" + StringUtil.firstCharToUpperCase(field.getName()) + "\" in class: " + target.getClass());
|
||||
}
|
||||
return getterMethod.invoke(target);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user