diff --git a/.gitignore b/.gitignore index 5618f13338f682039379597620801e24796f56de..e0710138b4e5eeb3a55b45122882f952351a0a24 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ /src/main/webapp/WEB-INF/classes/* /src/main/webapp/userfiles/* /target/ +.externalToolBuilders/ diff --git a/pom.xml b/pom.xml index 3d629b9e66ab64ab4adbc6078242f77fccc2dee6..7ea827645915c82a317aebd5e6afe382496306de 100644 --- a/pom.xml +++ b/pom.xml @@ -66,6 +66,54 @@ http://maven.aliyun.com/nexus/content/groups/public + + java-repos + Java Repository + http://download.java.net/maven/2/ + + + + springsource-repos + SpringSource Repository + http://repo.spring.io/release/ + + + + central-repos + Central Repository + http://repo.maven.apache.org/maven2 + + + + central-repos2 + Central Repository 2 + http://repo1.maven.org/maven2/ + + + + activiti-repos + Activiti Repository + https://maven.alfresco.com/nexus/content/groups/public + + + + activiti-repos2 + Activiti Repository 2 + https://app.camunda.com/nexus/content/groups/public + + + + thinkgem-repos + ThinkGem Repository + http://git.oschina.net/thinkgem/repos/raw/master + + + + thinkgem-repos2 + ThinkGem Repository 2 + https://raw.github.com/thinkgem/repository/master + + @@ -782,6 +830,10 @@ ${project.build.directory}/${project.artifactId} ${project.artifactId} + + + true + api @@ -919,14 +971,14 @@ - - + - + + - + - --> + password="${jdbc.password}" schema="${jdbc.username}" > diff --git a/src/main/java/com/thinkgem/jeesite/common/persistence/DataEntity.java b/src/main/java/com/thinkgem/jeesite/common/persistence/DataEntity.java index 81e0c04fc56a03f6e4d6a43decca42bd34212599..9381dae6936a942143696815465b9ef408f3267d 100644 --- a/src/main/java/com/thinkgem/jeesite/common/persistence/DataEntity.java +++ b/src/main/java/com/thinkgem/jeesite/common/persistence/DataEntity.java @@ -10,6 +10,8 @@ import org.hibernate.validator.constraints.Length; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.thinkgem.jeesite.common.config.Global; +import com.thinkgem.jeesite.common.utils.CharUtil; import com.thinkgem.jeesite.common.utils.IdGen; import com.thinkgem.jeesite.modules.sys.entity.User; import com.thinkgem.jeesite.modules.sys.utils.UserUtils; @@ -55,6 +57,11 @@ public abstract class DataEntity extends BaseEntity { } this.updateDate = new Date(); this.createDate = this.updateDate; + + //ORACLE US7ASCII 字符集时的特殊处理 add by zkool 2017-2-8 + if(Global.getConfig("jdbc.charset").equalsIgnoreCase("US7ASCII")){ + CharUtil.converFieldValue(this, 1); + } } /** @@ -67,6 +74,11 @@ public abstract class DataEntity extends BaseEntity { this.updateBy = user; } this.updateDate = new Date(); + + //ORACLE US7ASCII 字符集时的特殊处理 add by zkool 2017-2-8 + if(Global.getConfig("jdbc.charset").equalsIgnoreCase("US7ASCII")){ + CharUtil.converFieldValue(this, 1); + } } @Length(min=0, max=255) diff --git a/src/main/java/com/thinkgem/jeesite/common/persistence/interceptor/PaginationInterceptor.java b/src/main/java/com/thinkgem/jeesite/common/persistence/interceptor/PaginationInterceptor.java index 4c29edf9a09cc113d84ce2fafb9036c5f286f51b..a0d0d8d5dcb4e0b19eb1efed2f0b4bc1d3826dbd 100644 --- a/src/main/java/com/thinkgem/jeesite/common/persistence/interceptor/PaginationInterceptor.java +++ b/src/main/java/com/thinkgem/jeesite/common/persistence/interceptor/PaginationInterceptor.java @@ -15,10 +15,14 @@ import org.apache.ibatis.reflection.MetaObject; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; +import com.thinkgem.jeesite.common.config.Global; +import com.thinkgem.jeesite.common.persistence.DataEntity; import com.thinkgem.jeesite.common.persistence.Page; +import com.thinkgem.jeesite.common.utils.CharUtil; import com.thinkgem.jeesite.common.utils.Reflections; import com.thinkgem.jeesite.common.utils.StringUtils; +import java.util.List; import java.util.Properties; /** @@ -44,10 +48,20 @@ public class PaginationInterceptor extends BaseInterceptor { BoundSql boundSql = mappedStatement.getBoundSql(parameter); Object parameterObject = boundSql.getParameterObject(); + boolean flag = false; + //获取分页参数对象 Page page = null; if (parameterObject != null) { page = convertParameter(parameterObject, page); + + //ORACLE US7ASCII 字符集时的特殊处理 add by zkool 2017-2-8 + if(Global.getConfig("jdbc.charset").equalsIgnoreCase("US7ASCII")){ + if(parameterObject instanceof DataEntity){ + CharUtil.converFieldValue(parameterObject, 1); + flag = true; + } + } } //如果设置了分页对象,则进行分页 @@ -79,7 +93,29 @@ public class PaginationInterceptor extends BaseInterceptor { invocation.getArgs()[0] = newMs; } // } - return invocation.proceed(); + + Object result = invocation.proceed(); //执行请求方法,并将所得结果保存到result中 + + //ORACLE US7ASCII 字符集时的特殊处理 add by zkool 2017-2-8 + if(Global.getConfig("jdbc.charset").equalsIgnoreCase("US7ASCII")){ + if (result instanceof List) { + List resultList = (List) result; + for (int i = 0; i < resultList.size(); i++) { + if (resultList.get(i) instanceof DataEntity) { + DataEntity resultObj = (DataEntity) resultList.get(i); + CharUtil.converFieldValue(resultObj, 2); + } + } + }else if(result instanceof DataEntity){ + CharUtil.converFieldValue(result, 2); + } + + if(flag){ + CharUtil.converFieldValue(parameterObject, 2); + } + } + + return result; } diff --git a/src/main/java/com/thinkgem/jeesite/common/utils/CharUtil.java b/src/main/java/com/thinkgem/jeesite/common/utils/CharUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..4a1f3a973fa6775ec5fdcffb618b27e759235465 --- /dev/null +++ b/src/main/java/com/thinkgem/jeesite/common/utils/CharUtil.java @@ -0,0 +1,472 @@ +package com.thinkgem.jeesite.common.utils; + +import java.io.UnsupportedEncodingException; +import java.lang.Character.UnicodeBlock; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.thinkgem.jeesite.common.persistence.DataEntity; + +/** + * Java 完美判断中文字符 + * Java判断一个字符串是否有中文一般情况是利用Unicode编码(CJK统一汉字的编码区间:0x4e00–0x9fbb)的正则来做判断,但是其实这个区间来判断中文不是非常精确,因为有些中文的标点符号比如:,。等等是不能识别的 + * @description: + * @author kool.zhao + * @createDate 2017年2月8日;上午11:03:24 + */ +public class CharUtil { + + public static void main(String[] args) { +// String[] strArr = new String[] { "www.micmiu.com", "!@#$%^&*()_+{}[]|\"'?/:;<>,.", "!¥……()——:;“”‘’《》,。?、", "不要啊", "やめて", "韩佳人", "???" }; +// for (String str : strArr) { +// System.out.println("===========> 测试字符串:" + str); +// System.out.println("正则判断结果:" + isChineseByREG(str) + " -- " + isChineseByName(str)); +// System.out.println("Unicode判断结果 :" + isChinese(str)); +// System.out.println("详细判断列表:"); +// char[] ch = str.toCharArray(); +// for (int i = 0; i < ch.length; i++) { +// char c = ch[i]; +// System.out.println(c + " --> " + (isChinese(c) ? "是" : "否")); +// } +// } + + System.out.println(isCharOrNumber("啊")); + System.out.println(isCharOrNumber("ɽ¶«Ê¡×ܹ«Ë¾")); + System.out.println(isChinese("的")); + System.out.println(isChinese("ɽ¶«Ê¡×ܹ«Ë¾")); + } + + public static boolean isCharOrNumber(String strName) { + if (strName == null) { + return false; + } + // 编译正则表达式 + Pattern pattern = Pattern.compile("[0-9a-zA-Z]*"); + Matcher matcher = pattern.matcher(strName); + return matcher.matches(); + } + + // 根据Unicode编码完美的判断中文汉字和符号 + private static boolean isChinese(char c) { + Character.UnicodeBlock ub = Character.UnicodeBlock.of(c); + if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS + || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B + || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS + || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION) { + return true; + } + return false; + } + + // 完整的判断中文汉字和符号 + public static boolean isChinese(String strName) { + char[] ch = strName.toCharArray(); + for (int i = 0; i < ch.length; i++) { + char c = ch[i]; + if (isChinese(c)) { + return true; + } + } + return false; + } + + // 只能判断部分CJK字符(CJK统一汉字) + public static boolean isChineseByREG(String str) { + if (str == null) { + return false; + } + Pattern pattern = Pattern.compile("[\\u4E00-\\u9FBF]+"); + return pattern.matcher(str.trim()).find(); + } + + // 只能判断部分CJK字符(CJK统一汉字) + public static boolean isChineseByName(String str) { + if (str == null) { + return false; + } + // 大小写不同:\\p 表示包含,\\P 表示不包含 + // \\p{Cn} 的意思为 Unicode 中未被定义字符的编码,\\P{Cn} 就表示 Unicode中已经被定义字符的编码 + String reg = "\\p{InCJK Unified Ideographs}&&\\P{Cn}"; + Pattern pattern = Pattern.compile(reg); + return pattern.matcher(str.trim()).find(); + } + + /** + * + * 字符串转码:转成符合oracle us7ascii 的编码 + * @param input + * @return + * @throws UnsupportedEncodingException + */ + public static String str2ISO88591(String str){ + if(str == null){ + return ""; + } + + try { + return new String(str.getBytes("GBK"), "iso-8859-1"); + } catch (UnsupportedEncodingException e) { + return null; + } + + } + + /** + * 字符串转码:转换成与查询条件一直的 + * @param search + * @return + * @throws UnsupportedEncodingException + */ + public static String ISO885912str(String str){ + if(str == null){ + return ""; + } + + try { + return new String(str.getBytes("iso-8859-1"), "GBK"); + } catch (UnsupportedEncodingException e) { + return null; + } + } + + public static boolean isNeedConvert(char para) { + return ((para & (0x00FF)) != para); + } + + /** + * + * @param str + * @return String + */ + public static String GBK2Unicode(String str) { + if(str == null){ + return ""; + } + StringBuffer result = new StringBuffer(); + for (int i = 0; i < str.length(); i++) { + char chr1 = (char) str.charAt(i); + + if (!isNeedConvert(chr1)) { + result.append(chr1); + continue; + } + + result.append("\\u" + Integer.toHexString((int) chr1)); + } + + return result.toString(); + } + + /** + * + * @param dataStr + * @return String + */ + public static String Unicode2GBK(String dataStr) { + if(dataStr == null){ + return ""; + } + int index = 0; + StringBuffer buffer = new StringBuffer(); + + int li_len = dataStr.length(); + while (index < li_len) { + if (index >= li_len - 1 + || !"\\u".equals(dataStr.substring(index, index + 2))) { + buffer.append(dataStr.charAt(index)); + + index++; + continue; + } + + String charStr = ""; + charStr = dataStr.substring(index + 2, index + 6); + + char letter = (char) Integer.parseInt(charStr, 16); + + buffer.append(letter); + index += 6; + } + + return buffer.toString(); + } + + /** + * utf-8 转unicode + * + * @param inStr + * @return String + */ + public static String utf8ToUnicode(String inStr) { + char[] myBuffer = inStr.toCharArray(); + + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < inStr.length(); i++) { + UnicodeBlock ub = UnicodeBlock.of(myBuffer[i]); + if (ub == UnicodeBlock.BASIC_LATIN) { + sb.append(myBuffer[i]); + } else if (ub == UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) { + int j = (int) myBuffer[i] - 65248; + sb.append((char) j); + } else { + short s = (short) myBuffer[i]; + String hexS = Integer.toHexString(s); + String unicode = "\\u" + hexS; + sb.append(unicode.toLowerCase()); + } + } + return sb.toString(); + } + + /** + * + * @param theString + * @return String + */ + public static String unicodeToUtf8(String theString) { + char aChar; + int len = theString.length(); + StringBuffer outBuffer = new StringBuffer(len); + for (int x = 0; x < len;) { + aChar = theString.charAt(x++); + if (aChar == '\\') { + aChar = theString.charAt(x++); + if (aChar == 'u') { + // Read the xxxx + int value = 0; + for (int i = 0; i < 4; i++) { + aChar = theString.charAt(x++); + switch (aChar) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + value = (value << 4) + aChar - '0'; + break; + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + value = (value << 4) + 10 + aChar - 'a'; + break; + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + value = (value << 4) + 10 + aChar - 'A'; + break; + default: + throw new IllegalArgumentException( + "Malformed \\uxxxx encoding."); + } + } + outBuffer.append((char) value); + } else { + if (aChar == 't') + aChar = '\t'; + else if (aChar == 'r') + aChar = '\r'; + else if (aChar == 'n') + aChar = '\n'; + else if (aChar == 'f') + aChar = '\f'; + outBuffer.append(aChar); + } + } else + outBuffer.append(aChar); + } + return outBuffer.toString(); + } + + public static String gbk2utf8(String gbk) { + String l_temp = GBK2Unicode(gbk); + l_temp = unicodeToUtf8(l_temp); + + return l_temp; + } + + public static String utf82gbk(String utf) { + String l_temp = utf8ToUnicode(utf); + l_temp = Unicode2GBK(l_temp); + + return l_temp; + } + + /** + * + * @description: 转换对象的属性值为Unicode oracle us7ascii 字符集下用 + * @param model + * @param flag 1 string to Unicode;str2ISO88591 0 or 2 Unicode to string;ISO885912str + * @author kool.zhao + * @createDate 2017年2月8日;下午12:16:58 + */ + public static void converFieldValue(Object model, int flag){ + Field[] field = model.getClass().getDeclaredFields(); // 获取实体类的所有属性,返回Field数组 + try { + List list = new ArrayList(); + for (int i = 0; i < field.length; i++) { + list.add(field[i]); + } + + String superName = model.getClass().getSuperclass().getSimpleName(); + if("TreeEntity".equals(superName)){ + list.add(model.getClass().getSuperclass().getDeclaredField("name")); + list.add(model.getClass().getSuperclass().getSuperclass().getDeclaredField("remarks")); + list.add(model.getClass().getSuperclass().getSuperclass().getDeclaredField("createBy")); + list.add(model.getClass().getSuperclass().getSuperclass().getDeclaredField("updateBy")); + }else{ + list.add(model.getClass().getSuperclass().getDeclaredField("remarks")); + list.add(model.getClass().getSuperclass().getDeclaredField("createBy")); + list.add(model.getClass().getSuperclass().getDeclaredField("updateBy")); + } + + for (Field f:list) { // 遍历所有属性 + String name = f.getName(); // 获取属性的名字 + name = name.substring(0, 1).toUpperCase() + name.substring(1); // 将属性的首字符大写,方便构造get,set方法 + String type = f.getGenericType().toString(); // 获取属性的类型 + if (!Modifier.isStatic(f.getModifiers()) && type.equals("class java.lang.String")) { // 如果type是类类型,则前面包含"class ",后面跟类名 + Method m = model.getClass().getMethod("get" + name); + String value = (String) m.invoke(model); // 调用getter方法获取属性值 + if (value != null) { + m = model.getClass().getMethod("set"+name,String.class); + if(flag == 1 && isChinese(value)){ +// m.invoke(model, GBK2Unicode(value)); + m.invoke(model, str2ISO88591(value)); + } + if(flag == 2 && !isCharOrNumber(value) && !isChinese(value)){ + /* if(value.contains("\\")){ + m.invoke(model, Unicode2GBK(value)); + }*/ + m.invoke(model, ISO885912str(value)); + } + } + } + + if (flag == 2 && type.contains(".entity.")) {//说明是实体类 + Method m = model.getClass().getMethod("get" + name); + Object result = m.invoke(model); + if(result != null){ + if(result instanceof DataEntity){ + converFieldValue(result, 2); + } + } + } + // 如果有需要,可以仿照上面继续进行扩充,再增加对其它类型的判断 type.equals("class java.lang.Integer") type.equals("class java.lang.Boolean") type.equals("class java.util.Date") + } + } catch (NoSuchMethodException e) { +// e.printStackTrace(); + } catch (NoSuchFieldException e) { +// e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + + public static void converFieldValue(Object model){ + Field[] field = model.getClass().getDeclaredFields(); // 获取实体类的所有属性,返回Field数组 + try { + List list = new ArrayList(); + for (int i = 0; i < field.length; i++) { + list.add(field[i]); + } + + String superName = model.getClass().getSuperclass().getSimpleName(); + if("TreeEntity".equals(superName)){ + list.add(model.getClass().getSuperclass().getDeclaredField("name")); + list.add(model.getClass().getSuperclass().getSuperclass().getDeclaredField("remarks")); + }else{ + list.add(model.getClass().getSuperclass().getDeclaredField("remarks")); + } + + for (Field f:list) { // 遍历所有属性 + String name = f.getName(); // 获取属性的名字 + name = name.substring(0, 1).toUpperCase() + name.substring(1); // 将属性的首字符大写,方便构造get,set方法 + String type = f.getGenericType().toString(); // 获取属性的类型 + if (!Modifier.isStatic(f.getModifiers()) && type.equals("class java.lang.String")) { // 如果type是类类型,则前面包含"class ",后面跟类名 + Method m = model.getClass().getMethod("get" + name); + String value = (String) m.invoke(model); // 调用getter方法获取属性值 + if (value != null) { + m = model.getClass().getMethod("set"+name,String.class); + if(!isCharOrNumber(value) && !isChinese(value)){ + m.invoke(model, ISO885912str(value)); + } + } + } + + // 如果有需要,可以仿照上面继续进行扩充,再增加对其它类型的判断 type.equals("class java.lang.Integer") type.equals("class java.lang.Boolean") type.equals("class java.util.Date") + } + } catch (NoSuchMethodException e) { +// e.printStackTrace(); + } catch (NoSuchFieldException e) { +// e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + + public static String getEncoding(String str) { + String encode = "GB2312"; + try { + if (str.equals(new String(str.getBytes(encode), encode))) { + String s = encode; + return s; + } + } catch (Exception exception) { + } + encode = "ISO-8859-1"; + try { + if (str.equals(new String(str.getBytes(encode), encode))) { + String s1 = encode; + return s1; + } + } catch (Exception exception1) { + } + encode = "UTF-8"; + try { + if (str.equals(new String(str.getBytes(encode), encode))) { + String s2 = encode; + return s2; + } + } catch (Exception exception2) { + } + encode = "GBK"; + try { + if (str.equals(new String(str.getBytes(encode), encode))) { + String s3 = encode; + return s3; + } + } catch (Exception exception3) { + } + return ""; + } + +} diff --git a/src/main/resources/templates/modules/gen/treetable/mapper.xml b/src/main/resources/templates/modules/gen/treetable/mapper.xml index 348c2e4482369be551b2644e9fa13887d309e508..2c78d7a6eb277d04eca5def006ee2aebe97493a2 100644 --- a/src/main/resources/templates/modules/gen/treetable/mapper.xml +++ b/src/main/resources/templates/modules/gen/treetable/mapper.xml @@ -206,7 +206,10 @@ ${updateField?substring(0, updateField?last_index_of(","))} <#else> - WHERE id = ${"#"}{id} OR parent_ids LIKE '%,'||${"#"}{id}||',%' + WHERE id = ${"#"}{id} OR parent_ids LIKE + '%,'||${"#"}{id}||',%' + '%,'+${"#"}{id}+',%' + CONCAT('%,', ${"#"}{id}, ',%') diff --git a/src/main/webapp/WEB-INF/views/layouts/blank.jsp b/src/main/webapp/WEB-INF/views/layouts/blank.jsp index 173285f92b20d7ea8e236fb8ee421e8872399d93..43969068f35125ff4a60fffee3f179f98a57a782 100644 --- a/src/main/webapp/WEB-INF/views/layouts/blank.jsp +++ b/src/main/webapp/WEB-INF/views/layouts/blank.jsp @@ -6,7 +6,7 @@ <sitemesh:title/> <%@include file="/WEB-INF/views/include/head.jsp" %> - + diff --git a/src/main/webapp/WEB-INF/views/layouts/default.jsp b/src/main/webapp/WEB-INF/views/layouts/default.jsp index 10d141a8329af1f7c562e085ee2b5e93b393bc1b..94429831f9c10f0117cd5ee9ea94243ce2e43e48 100644 --- a/src/main/webapp/WEB-INF/views/layouts/default.jsp +++ b/src/main/webapp/WEB-INF/views/layouts/default.jsp @@ -6,7 +6,7 @@ <sitemesh:title/> - Powered By JeeSite <%@include file="/WEB-INF/views/include/head.jsp" %> - + diff --git a/src/main/webapp/WEB-INF/views/modules/cms/front/themes/basic/layouts/default.jsp b/src/main/webapp/WEB-INF/views/modules/cms/front/themes/basic/layouts/default.jsp index 82d28114bf20ea1aa4299ed5336bb13f29de877a..6b56732dc49f1b15569fba154a204370ea36b78c 100644 --- a/src/main/webapp/WEB-INF/views/modules/cms/front/themes/basic/layouts/default.jsp +++ b/src/main/webapp/WEB-INF/views/modules/cms/front/themes/basic/layouts/default.jsp @@ -6,7 +6,7 @@ <sitemesh:title default="欢迎光临"/> - ${site.title} - Powered By JeeSite <%@include file="/WEB-INF/views/modules/cms/front/include/head.jsp" %> - +