|
@@ -1,8 +1,10 @@
|
|
package org.jeecg.common.util;
|
|
package org.jeecg.common.util;
|
|
|
|
|
|
-import org.apache.commons.lang.StringEscapeUtils;
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Field;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigInteger;
|
|
import java.math.BigInteger;
|
|
@@ -16,10 +18,11 @@ import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
/**
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @Author 张代浩
|
|
* @Author 张代浩
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
|
|
+@Slf4j
|
|
public class oConvertUtils {
|
|
public class oConvertUtils {
|
|
public static boolean isEmpty(Object object) {
|
|
public static boolean isEmpty(Object object) {
|
|
if (object == null) {
|
|
if (object == null) {
|
|
@@ -33,9 +36,9 @@ public class oConvertUtils {
|
|
}
|
|
}
|
|
return (false);
|
|
return (false);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static boolean isNotEmpty(Object object) {
|
|
public static boolean isNotEmpty(Object object) {
|
|
- if (object != null && !"".equals(object) && !"null".equals(object)) {
|
|
|
|
|
|
+ if (object != null && !object.equals("") && !object.equals("null")) {
|
|
return (true);
|
|
return (true);
|
|
}
|
|
}
|
|
return (false);
|
|
return (false);
|
|
@@ -46,13 +49,28 @@ public class oConvertUtils {
|
|
return temp;
|
|
return temp;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static String StrToUTF(String strIn, String sourceCode, String targetCode) {
|
|
|
|
+ strIn = "";
|
|
|
|
+ try {
|
|
|
|
+ strIn = new String(strIn.getBytes("ISO-8859-1"), "GBK");
|
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
|
+ // TODO Auto-generated catch block
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return strIn;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
private static String code2code(String strIn, String sourceCode, String targetCode) {
|
|
private static String code2code(String strIn, String sourceCode, String targetCode) {
|
|
- if (strIn == null || "".equals(strIn.trim())) {
|
|
|
|
|
|
+ String strOut = null;
|
|
|
|
+ if (strIn == null || (strIn.trim()).equals("")) {
|
|
return strIn;
|
|
return strIn;
|
|
}
|
|
}
|
|
- String strOut = null;
|
|
|
|
try {
|
|
try {
|
|
byte[] b = strIn.getBytes(sourceCode);
|
|
byte[] b = strIn.getBytes(sourceCode);
|
|
|
|
+ for (int i = 0; i < b.length; i++) {
|
|
|
|
+ System.out.print(b[i] + " ");
|
|
|
|
+ }
|
|
strOut = new String(b, targetCode);
|
|
strOut = new String(b, targetCode);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
@@ -62,7 +80,7 @@ public class oConvertUtils {
|
|
}
|
|
}
|
|
|
|
|
|
public static int getInt(String s, int defval) {
|
|
public static int getInt(String s, int defval) {
|
|
- if (s == null || s.trim().equals("")) {
|
|
|
|
|
|
+ if (s == null || s == "") {
|
|
return (defval);
|
|
return (defval);
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
@@ -73,7 +91,7 @@ public class oConvertUtils {
|
|
}
|
|
}
|
|
|
|
|
|
public static int getInt(String s) {
|
|
public static int getInt(String s) {
|
|
- if (s == null || s.trim().equals("")) {
|
|
|
|
|
|
+ if (s == null || s == "") {
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
@@ -84,7 +102,7 @@ public class oConvertUtils {
|
|
}
|
|
}
|
|
|
|
|
|
public static int getInt(String s, Integer df) {
|
|
public static int getInt(String s, Integer df) {
|
|
- if (s == null || s.trim().equals("")) {
|
|
|
|
|
|
+ if (s == null || s == "") {
|
|
return df;
|
|
return df;
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
@@ -95,10 +113,10 @@ public class oConvertUtils {
|
|
}
|
|
}
|
|
|
|
|
|
public static Integer[] getInts(String[] s) {
|
|
public static Integer[] getInts(String[] s) {
|
|
|
|
+ Integer[] integer = new Integer[s.length];
|
|
if (s == null) {
|
|
if (s == null) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
- Integer[] integer = new Integer[s.length];
|
|
|
|
for (int i = 0; i < s.length; i++) {
|
|
for (int i = 0; i < s.length; i++) {
|
|
integer[i] = Integer.parseInt(s[i]);
|
|
integer[i] = Integer.parseInt(s[i]);
|
|
}
|
|
}
|
|
@@ -107,7 +125,7 @@ public class oConvertUtils {
|
|
}
|
|
}
|
|
|
|
|
|
public static double getDouble(String s, double defval) {
|
|
public static double getDouble(String s, double defval) {
|
|
- if (s == null || s.trim().equals("")) {
|
|
|
|
|
|
+ if (s == null || s == "") {
|
|
return (defval);
|
|
return (defval);
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
@@ -124,6 +142,14 @@ public class oConvertUtils {
|
|
return s;
|
|
return s;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /*public static Short getShort(String s) {
|
|
|
|
+ if (StringUtil.isNotEmpty(s)) {
|
|
|
|
+ return (Short.parseShort(s));
|
|
|
|
+ } else {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }*/
|
|
|
|
+
|
|
public static int getInt(Object object, int defval) {
|
|
public static int getInt(Object object, int defval) {
|
|
if (isEmpty(object)) {
|
|
if (isEmpty(object)) {
|
|
return (defval);
|
|
return (defval);
|
|
@@ -134,7 +160,7 @@ public class oConvertUtils {
|
|
return (defval);
|
|
return (defval);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static Integer getInt(Object object) {
|
|
public static Integer getInt(Object object) {
|
|
if (isEmpty(object)) {
|
|
if (isEmpty(object)) {
|
|
return null;
|
|
return null;
|
|
@@ -153,12 +179,12 @@ public class oConvertUtils {
|
|
return s.intValue();
|
|
return s.intValue();
|
|
}
|
|
}
|
|
|
|
|
|
- public static Integer[] getIntegerArray(String[] object) {
|
|
|
|
|
|
+ public static Integer[] getIntegerArry(String[] object) {
|
|
int len = object.length;
|
|
int len = object.length;
|
|
Integer[] result = new Integer[len];
|
|
Integer[] result = new Integer[len];
|
|
try {
|
|
try {
|
|
for (int i = 0; i < len; i++) {
|
|
for (int i = 0; i < len; i++) {
|
|
- result[i] = Integer.getInteger(object[i].trim());
|
|
|
|
|
|
+ result[i] = new Integer(object[i].trim());
|
|
}
|
|
}
|
|
return result;
|
|
return result;
|
|
} catch (NumberFormatException e) {
|
|
} catch (NumberFormatException e) {
|
|
@@ -175,10 +201,10 @@ public class oConvertUtils {
|
|
* @param s
|
|
* @param s
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public static String escapeJava(Object s) {
|
|
|
|
|
|
+ /*public static String escapeJava(Object s) {
|
|
return StringEscapeUtils.escapeJava(getString(s));
|
|
return StringEscapeUtils.escapeJava(getString(s));
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ }*/
|
|
|
|
+
|
|
public static String getString(Object object) {
|
|
public static String getString(Object object) {
|
|
if (isEmpty(object)) {
|
|
if (isEmpty(object)) {
|
|
return "";
|
|
return "";
|
|
@@ -209,7 +235,12 @@ public class oConvertUtils {
|
|
}
|
|
}
|
|
|
|
|
|
public static long stringToLong(String str) {
|
|
public static long stringToLong(String str) {
|
|
- return Long.valueOf(str);
|
|
|
|
|
|
+ Long test = new Long(0);
|
|
|
|
+ try {
|
|
|
|
+ test = Long.valueOf(str);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ }
|
|
|
|
+ return test.longValue();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -229,12 +260,12 @@ public class oConvertUtils {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 判断一个类是否为基本数据类型。
|
|
* 判断一个类是否为基本数据类型。
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param clazz
|
|
* @param clazz
|
|
* 要判断的类。
|
|
* 要判断的类。
|
|
* @return true 表示为基本数据类型。
|
|
* @return true 表示为基本数据类型。
|
|
*/
|
|
*/
|
|
- private static boolean isBaseDataType(Class clazz) {
|
|
|
|
|
|
+ private static boolean isBaseDataType(Class clazz) throws Exception {
|
|
return (clazz.equals(String.class) || clazz.equals(Integer.class) || clazz.equals(Byte.class) || clazz.equals(Long.class) || clazz.equals(Double.class) || clazz.equals(Float.class) || clazz.equals(Character.class) || clazz.equals(Short.class) || clazz.equals(BigDecimal.class) || clazz.equals(BigInteger.class) || clazz.equals(Boolean.class) || clazz.equals(Date.class) || clazz.isPrimitive());
|
|
return (clazz.equals(String.class) || clazz.equals(Integer.class) || clazz.equals(Byte.class) || clazz.equals(Long.class) || clazz.equals(Double.class) || clazz.equals(Float.class) || clazz.equals(Character.class) || clazz.equals(Short.class) || clazz.equals(BigDecimal.class) || clazz.equals(BigInteger.class) || clazz.equals(Boolean.class) || clazz.equals(Date.class) || clazz.isPrimitive());
|
|
}
|
|
}
|
|
|
|
|
|
@@ -262,25 +293,22 @@ public class oConvertUtils {
|
|
* @throws SocketException
|
|
* @throws SocketException
|
|
*/
|
|
*/
|
|
public static String getRealIp() throws SocketException {
|
|
public static String getRealIp() throws SocketException {
|
|
- // 本地IP,如果没有配置外网IP则返回它
|
|
|
|
- String localip = null;
|
|
|
|
- // 外网IP
|
|
|
|
- String netip = null;
|
|
|
|
|
|
+ String localip = null;// 本地IP,如果没有配置外网IP则返回它
|
|
|
|
+ String netip = null;// 外网IP
|
|
|
|
|
|
Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces();
|
|
Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces();
|
|
InetAddress ip = null;
|
|
InetAddress ip = null;
|
|
- // 是否找到外网IP
|
|
|
|
- boolean finded = false;
|
|
|
|
|
|
+ boolean finded = false;// 是否找到外网IP
|
|
while (netInterfaces.hasMoreElements() && !finded) {
|
|
while (netInterfaces.hasMoreElements() && !finded) {
|
|
NetworkInterface ni = netInterfaces.nextElement();
|
|
NetworkInterface ni = netInterfaces.nextElement();
|
|
Enumeration<InetAddress> address = ni.getInetAddresses();
|
|
Enumeration<InetAddress> address = ni.getInetAddresses();
|
|
while (address.hasMoreElements()) {
|
|
while (address.hasMoreElements()) {
|
|
ip = address.nextElement();
|
|
ip = address.nextElement();
|
|
- if (!ip.isSiteLocalAddress() && !ip.isLoopbackAddress() && ip.getHostAddress().indexOf(':') == -1) {
|
|
|
|
|
|
+ if (!ip.isSiteLocalAddress() && !ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == -1) {// 外网IP
|
|
netip = ip.getHostAddress();
|
|
netip = ip.getHostAddress();
|
|
finded = true;
|
|
finded = true;
|
|
break;
|
|
break;
|
|
- } else if (ip.isSiteLocalAddress() && !ip.isLoopbackAddress() && ip.getHostAddress().indexOf(':') == -1) {
|
|
|
|
|
|
+ } else if (ip.isSiteLocalAddress() && !ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == -1) {// 内网IP
|
|
localip = ip.getHostAddress();
|
|
localip = ip.getHostAddress();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -295,7 +323,7 @@ public class oConvertUtils {
|
|
|
|
|
|
/**
|
|
/**
|
|
* java去除字符串中的空格、回车、换行符、制表符
|
|
* java去除字符串中的空格、回车、换行符、制表符
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param str
|
|
* @param str
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@@ -312,7 +340,7 @@ public class oConvertUtils {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 判断元素是否在数组内
|
|
* 判断元素是否在数组内
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param substring
|
|
* @param substring
|
|
* @param source
|
|
* @param source
|
|
* @return
|
|
* @return
|
|
@@ -331,13 +359,20 @@ public class oConvertUtils {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * 获取Map对象
|
|
|
|
+ */
|
|
|
|
+ public static Map<Object, Object> getHashMap() {
|
|
|
|
+ return new HashMap<Object, Object>();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
* SET转换MAP
|
|
* SET转换MAP
|
|
- *
|
|
|
|
- * @param setobj
|
|
|
|
|
|
+ *
|
|
|
|
+ * @param str
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public static Map<Object, Object> setToMap(Set<Object> setobj) {
|
|
|
|
- Map<Object, Object> map = new HashMap<>();
|
|
|
|
|
|
+ public static Map<Object, Object> SetToMap(Set<Object> setobj) {
|
|
|
|
+ Map<Object, Object> map = getHashMap();
|
|
for (Iterator iterator = setobj.iterator(); iterator.hasNext();) {
|
|
for (Iterator iterator = setobj.iterator(); iterator.hasNext();) {
|
|
Map.Entry<Object, Object> entry = (Map.Entry<Object, Object>) iterator.next();
|
|
Map.Entry<Object, Object> entry = (Map.Entry<Object, Object>) iterator.next();
|
|
map.put(entry.getKey().toString(), entry.getValue() == null ? "" : entry.getValue().toString().trim());
|
|
map.put(entry.getKey().toString(), entry.getValue() == null ? "" : entry.getValue().toString().trim());
|
|
@@ -346,7 +381,7 @@ public class oConvertUtils {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- public static boolean isInnerIp(String ipAddress) {
|
|
|
|
|
|
+ public static boolean isInnerIP(String ipAddress) {
|
|
boolean isInnerIp = false;
|
|
boolean isInnerIp = false;
|
|
long ipNum = getIpNum(ipAddress);
|
|
long ipNum = getIpNum(ipAddress);
|
|
/**
|
|
/**
|
|
@@ -358,7 +393,7 @@ public class oConvertUtils {
|
|
long bEnd = getIpNum("172.31.255.255");
|
|
long bEnd = getIpNum("172.31.255.255");
|
|
long cBegin = getIpNum("192.168.0.0");
|
|
long cBegin = getIpNum("192.168.0.0");
|
|
long cEnd = getIpNum("192.168.255.255");
|
|
long cEnd = getIpNum("192.168.255.255");
|
|
- isInnerIp = isInner(ipNum, aBegin, aEnd) || isInner(ipNum, bBegin, bEnd) || isInner(ipNum, cBegin, cEnd) || "127.0.0.1".equals(ipAddress);
|
|
|
|
|
|
+ isInnerIp = isInner(ipNum, aBegin, aEnd) || isInner(ipNum, bBegin, bEnd) || isInner(ipNum, cBegin, cEnd) || ipAddress.equals("127.0.0.1");
|
|
return isInnerIp;
|
|
return isInnerIp;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -368,18 +403,20 @@ public class oConvertUtils {
|
|
long b = Integer.parseInt(ip[1]);
|
|
long b = Integer.parseInt(ip[1]);
|
|
long c = Integer.parseInt(ip[2]);
|
|
long c = Integer.parseInt(ip[2]);
|
|
long d = Integer.parseInt(ip[3]);
|
|
long d = Integer.parseInt(ip[3]);
|
|
- return a * 256 * 256 * 256 + b * 256 * 256 + c * 256 + d;
|
|
|
|
|
|
+
|
|
|
|
+ long ipNum = a * 256 * 256 * 256 + b * 256 * 256 + c * 256 + d;
|
|
|
|
+ return ipNum;
|
|
}
|
|
}
|
|
|
|
|
|
private static boolean isInner(long userIp, long begin, long end) {
|
|
private static boolean isInner(long userIp, long begin, long end) {
|
|
return (userIp >= begin) && (userIp <= end);
|
|
return (userIp >= begin) && (userIp <= end);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 将下划线大写方式命名的字符串转换为驼峰式。
|
|
* 将下划线大写方式命名的字符串转换为驼峰式。
|
|
* 如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。</br>
|
|
* 如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。</br>
|
|
* 例如:hello_world->helloWorld
|
|
* 例如:hello_world->helloWorld
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param name
|
|
* @param name
|
|
* 转换前的下划线大写方式命名的字符串
|
|
* 转换前的下划线大写方式命名的字符串
|
|
* @return 转换后的驼峰式命名的字符串
|
|
* @return 转换后的驼峰式命名的字符串
|
|
@@ -398,7 +435,7 @@ public class oConvertUtils {
|
|
//update-end--Author:zhoujf Date:20180503 for:TASK #2500 【代码生成器】代码生成器开发一通用模板生成功能
|
|
//update-end--Author:zhoujf Date:20180503 for:TASK #2500 【代码生成器】代码生成器开发一通用模板生成功能
|
|
}
|
|
}
|
|
// 用下划线将原始字符串分割
|
|
// 用下划线将原始字符串分割
|
|
- String[] camels = name.split("_");
|
|
|
|
|
|
+ String camels[] = name.split("_");
|
|
for (String camel : camels) {
|
|
for (String camel : camels) {
|
|
// 跳过原始字符串中开头、结尾的下换线或双重下划线
|
|
// 跳过原始字符串中开头、结尾的下换线或双重下划线
|
|
if (camel.isEmpty()) {
|
|
if (camel.isEmpty()) {
|
|
@@ -416,18 +453,18 @@ public class oConvertUtils {
|
|
}
|
|
}
|
|
return result.toString();
|
|
return result.toString();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 将下划线大写方式命名的字符串转换为驼峰式。
|
|
* 将下划线大写方式命名的字符串转换为驼峰式。
|
|
* 如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。</br>
|
|
* 如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。</br>
|
|
* 例如:hello_world,test_id->helloWorld,testId
|
|
* 例如:hello_world,test_id->helloWorld,testId
|
|
- *
|
|
|
|
- * @param names
|
|
|
|
|
|
+ *
|
|
|
|
+ * @param name
|
|
* 转换前的下划线大写方式命名的字符串
|
|
* 转换前的下划线大写方式命名的字符串
|
|
* @return 转换后的驼峰式命名的字符串
|
|
* @return 转换后的驼峰式命名的字符串
|
|
*/
|
|
*/
|
|
public static String camelNames(String names) {
|
|
public static String camelNames(String names) {
|
|
- if (names == null || "".equals(names)) {
|
|
|
|
|
|
+ if(names==null||names.equals("")){
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
StringBuffer sf = new StringBuffer();
|
|
StringBuffer sf = new StringBuffer();
|
|
@@ -439,13 +476,13 @@ public class oConvertUtils {
|
|
String result = sf.toString();
|
|
String result = sf.toString();
|
|
return result.substring(0, result.length() - 1);
|
|
return result.substring(0, result.length() - 1);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
//update-begin--Author:zhoujf Date:20180503 for:TASK #2500 【代码生成器】代码生成器开发一通用模板生成功能
|
|
//update-begin--Author:zhoujf Date:20180503 for:TASK #2500 【代码生成器】代码生成器开发一通用模板生成功能
|
|
/**
|
|
/**
|
|
* 将下划线大写方式命名的字符串转换为驼峰式。(首字母写)
|
|
* 将下划线大写方式命名的字符串转换为驼峰式。(首字母写)
|
|
* 如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。</br>
|
|
* 如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。</br>
|
|
* 例如:hello_world->HelloWorld
|
|
* 例如:hello_world->HelloWorld
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param name
|
|
* @param name
|
|
* 转换前的下划线大写方式命名的字符串
|
|
* 转换前的下划线大写方式命名的字符串
|
|
* @return 转换后的驼峰式命名的字符串
|
|
* @return 转换后的驼峰式命名的字符串
|
|
@@ -461,7 +498,7 @@ public class oConvertUtils {
|
|
return name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase();
|
|
return name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase();
|
|
}
|
|
}
|
|
// 用下划线将原始字符串分割
|
|
// 用下划线将原始字符串分割
|
|
- String[] camels = name.split("_");
|
|
|
|
|
|
+ String camels[] = name.split("_");
|
|
for (String camel : camels) {
|
|
for (String camel : camels) {
|
|
// 跳过原始字符串中开头、结尾的下换线或双重下划线
|
|
// 跳过原始字符串中开头、结尾的下换线或双重下划线
|
|
if (camel.isEmpty()) {
|
|
if (camel.isEmpty()) {
|
|
@@ -474,27 +511,26 @@ public class oConvertUtils {
|
|
return result.toString();
|
|
return result.toString();
|
|
}
|
|
}
|
|
//update-end--Author:zhoujf Date:20180503 for:TASK #2500 【代码生成器】代码生成器开发一通用模板生成功能
|
|
//update-end--Author:zhoujf Date:20180503 for:TASK #2500 【代码生成器】代码生成器开发一通用模板生成功能
|
|
-
|
|
|
|
- /**
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
* 将驼峰命名转化成下划线
|
|
* 将驼峰命名转化成下划线
|
|
* @param para
|
|
* @param para
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public static String camelToUnderline(String para){
|
|
public static String camelToUnderline(String para){
|
|
if(para.length()<3){
|
|
if(para.length()<3){
|
|
- return para.toLowerCase();
|
|
|
|
|
|
+ return para.toLowerCase();
|
|
}
|
|
}
|
|
StringBuilder sb=new StringBuilder(para);
|
|
StringBuilder sb=new StringBuilder(para);
|
|
- //定位
|
|
|
|
- int temp = 0;
|
|
|
|
- //从第三个字符开始 避免命名不规范
|
|
|
|
|
|
+ int temp=0;//定位
|
|
|
|
+ //从第三个字符开始 避免命名不规范
|
|
for(int i=2;i<para.length();i++){
|
|
for(int i=2;i<para.length();i++){
|
|
if(Character.isUpperCase(para.charAt(i))){
|
|
if(Character.isUpperCase(para.charAt(i))){
|
|
sb.insert(i+temp, "_");
|
|
sb.insert(i+temp, "_");
|
|
temp+=1;
|
|
temp+=1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return sb.toString().toLowerCase();
|
|
|
|
|
|
+ return sb.toString().toLowerCase();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -510,10 +546,10 @@ public class oConvertUtils {
|
|
}
|
|
}
|
|
return sb.toString();
|
|
return sb.toString();
|
|
}
|
|
}
|
|
-
|
|
|
|
- /**
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
* 获取类的所有属性,包括父类
|
|
* 获取类的所有属性,包括父类
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param object
|
|
* @param object
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@@ -528,9 +564,8 @@ public class oConvertUtils {
|
|
fieldList.toArray(fields);
|
|
fieldList.toArray(fields);
|
|
return fields;
|
|
return fields;
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
* 将map的key全部转成小写
|
|
* 将map的key全部转成小写
|
|
* @param list
|
|
* @param list
|
|
* @return
|
|
* @return
|
|
@@ -539,13 +574,76 @@ public class oConvertUtils {
|
|
List<Map<String, Object>> select = new ArrayList<>();
|
|
List<Map<String, Object>> select = new ArrayList<>();
|
|
for (Map<String, Object> row : list) {
|
|
for (Map<String, Object> row : list) {
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
- Set<String> keySet = row.keySet();
|
|
|
|
- for (String key : keySet) {
|
|
|
|
- String newKey = key.toLowerCase();
|
|
|
|
- resultMap.put(newKey, row.get(key));
|
|
|
|
|
|
+ Set<String> keySet = row.keySet();
|
|
|
|
+ for (String key : keySet) {
|
|
|
|
+ String newKey = key.toLowerCase();
|
|
|
|
+ resultMap.put(newKey, row.get(key));
|
|
}
|
|
}
|
|
select.add(resultMap);
|
|
select.add(resultMap);
|
|
}
|
|
}
|
|
return select;
|
|
return select;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 将entityList转换成modelList
|
|
|
|
+ * @param fromList
|
|
|
|
+ * @param tClass
|
|
|
|
+ * @param <F>
|
|
|
|
+ * @param <T>
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static<F,T> List<T> entityListToModelList(List<F> fromList, Class<T> tClass){
|
|
|
|
+ if(fromList.isEmpty() || fromList == null){
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ List<T> tList = new ArrayList<>();
|
|
|
|
+ for(F f : fromList){
|
|
|
|
+ T t = entityToModel(f, tClass);
|
|
|
|
+ tList.add(t);
|
|
|
|
+ }
|
|
|
|
+ return tList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static<F,T> T entityToModel(F entity, Class<T> modelClass) {
|
|
|
|
+ log.debug("entityToModel : Entity属性的值赋值到Model");
|
|
|
|
+ Object model = null;
|
|
|
|
+ if (entity == null || modelClass ==null) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ model = modelClass.newInstance();
|
|
|
|
+ } catch (InstantiationException e) {
|
|
|
|
+ log.error("entityToModel : 实例化异常", e);
|
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
|
+ log.error("entityToModel : 安全权限异常", e);
|
|
|
|
+ }
|
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
|
+ return (T)model;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 判断 list 是否为空
|
|
|
|
+ *
|
|
|
|
+ * @param list
|
|
|
|
+ * @return true or false
|
|
|
|
+ * list == null : true
|
|
|
|
+ * list.size() == 0 : true
|
|
|
|
+ */
|
|
|
|
+ public static boolean listIsEmpty(Collection list) {
|
|
|
|
+ return (list == null || list.size() == 0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 判断 list 是否不为空
|
|
|
|
+ *
|
|
|
|
+ * @param list
|
|
|
|
+ * @return true or false
|
|
|
|
+ * list == null : false
|
|
|
|
+ * list.size() == 0 : false
|
|
|
|
+ */
|
|
|
|
+ public static boolean listIsNotEmpty(Collection list) {
|
|
|
|
+ return !listIsEmpty(list);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|