diff --git a/.gitignore b/.gitignore index 79bae6d..22dac44 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ -*.class - -# Package Files # -*.jar -*.war +*.class + +# Package Files # +*.jar +*.war *.ear /target/ -target +target +com diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 365bbd6..cf6931b 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -1,5 +1,4 @@ eclipse.preferences.version=1 encoding//src/main/java=UTF-8 encoding//src/main/resources=UTF-8 -encoding//src/test/java=UTF-8 encoding/=UTF-8 diff --git a/pom.xml b/pom.xml index 5165e0f..669752d 100644 --- a/pom.xml +++ b/pom.xml @@ -13,6 +13,10 @@ UTF-8 4.2.4.RELEASE 2.5 + 3.2.7 + 1.1.1 + 0.0.1 + 1.3.2 @@ -112,8 +116,44 @@ ${servlet.version} provided + + + + org.mybatis + mybatis + ${mybatis.version} + + + org.mybatis + mybatis-spring + ${mybatis.spring.version} + + + com.github.loafer + mybatis-paging + ${mybatis.paging.version} + + + org.mybatis.generator + mybatis-generator-core + ${mybatis.generator.core.version} + + useful-code + + + + org.mybatis.generator + mybatis-generator-maven-plugin + 1.3.2 + + true + true + + + + diff --git a/src/main/java/osc/git/eh3/test/TestCode.java b/src/main/java/osc/git/eh3/test/TestCode.java index 794238b..a5abe13 100644 --- a/src/main/java/osc/git/eh3/test/TestCode.java +++ b/src/main/java/osc/git/eh3/test/TestCode.java @@ -1,11 +1,17 @@ package osc.git.eh3.test; +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; import java.math.BigDecimal; import java.net.InetAddress; import java.net.UnknownHostException; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Calendar; import java.util.Date; +import java.util.HashSet; +import java.util.Set; import com.caucho.hessian.client.HessianProxyFactory; @@ -119,17 +125,47 @@ public class TestCode { // System.out.println(jj.optString("pring")); - // 根据网卡取本机配置的IP - InetAddress inet = null; - try { - inet = InetAddress.getLocalHost(); - } catch (UnknownHostException e) { - e.printStackTrace(); - } - String ipAddress = inet.getHostAddress(); +// // 根据网卡取本机配置的IP +// InetAddress inet = null; +// try { +// inet = InetAddress.getLocalHost(); +// } catch (UnknownHostException e) { +// e.printStackTrace(); +// } +// String ipAddress = inet.getHostAddress(); +// +// System.out.println(ipAddress); - System.out.println(ipAddress); + +// TestCode test = new TestCode(); +// System.out.println(test.dd("ddd")); + + +// Package pkg = Package.getPackage("osc.git.eh3.test"); +// Annotation[] annotations = pkg.getAnnotations(); +// for (Annotation annotation : annotations) { +// System.out.println(annotation); +// } + +// String[] arrs = new String[]{"111","111","2222"}; +// for (String string : Array2Set(arrs)) { +// +// System.out.println(string); +// } + +// Class clazz = StatisByHourModel.class; +// Method[] methods = clazz.getMethods(); +// for (Method method : methods) { +// System.out.println(method.getName()); +// } + Object dd = new Date(); + + System.out.println(dd instanceof Date); + + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); + System.out.println(sdf.format(dd)); + } public static Long parseDate(String s) { @@ -147,4 +183,13 @@ public class TestCode { } return time; } + + public B dd(B t){ + return t; + } + + public static Set Array2Set(T[] tArray) { + Set tSet = new HashSet(Arrays.asList(tArray)); + return tSet; + } } \ No newline at end of file diff --git a/src/main/java/osc/git/eh3/utils/CommonUtils.java b/src/main/java/osc/git/eh3/utils/CommonUtils.java index 77c62e7..4fed7c7 100644 --- a/src/main/java/osc/git/eh3/utils/CommonUtils.java +++ b/src/main/java/osc/git/eh3/utils/CommonUtils.java @@ -22,6 +22,7 @@ public class CommonUtils { * @return 转换后数据对象 */ public static T convertClass(Object bean, Class clazz) { + Map maps = new HashMap(); T dataBean = null; if (null == bean) { @@ -34,67 +35,76 @@ public class CommonUtils { Field[] beanFields = clazz.getDeclaredFields(); for (Field field : fields) { try { - String fieldName = field.getName(); - String strGet = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1, fieldName.length()); - Method methodGet = cls.getDeclaredMethod(strGet); - Object object = methodGet.invoke(bean); - maps.put(fieldName, object == null ? "" : object); + String fieldName = field.getName().toLowerCase(); + String strGet = "get" + fieldName; + + Method[] methods = cls.getMethods(); + for (Method method : methods) { + if (strGet.equalsIgnoreCase(method.getName())) { + Object object = method.invoke(bean); + maps.put(fieldName, object == null ? "" : object); + } + } } catch (Exception e) { } } for (Field field : beanFields) { field.setAccessible(true); - String fieldName = field.getName(); + String fieldName = field.getName().toLowerCase(); Class fieldType = field.getType(); - String fieldValue = (maps.get(fieldName) == null || "".equals(maps.get(fieldName))) ? null : maps.get(fieldName).toString(); + Object fieldValue = (maps.get(fieldName) == null || "".equals(maps.get(fieldName))) ? null : maps.get(fieldName); if (fieldValue != null) { if (String.class.equals(fieldType)) { - field.set(dataBean, fieldValue); + if (fieldValue instanceof Date) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + field.set(dataBean, sdf.format(fieldValue)); + } else { + field.set(dataBean, fieldValue.toString()); + } } else if (byte.class.equals(fieldType)) { - field.setByte(dataBean, Byte.parseByte(fieldValue)); + field.setByte(dataBean, Byte.parseByte(fieldValue.toString())); } else if (Byte.class.equals(fieldType)) { - field.set(dataBean, Byte.valueOf(fieldValue)); + field.set(dataBean, Byte.valueOf(fieldValue.toString())); } else if (boolean.class.equals(fieldType)) { - field.setBoolean(dataBean, Boolean.parseBoolean(fieldValue)); + field.setBoolean(dataBean, Boolean.parseBoolean(fieldValue.toString())); } else if (Boolean.class.equals(fieldType)) { - field.set(dataBean, Boolean.valueOf(fieldValue)); + field.set(dataBean, Boolean.valueOf(fieldValue.toString())); } else if (short.class.equals(fieldType)) { - field.setShort(dataBean, Short.parseShort(fieldValue)); + field.setShort(dataBean, Short.parseShort(fieldValue.toString())); } else if (Short.class.equals(fieldType)) { - field.set(dataBean, Short.valueOf(fieldValue)); + field.set(dataBean, Short.valueOf(fieldValue.toString())); } else if (int.class.equals(fieldType)) { - field.setInt(dataBean, Integer.parseInt(fieldValue)); + field.setInt(dataBean, Integer.parseInt(fieldValue.toString())); } else if (Integer.class.equals(fieldType)) { - field.set(dataBean, Integer.valueOf(fieldValue)); + field.set(dataBean, Integer.valueOf(fieldValue.toString())); } else if (long.class.equals(fieldType)) { - field.setLong(dataBean, Long.parseLong(fieldValue)); + field.setLong(dataBean, Long.parseLong(fieldValue.toString())); } else if (Long.class.equals(fieldType)) { - field.set(dataBean, Long.valueOf(fieldValue)); + field.set(dataBean, Long.valueOf(fieldValue.toString())); } else if (float.class.equals(fieldType)) { - field.setFloat(dataBean, Float.parseFloat(fieldValue)); + field.setFloat(dataBean, Float.parseFloat(fieldValue.toString())); } else if (Float.class.equals(fieldType)) { - field.set(dataBean, Float.valueOf(fieldValue)); + field.set(dataBean, Float.valueOf(fieldValue.toString())); } else if (double.class.equals(fieldType)) { - field.setDouble(dataBean, Double.parseDouble(fieldValue)); + field.setDouble(dataBean, Double.parseDouble(fieldValue.toString())); } else if (Double.class.equals(fieldType)) { - field.set(dataBean, Double.valueOf(fieldValue)); + field.set(dataBean, Double.valueOf(fieldValue.toString())); } else if (Date.class.equals(fieldType)) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); - field.set(dataBean, sdf.parse(fieldValue)); + field.set(dataBean, fieldValue); } } }