|
|
@@ -172,9 +172,28 @@ public class BaseDao<T extends BaseEntity> {
|
|
|
* @param k 指定对象
|
|
|
* @return 指定字段的值
|
|
|
*/
|
|
|
- private <K> Object getValue(String field, @NotEmpty("k") K k) throws IllegalStateException, NoSuchFieldException {
|
|
|
- Field declaredField = k.getClass().getDeclaredField(field);
|
|
|
- return getValue(declaredField, k);
|
|
|
+ private <K> Object getValue(@NotEmpty("field") String field, @NotEmpty("k") K k) throws IllegalStateException, NoSuchFieldException {
|
|
|
+ return getValue(getField(field, k.getClass()), k);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 递归获取指定类的指定字段(包括父类的私有字段)
|
|
|
+ *
|
|
|
+ * @param field 指定字段
|
|
|
+ * @param clazz 指定类
|
|
|
+ * @return 指定字段
|
|
|
+ * @throws NoSuchFieldException
|
|
|
+ */
|
|
|
+ private Field getField(@NotEmpty("field") String field, @NotEmpty("clazz") Class<?> clazz) throws NoSuchFieldException {
|
|
|
+ try {
|
|
|
+ return clazz.getDeclaredField(field);
|
|
|
+ } catch (NoSuchFieldException e) {
|
|
|
+ Class<?> superclass = clazz.getSuperclass();
|
|
|
+ if (superclass != null) {
|
|
|
+ return getField(field, superclass);
|
|
|
+ }
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -258,8 +277,8 @@ public class BaseDao<T extends BaseEntity> {
|
|
|
String message = e.getMessage();
|
|
|
int leftIndex = message.indexOf("{");
|
|
|
int rightIndex = message.indexOf("}");
|
|
|
- message = message.substring(leftIndex + 5, rightIndex - 2);
|
|
|
- return "已存在:" + message;
|
|
|
+ message = message.substring(leftIndex + 4, rightIndex - 1);
|
|
|
+ return "已存在:{" + message.replace(":", "") + "}";
|
|
|
}
|
|
|
|
|
|
/**
|