| | |
| | | package org.yeshi.utils.annotation;
|
| | |
|
| | | import java.lang.annotation.Annotation;
|
| | | import java.lang.reflect.Field;
|
| | | import java.util.Properties;
|
| | |
|
| | | public class MapUtil {
|
| | |
|
| | | public static Object parseMap(Class<?> clazz, Properties ps) {
|
| | | System.out.println(clazz.getName());
|
| | | Object target = null;
|
| | | try {
|
| | | Class clz = Class.forName(clazz.getName());
|
| | | target = clz.newInstance();
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | Field[] fields = clazz.getDeclaredFields();
|
| | | for (Field fd : fields) {
|
| | | fd.setAccessible(true);
|
| | | Annotation[] as = fd.getAnnotations();
|
| | | for (Annotation a : as) {
|
| | | if (a instanceof Map) {
|
| | | Map c = (Map) a;
|
| | | try {
|
| | | fd.set(target, new String(ps.getProperty(c.value()).getBytes("ISO-8859-1"), "UTF-8"));
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | return target;
|
| | | }
|
| | |
|
| | | }
|
| | | package org.yeshi.utils.annotation; |
| | | |
| | | import java.lang.annotation.Annotation; |
| | | import java.lang.reflect.Field; |
| | | import java.util.Properties; |
| | | |
| | | public class MapUtil { |
| | | |
| | | public static Object parseMap(Class<?> clazz, Properties ps) { |
| | | System.out.println(clazz.getName()); |
| | | Object target = null; |
| | | try { |
| | | Class clz = Class.forName(clazz.getName()); |
| | | target = clz.newInstance(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | Field[] fields = clazz.getDeclaredFields(); |
| | | for (Field fd : fields) { |
| | | fd.setAccessible(true); |
| | | Annotation[] as = fd.getAnnotations(); |
| | | for (Annotation a : as) { |
| | | if (a instanceof Map) { |
| | | Map c = (Map) a; |
| | | try { |
| | | fd.set(target, new String(ps.getProperty(c.value()).getBytes("ISO-8859-1"), "UTF-8")); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return target; |
| | | } |
| | | |
| | | } |