diff --git a/FastChar.iml b/FastChar.iml index 5826613..2a6eddd 100644 --- a/FastChar.iml +++ b/FastChar.iml @@ -10,15 +10,6 @@ - - - - - - - - - @@ -55,5 +46,12 @@ + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 875f1e8..adf7d08 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.fastchar fastchar - 1.5.4 + 1.5.5 @@ -316,6 +316,24 @@ + + + io.netty + netty-all + 4.1.58.Final + test + + + + + + org.springframework + spring-mock + 2.0.8 + test + + + \ No newline at end of file diff --git a/src/main/java/com/fastchar/core/FastAction.java b/src/main/java/com/fastchar/core/FastAction.java index ccbf99d..090b289 100644 --- a/src/main/java/com/fastchar/core/FastAction.java +++ b/src/main/java/com/fastchar/core/FastAction.java @@ -30,6 +30,7 @@ import java.util.regex.Pattern; /** * Request请求处理类,FastChar核心类 + * * @author 沈建(Janesen) */ @SuppressWarnings("all") @@ -57,6 +58,7 @@ public abstract class FastAction { /** * 根据key获取一个对象锁 + * * @param key 唯一key * @return ReentrantLock */ @@ -66,6 +68,7 @@ public abstract class FastAction { /** * 删除一个对象锁 + * * @param key 唯一key */ protected void removeLock(String key) { @@ -74,6 +77,7 @@ public abstract class FastAction { /** * 获得路由地址 + * * @return String */ protected abstract String getRoute(); @@ -100,6 +104,7 @@ public abstract class FastAction { /** * 判断是否是multipart/form-data表单格式 + * * @return 布尔值 */ public boolean isMultipart() { @@ -125,6 +130,7 @@ public abstract class FastAction { /** * 获得项目的主路径地址,例如:http://localhost:8080/fastchar_test/ + * * @return 项目主路径 */ public String getProjectHost() { @@ -147,6 +153,7 @@ public abstract class FastAction { /** * 获得请求对象 + * * @return HttpServletRequest */ public HttpServletRequest getRequest() { @@ -168,6 +175,7 @@ public abstract class FastAction { /** * 获取Web全局上下文 + * * @return ServletContext */ public final ServletContext getServletContext() { @@ -176,6 +184,7 @@ public abstract class FastAction { /** * 判断参数是否为空 + * * @param paramName 参数名称 * @return 布尔值 */ @@ -185,6 +194,7 @@ public abstract class FastAction { /** * 判断参数是否不为空 + * * @param paramName 参数名 * @return 布尔值 */ @@ -194,6 +204,7 @@ public abstract class FastAction { /** * 判断参数是否为【空白】值 + * * @param paramName 参数名 * @return 布尔值 */ @@ -203,6 +214,7 @@ public abstract class FastAction { /** * 判断参数是否不为【空白】值 + * * @param paramName 参数名 * @return 布尔值 */ @@ -212,6 +224,7 @@ public abstract class FastAction { /** * 判断参数是否存在 + * * @param paramName 参数名 * @return 布尔值 */ @@ -221,7 +234,8 @@ public abstract class FastAction { /** * 添加请求的参数 - * @param paramName 参数名 + * + * @param paramName 参数名 * @param paramValue 参数值 * @return 当前对象 */ @@ -230,9 +244,31 @@ public abstract class FastAction { return this; } + /** + * 设置请求的参数,将覆盖request中的参数 + * + * @param paramName 参数名 + * @param paramValue 参数值 + * @return 当前对象 + */ + public FastAction setParam(String paramName, String paramValue) { + List waitRemove = new ArrayList<>(); + for (FastRequestParam param : params) { + if (param.getName().equals(paramName)) { + waitRemove.add(param); + } + } + if (waitRemove.size() > 0) { + params.removeAll(waitRemove); + } + params.add(new FastRequestParam().setName(paramName).setValue(paramValue).setDoSet(true)); + return this; + } + /** * 获取所有参数名称集合 + * * @return Set<String> */ public Set getParamNames() { @@ -251,7 +287,8 @@ public abstract class FastAction { /** * 获得参数 - * @param paramName 参数名 + * + * @param paramName 参数名 * @param defaultValue 默认值 * @return String */ @@ -261,6 +298,7 @@ public abstract class FastAction { /** * 获得参数 + * * @param paramName 参数名 * @return String */ @@ -270,8 +308,9 @@ public abstract class FastAction { /** * 获得参数 + * * @param paramName 参数名 - * @param notNull 是否不为空 + * @param notNull 是否不为空 * @return String */ public String getParam(String paramName, boolean notNull) { @@ -295,6 +334,7 @@ public abstract class FastAction { /** * 获得参数数组 + * * @param paramName 参数名 * @return String[] */ @@ -304,21 +344,27 @@ public abstract class FastAction { /** * 获得参数数组 + * * @param paramName 参数名 - * @param notNull 是否不为空 + * @param notNull 是否不为空 * @return String[] */ public String[] getParamToArray(String paramName, boolean notNull) { String[] parameterValues = getRequest().getParameterValues(paramName); List arrays = new ArrayList<>(); - if (parameterValues != null) { - arrays.addAll(Arrays.asList(parameterValues)); - } + + //2021-1-11 新增 + boolean breakRequestValue = false; for (FastRequestParam param : params) { if (param.getName().equals(paramName)) { arrays.add(param.getValue()); + breakRequestValue = param.isDoSet(); } } + + if (parameterValues != null && !breakRequestValue) { + arrays.addAll(Arrays.asList(parameterValues)); + } if (arrays.size() == 0 && notNull) { responseParamError(paramName, FastChar.getLocal().getInfo(FastCharLocal.PARAM_ERROR1, paramName)); } @@ -331,6 +377,7 @@ public abstract class FastAction { /** * 获得参数数组 + * * @param paramName 参数名 * @return Integer[] */ @@ -340,14 +387,18 @@ public abstract class FastAction { /** * 获得参数数组 + * * @param paramName 参数名 - * @param notNull 是否不为空 + * @param notNull 是否不为空 * @return Integer[] */ public Integer[] getParamToIntArray(String paramName, boolean notNull) { List arrays = new ArrayList<>(); String[] parameterValues = getParamToArray(paramName, notNull); for (String parameterValue : parameterValues) { + if (FastStringUtils.isEmpty(parameterValue)) { + continue; + } arrays.add(FastNumberUtils.formatToInt(parameterValue)); } return arrays.toArray(new Integer[]{}); @@ -355,6 +406,7 @@ public abstract class FastAction { /** * 获得参数数组 + * * @param paramName 参数名 * @return Double[] */ @@ -364,14 +416,18 @@ public abstract class FastAction { /** * 获得参数数组 + * * @param paramName 参数名 - * @param notNull 是否不为空 + * @param notNull 是否不为空 * @return Double[] */ public Double[] getParamToDoubleArray(String paramName, boolean notNull) { List arrays = new ArrayList<>(); String[] parameterValues = getParamToArray(paramName, notNull); for (String parameterValue : parameterValues) { + if (FastStringUtils.isEmpty(parameterValue)) { + continue; + } arrays.add(FastNumberUtils.formatToDouble(parameterValue)); } return arrays.toArray(new Double[]{}); @@ -379,6 +435,7 @@ public abstract class FastAction { /** * 获得参数数组 + * * @param paramName 参数名 * @return Long[] */ @@ -388,14 +445,18 @@ public abstract class FastAction { /** * 获得参数数组 + * * @param paramName 参数名 - * @param notNull 是否不为空 + * @param notNull 是否不为空 * @return Long[] */ public Long[] getParamToLongArray(String paramName, boolean notNull) { List arrays = new ArrayList<>(); String[] parameterValues = getParamToArray(paramName, notNull); for (String parameterValue : parameterValues) { + if (FastStringUtils.isEmpty(parameterValue)) { + continue; + } arrays.add(FastNumberUtils.formatToLong(parameterValue)); } return arrays.toArray(new Long[]{}); @@ -403,6 +464,7 @@ public abstract class FastAction { /** * 获得参数数组 + * * @param paramName 参数名 * @return Float[] */ @@ -412,14 +474,18 @@ public abstract class FastAction { /** * 获得参数数组 + * * @param paramName 参数名 - * @param notNull 是否不为空 + * @param notNull 是否不为空 * @return Float[] */ public Float[] getParamToFloatArray(String paramName, boolean notNull) { List arrays = new ArrayList<>(); String[] parameterValues = getParamToArray(paramName, notNull); for (String parameterValue : parameterValues) { + if (FastStringUtils.isEmpty(parameterValue)) { + continue; + } arrays.add(FastNumberUtils.formatToFloat(parameterValue)); } return arrays.toArray(new Float[]{}); @@ -427,6 +493,7 @@ public abstract class FastAction { /** * 获得参数数组 + * * @param paramName 参数名 * @return Short[] */ @@ -436,14 +503,18 @@ public abstract class FastAction { /** * 获得参数数组 + * * @param paramName 参数名 - * @param notNull 是否不为空 + * @param notNull 是否不为空 * @return Short[] */ public Short[] getParamToShortArray(String paramName, boolean notNull) { List arrays = new ArrayList<>(); String[] parameterValues = getParamToArray(paramName, notNull); for (String parameterValue : parameterValues) { + if (FastStringUtils.isEmpty(parameterValue)) { + continue; + } arrays.add(FastNumberUtils.formatToShort(parameterValue)); } return arrays.toArray(new Short[]{}); @@ -451,6 +522,7 @@ public abstract class FastAction { /** * 获得参数数组 + * * @param paramName 参数名 * @return Boolean[] */ @@ -460,14 +532,18 @@ public abstract class FastAction { /** * 获得参数数组 + * * @param paramName 参数名 - * @param notNull 是否不为空 + * @param notNull 是否不为空 * @return Boolean[] */ public Boolean[] getParamToBooleanArray(String paramName, boolean notNull) { List arrays = new ArrayList<>(); String[] parameterValues = getParamToArray(paramName, notNull); for (String parameterValue : parameterValues) { + if (FastStringUtils.isEmpty(parameterValue)) { + continue; + } arrays.add(FastBooleanUtils.formatToBoolean(parameterValue)); } return arrays.toArray(new Boolean[]{}); @@ -475,6 +551,7 @@ public abstract class FastAction { /** * 获得参数数组,符合系统全局日期格式 + * * @param paramName 参数名 * @return Date[] */ @@ -484,8 +561,9 @@ public abstract class FastAction { /** * 获得参数数组 ,符合系统全局日期格式 + * * @param paramName 参数名 - * @param notNull 是否不为空 + * @param notNull 是否不为空 * @return Date[] */ public Date[] getParamToDateArray(String paramName, boolean notNull) { @@ -494,7 +572,8 @@ public abstract class FastAction { /** * 获得参数数组,符合系统全局日期格式 - * @param paramName 参数名 + * + * @param paramName 参数名 * @param dateFormat 日期格式类型,例如:yyyy-MM-dd * @return Date[] */ @@ -504,15 +583,19 @@ public abstract class FastAction { /** * 获得参数数组,符合系统全局日期格式 - * @param paramName 参数名 + * + * @param paramName 参数名 * @param dateFormat 日期格式类型,例如:yyyy-MM-dd - * @param notNull 是否不为空 + * @param notNull 是否不为空 * @return Date[] */ public Date[] getParamToDateArray(String paramName, String dateFormat, boolean notNull) { List arrays = new ArrayList<>(); String[] parameterValues = getParamToArray(paramName, notNull); for (String parameterValue : parameterValues) { + if (FastStringUtils.isEmpty(parameterValue)) { + continue; + } arrays.add(FastDateUtils.parse(parameterValue, dateFormat)); } return arrays.toArray(new Date[]{}); @@ -520,9 +603,10 @@ public abstract class FastAction { /** * 获得参数数组 + * * @param paramName 参数名 * @param enumClass 枚举的类 - * @param 继承Enum的类 + * @param 继承Enum的类 * @return T[] */ public T[] getParamToEnumArray(String paramName, Class enumClass) { @@ -531,17 +615,22 @@ public abstract class FastAction { /** * 获得参数数组 + * * @param paramName 参数名 * @param enumClass 枚举的类 - * @param notNull 是否不为空 - * @param 继承Enum的类 + * @param notNull 是否不为空 + * @param 继承Enum的类 * @return T[] */ public T[] getParamToEnumArray(String paramName, Class enumClass, boolean notNull) { String[] parameterValues = getParamToArray(paramName, notNull); Object array = Array.newInstance(enumClass, parameterValues.length); for (int i = 0; i < parameterValues.length; i++) { - T e = FastEnumUtils.formatToEnum(enumClass, parameterValues[i]); + String parameterValue = parameterValues[i]; + if (FastStringUtils.isEmpty(parameterValue)) { + continue; + } + T e = FastEnumUtils.formatToEnum(enumClass, parameterValue); Array.set(array, i, e); } return (T[]) array; @@ -550,6 +639,7 @@ public abstract class FastAction { /** * 获得参数集合 + * * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map * @return List<String> */ @@ -559,7 +649,8 @@ public abstract class FastAction { /** * 获得参数集合 - * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map + * + * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map * @param notNull 是否不为空 * @return List<String> */ @@ -589,6 +680,7 @@ public abstract class FastAction { /** * 获得参数集合 + * * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map * @return List<Integer> */ @@ -598,7 +690,8 @@ public abstract class FastAction { /** * 获得参数集合 - * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map + * + * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map * @param notNull 是否不为空 * @return List<Integer> */ @@ -606,6 +699,9 @@ public abstract class FastAction { List list = new ArrayList<>(); List paramToList = getParamToList(prefix, notNull); for (String value : paramToList) { + if (FastStringUtils.isEmpty(value)) { + continue; + } list.add(FastNumberUtils.formatToInt(value)); } return list; @@ -613,6 +709,7 @@ public abstract class FastAction { /** * 获得参数集合 + * * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map * @return List<Double> */ @@ -622,7 +719,8 @@ public abstract class FastAction { /** * 获得参数集合 - * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map + * + * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map * @param notNull 是否不为空 * @return List<Double> */ @@ -630,6 +728,9 @@ public abstract class FastAction { List list = new ArrayList<>(); List paramToList = getParamToList(prefix, notNull); for (String value : paramToList) { + if (FastStringUtils.isEmpty(value)) { + continue; + } list.add(FastNumberUtils.formatToDouble(value)); } return list; @@ -637,6 +738,7 @@ public abstract class FastAction { /** * 获得参数集合 + * * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map * @return List<Float> */ @@ -646,7 +748,8 @@ public abstract class FastAction { /** * 获得参数集合 - * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map + * + * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map * @param notNull 是否不为空 * @return List<Float> */ @@ -654,6 +757,9 @@ public abstract class FastAction { List list = new ArrayList<>(); List paramToList = getParamToList(prefix, notNull); for (String value : paramToList) { + if (FastStringUtils.isEmpty(value)) { + continue; + } list.add(FastNumberUtils.formatToFloat(value)); } return list; @@ -661,6 +767,7 @@ public abstract class FastAction { /** * 获得参数集合 + * * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map * @return List<Long> */ @@ -670,7 +777,8 @@ public abstract class FastAction { /** * 获得参数集合 - * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map + * + * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map * @param notNull 是否不为空 * @return List<Long> */ @@ -678,6 +786,9 @@ public abstract class FastAction { List list = new ArrayList<>(); List paramToList = getParamToList(prefix, notNull); for (String value : paramToList) { + if (FastStringUtils.isEmpty(value)) { + continue; + } list.add(FastNumberUtils.formatToLong(value)); } return list; @@ -685,6 +796,7 @@ public abstract class FastAction { /** * 获得参数集合 + * * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map * @return List<Short> */ @@ -694,7 +806,8 @@ public abstract class FastAction { /** * 获得参数集合 - * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map + * + * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map * @param notNull 是否不为空 * @return List<Short> */ @@ -702,6 +815,9 @@ public abstract class FastAction { List list = new ArrayList<>(); List paramToList = getParamToList(prefix, notNull); for (String value : paramToList) { + if (FastStringUtils.isEmpty(value)) { + continue; + } list.add(FastNumberUtils.formatToShort(value)); } return list; @@ -709,9 +825,10 @@ public abstract class FastAction { /** * 获得参数集合 - * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map + * + * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map * @param enumClass 枚举的类 - * @param 继承Enum的类 + * @param 继承Enum的类 * @return List<T> */ public List getParamToEnumList(String prefix, Class enumClass) { @@ -719,11 +836,12 @@ public abstract class FastAction { } /** - * 获得参数集合 - * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map + * 获得参数集合 + * + * @param prefix 参数前缀,例如参数为:map.userId 那么参数前缀为:map * @param enumClass 枚举的类 - * @param notNull 是否不为空 - * @param 继承Enum的泛型类 + * @param notNull 是否不为空 + * @param 继承Enum的泛型类 * @return List<T> */ public List getParamToEnumList(String prefix, Class enumClass, boolean notNull) { @@ -732,7 +850,11 @@ public abstract class FastAction { List paramToList = getParamToList(prefix, notNull); Object array = Array.newInstance(enumClass, paramToList.size()); for (int i = 0; i < paramToList.size(); i++) { - T e = FastEnumUtils.formatToEnum(enumClass, paramToList.get(i)); + String value = paramToList.get(i); + if (FastStringUtils.isEmpty(value)) { + continue; + } + T e = FastEnumUtils.formatToEnum(enumClass, value); Array.set(array, i, e); } list.addAll(Arrays.asList((T[]) array)); @@ -742,6 +864,7 @@ public abstract class FastAction { /** * 获得参数 + * * @param paramName 参数名 * @return int */ @@ -751,8 +874,9 @@ public abstract class FastAction { /** * 获得参数 + * * @param paramName 参数名 - * @param notNull 是否不为空 + * @param notNull 是否不为空 * @return int */ public int getParamToInt(String paramName, boolean notNull) { @@ -761,7 +885,8 @@ public abstract class FastAction { /** * 获得参数 - * @param paramName 参数名 + * + * @param paramName 参数名 * @param defaultValue 默认值 * @return int */ @@ -771,6 +896,7 @@ public abstract class FastAction { /** * 获得参数 + * * @param paramName 参数名 * @return short */ @@ -780,8 +906,9 @@ public abstract class FastAction { /** * 获得参数 + * * @param paramName 参数名 - * @param notNull 是否不为空 + * @param notNull 是否不为空 * @return short */ public short getParamToShort(String paramName, boolean notNull) { @@ -791,7 +918,8 @@ public abstract class FastAction { /** * 获得参数 - * @param paramName 参数名 + * + * @param paramName 参数名 * @param defaultValue 默认值 * @return int */ @@ -802,6 +930,7 @@ public abstract class FastAction { /** * 获得参数 + * * @param paramName 参数名 * @return double */ @@ -811,8 +940,9 @@ public abstract class FastAction { /** * 获得参数 + * * @param paramName 参数名 - * @param notNull 是否不为空 + * @param notNull 是否不为空 * @return double */ public double getParamToDouble(String paramName, boolean notNull) { @@ -821,7 +951,8 @@ public abstract class FastAction { /** * 获得参数 - * @param paramName 参数名 + * + * @param paramName 参数名 * @param defaultValue 默认值 * @return double */ @@ -831,8 +962,9 @@ public abstract class FastAction { /** * 获得参数 + * * @param paramName 参数名 - * @param digit 精度,例如传2 表示保留2位小数 + * @param digit 精度,例如传2 表示保留2位小数 * @return double */ public double getParamToDouble(String paramName, int digit) { @@ -841,9 +973,10 @@ public abstract class FastAction { /** * 获得参数 - * @param paramName 参数名 + * + * @param paramName 参数名 * @param defaultValue 默认值 - * @param digit 精度,例如传2 表示保留2位小数 + * @param digit 精度,例如传2 表示保留2位小数 * @return double */ public double getParamToDouble(String paramName, double defaultValue, int digit) { @@ -852,6 +985,7 @@ public abstract class FastAction { /** * 获得参数 + * * @param paramName 参数名 * @return float */ @@ -861,8 +995,9 @@ public abstract class FastAction { /** * 获得参数 + * * @param paramName 参数名 - * @param notNull 是否不为空 + * @param notNull 是否不为空 * @return float */ public float getParamToFloat(String paramName, boolean notNull) { @@ -871,7 +1006,8 @@ public abstract class FastAction { /** * 获得参数 - * @param paramName 参数名 + * + * @param paramName 参数名 * @param defaultValue 默认值 * @return float */ @@ -881,9 +1017,10 @@ public abstract class FastAction { /** * 获得参数 - * @param paramName 参数名 + * + * @param paramName 参数名 * @param defaultValue 默认值 - * @param digit 精度,例如传2 表示保留2位小数 + * @param digit 精度,例如传2 表示保留2位小数 * @return float */ public float getParamToFloat(String paramName, float defaultValue, int digit) { @@ -892,8 +1029,9 @@ public abstract class FastAction { /** * 获得参数 + * * @param paramName 参数名 - * @param digit 精度,例如传2 表示保留2位小数 + * @param digit 精度,例如传2 表示保留2位小数 * @return double */ public float getParamToFloat(String paramName, int digit) { @@ -902,6 +1040,7 @@ public abstract class FastAction { /** * 获得参数 + * * @param paramName 参数名 * @return boolean */ @@ -911,8 +1050,9 @@ public abstract class FastAction { /** * 获得参数 + * * @param paramName 参数名 - * @param notNull 是否不为空 + * @param notNull 是否不为空 * @return boolean */ public boolean getParamToBoolean(String paramName, boolean notNull) { @@ -921,7 +1061,8 @@ public abstract class FastAction { /** * 获得参数 - * @param paramName 参数名 + * + * @param paramName 参数名 * @param defaultValue 默认值 * @return boolean */ @@ -931,6 +1072,7 @@ public abstract class FastAction { /** * 获得参数 + * * @param paramName 参数名 * @return long */ @@ -940,8 +1082,9 @@ public abstract class FastAction { /** * 获得参数 + * * @param paramName 参数名 - * @param notNull 是否不为空 + * @param notNull 是否不为空 * @return long */ public long getParamToLong(String paramName, boolean notNull) { @@ -950,7 +1093,8 @@ public abstract class FastAction { /** * 获得参数 - * @param paramName 参数名 + * + * @param paramName 参数名 * @param defaultValue 默认值 * @return long */ @@ -960,6 +1104,7 @@ public abstract class FastAction { /** * 获得参数 + * * @param paramName 参数名 * @return Date */ @@ -969,8 +1114,9 @@ public abstract class FastAction { /** * 获得参数 + * * @param paramName 参数名 - * @param notNull 是否不为空 + * @param notNull 是否不为空 * @return Date */ public Date getParamToDate(String paramName, boolean notNull) { @@ -979,7 +1125,8 @@ public abstract class FastAction { /** * 获得参数 - * @param paramName 参数名 + * + * @param paramName 参数名 * @param defaultValue 默认值 * @return Date */ @@ -989,19 +1136,21 @@ public abstract class FastAction { /** * 获得参数 - * @param paramName 参数名 + * + * @param paramName 参数名 * @param dateFormat 日期格式,例如:yyyy-MM-dd * @return Date */ public Date getParamToDate(String paramName, String dateFormat) { - return getParamToDate(paramName,dateFormat, null); + return getParamToDate(paramName, dateFormat, null); } /** * 获得参数 - * @param paramName 参数名 + * + * @param paramName 参数名 * @param dateFormat 日期格式,例如:yyyy-MM-dd - * @param notNull 是否不为空 + * @param notNull 是否不为空 * @return Date */ public Date getParamToDate(String paramName, String dateFormat, boolean notNull) { @@ -1010,8 +1159,9 @@ public abstract class FastAction { /** * 获得参数 - * @param paramName 参数名 - * @param dateFormat 日期格式,例如:yyyy-MM-dd + * + * @param paramName 参数名 + * @param dateFormat 日期格式,例如:yyyy-MM-dd * @param defaultValue 默认值 * @return Date */ @@ -1021,9 +1171,10 @@ public abstract class FastAction { /** * 获得参数 + * * @param paramName 参数名 * @param enumClass 枚举的类 - * @param 继承Enum的类 + * @param 继承Enum的类 * @return T */ public T getParamToEnum(String paramName, Class enumClass) { @@ -1032,10 +1183,11 @@ public abstract class FastAction { /** * 获得参数 + * * @param paramName 参数名 * @param enumClass 枚举的类 - * @param notNull 是否不为空 - * @param 继承Enum的类 + * @param notNull 是否不为空 + * @param 继承Enum的类 * @return T */ public T getParamToEnum(String paramName, Class enumClass, boolean notNull) { @@ -1044,10 +1196,11 @@ public abstract class FastAction { /** * 获得参数 - * @param paramName 参数名 - * @param enumClass 枚举的类 + * + * @param paramName 参数名 + * @param enumClass 枚举的类 * @param defaultValue 默认值 - * @param 继承Enum的类 + * @param 继承Enum的类 * @return T */ public T getParamToEnum(String paramName, Class enumClass, Enum defaultValue) { @@ -1056,11 +1209,12 @@ public abstract class FastAction { /** * 获得参数 - * @param paramName 参数名 - * @param enumClass 枚举的类 + * + * @param paramName 参数名 + * @param enumClass 枚举的类 * @param defaultValue 默认值 - * @param notNull 是否不为空 - * @param 继承Enum的类 + * @param notNull 是否不为空 + * @param 继承Enum的类 * @return T */ private T getParamToEnum(String paramName, Class enumClass, Enum defaultValue, boolean notNull) { @@ -1073,6 +1227,7 @@ public abstract class FastAction { /** * 获得参数的map对象 + * * @return Map<String, Object> */ public Map getParamToMap() { @@ -1096,6 +1251,7 @@ public abstract class FastAction { /** * 获得参数的map对象 + * * @param prefix 参数前缀,例如参数名:where.attr或where['attr'] 前缀都为:where * @return Map<String, Object> */ @@ -1105,7 +1261,8 @@ public abstract class FastAction { /** * 获得参数的map对象 - * @param prefix 参数前缀,例如参数名:where.attr或where['attr'] 前缀都为:where + * + * @param prefix 参数前缀,例如参数名:where.attr或where['attr'] 前缀都为:where * @param notNull 是否不为空 * @return Map<String, Object> */ @@ -1142,6 +1299,7 @@ public abstract class FastAction { /** * 获得参数的map集合 + * * @param prefix 参数前缀,参数前缀,例如参数名:where[i].name或where[i]['name'] 前缀都为:where,其中 i 是可变的数字 * @return List<Map<String, Object>> */ @@ -1151,7 +1309,8 @@ public abstract class FastAction { /** * 获得参数的map集合 - * @param prefix 参数前缀,参数前缀,例如参数名:where[i].name或where[i]['name'] 前缀都为:where,其中 i 是可变的数字 + * + * @param prefix 参数前缀,参数前缀,例如参数名:where[i].name或where[i]['name'] 前缀都为:where,其中 i 是可变的数字 * @param notNull 是否不为空 * @return List<Map<String, Object>> */ @@ -1182,9 +1341,10 @@ public abstract class FastAction { /** * 获得entity实体 - * @param prefix 参数前缀,例如参数名:where.attr或where['attr'] 前缀都为:where + * + * @param prefix 参数前缀,例如参数名:where.attr或where['attr'] 前缀都为:where * @param targetClass 实体类 - * @param 继承FastEntity的类 + * @param 继承FastEntity的类 * @return T */ public > T getParamToEntity(String prefix, Class targetClass) { @@ -1194,10 +1354,11 @@ public abstract class FastAction { /** * 获得entity实体 - * @param prefix 参数前缀,例如参数名:where.attr或where['attr'] 前缀都为:where + * + * @param prefix 参数前缀,例如参数名:where.attr或where['attr'] 前缀都为:where * @param targetClass 实体类 - * @param notNull 是否不为空 - * @param 继承FastEntity的类 + * @param notNull 是否不为空 + * @param 继承FastEntity的类 * @return T */ public > T getParamToEntity(String prefix, Class targetClass, @@ -1219,9 +1380,10 @@ public abstract class FastAction { /** * 获得entity实体集合 - * @param prefix 参数前缀,例如参数名:where[i].name或where[i]['name'] 前缀都为:where,其中 i 是可变的数字 + * + * @param prefix 参数前缀,例如参数名:where[i].name或where[i]['name'] 前缀都为:where,其中 i 是可变的数字 * @param targetClass 实体类 - * @param 继承FastEntity的类 + * @param 继承FastEntity的类 * @return List<T> */ public > List getParamToEntityList(String prefix, Class targetClass) { @@ -1230,10 +1392,11 @@ public abstract class FastAction { /** * 获得entity实体集合 - * @param prefix 参数前缀,例如参数名:where[i].name或where[i]['name'] 前缀都为:where,其中 i 是可变的数字 + * + * @param prefix 参数前缀,例如参数名:where[i].name或where[i]['name'] 前缀都为:where,其中 i 是可变的数字 * @param targetClass 实体类 - * @param notNull 是否不为空 - * @param 继承FastEntity的类 + * @param notNull 是否不为空 + * @param 继承FastEntity的类 * @return List<T> */ public > List getParamToEntityList(String prefix, Class targetClass, boolean notNull) { @@ -1261,9 +1424,10 @@ public abstract class FastAction { /** * 获得entity实体数组 - * @param prefix 参数前缀,例如参数名:where[i].name或where[i]['name'] 前缀都为:where,其中 i 是可变的数字 + * + * @param prefix 参数前缀,例如参数名:where[i].name或where[i]['name'] 前缀都为:where,其中 i 是可变的数字 * @param targetClass 实体类 - * @param 继承FastEntity的类 + * @param 继承FastEntity的类 * @return T[] */ public > T[] getParamToEntityArray(String prefix, Class targetClass) { @@ -1272,10 +1436,11 @@ public abstract class FastAction { /** * 获得entity实体数组 - * @param prefix 参数前缀,例如参数名:where[i].name或where[i]['name'] 前缀都为:where,其中 i 是可变的数字 + * + * @param prefix 参数前缀,例如参数名:where[i].name或where[i]['name'] 前缀都为:where,其中 i 是可变的数字 * @param targetClass 实体类 - * @param notNull 是否不为空 - * @param 继承FastEntity的类 + * @param notNull 是否不为空 + * @param 继承FastEntity的类 * @return T[] */ public > T[] getParamToEntityArray(String prefix, Class targetClass, boolean notNull) { @@ -1289,9 +1454,10 @@ public abstract class FastAction { /** * 获得任意类型的参数,触发IFastParamConverter转换器进行转换 - * @param paramName 参数名 + * + * @param paramName 参数名 * @param targetClass 目标类型 - * @param 泛型类 + * @param 泛型类 * @return T * @throws Exception 抛出转换异常 */ @@ -1300,11 +1466,12 @@ public abstract class FastAction { } /** - * 获得任意类型的参数,触发IFastParamConverter转换器进行转换 - * @param paramName 参数名 - * @param targetClass 目标类型 + * 获得任意类型的参数,触发IFastParamConverter转换器进行转换 + * + * @param paramName 参数名 + * @param targetClass 目标类型 * @param parameterizedType 目标类型 - * @param 泛型类 + * @param 泛型类 * @return T * @throws Exception 抛出转换异常 */ @@ -1319,6 +1486,7 @@ public abstract class FastAction { /** * 添加参数文件对象 + * * @param fastFile 文件 * @return 当前对象 */ @@ -1335,18 +1503,22 @@ public abstract class FastAction { * 删除当前request下的所有本地附件 */ public void deleteAllParamFiles() { - for (FastFile fastFile : getParamListFile()) { - fastFile.getFile().delete(); + List> paramListFile = getParamListFile(); + if (paramListFile != null) { + for (FastFile fastFile : paramListFile) { + fastFile.getFile().delete(); + } } } /** * 获得上传的附件 + * * @return FastFile */ public > T getParamFile() { List> paramToListFile = getParamListFile(); - if (paramToListFile.size() > 0) { + if (paramToListFile != null && paramToListFile.size() > 0) { return (T) paramToListFile.get(0); } return null; @@ -1354,6 +1526,7 @@ public abstract class FastAction { /** * 获得上传的附件 + * * @param paramName 参数名 * @return FastFile */ @@ -1368,15 +1541,21 @@ public abstract class FastAction { /** * 获得上传的附件数组 + * * @param paramName 参数名 * @return List<FastFile<?>> */ public > List getParamFileList(String paramName) { - return (List) Arrays.asList(getParamFiles(paramName)); + FastFile[] paramFiles = getParamFiles(paramName); + if (paramFiles != null) { + return (List) Arrays.asList(paramFiles); + } + return null; } /** * 获得上传的附件数组 + * * @param paramName 参数名 * @return FastFile[] */ @@ -1391,7 +1570,8 @@ public abstract class FastAction { /** * 获得上传的附件 - * @param paramName 参数名 + * + * @param paramName 参数名 * @param moveToDirectory 保存到指定的目录下 * @return FastFile * @throws FastFileException 抛出文件异常 @@ -1406,32 +1586,40 @@ public abstract class FastAction { /** * 获得上传的附件数组 + * * @param paramName 参数名 * @return List<FastFile<?>> */ - public > List getParamFileList(String paramName, String moveToDirectory) throws FastFileException, IOException{ - return (List) Arrays.asList(getParamFiles(paramName, moveToDirectory)); + public > List getParamFileList(String paramName, String moveToDirectory) throws FastFileException, IOException { + FastFile[] paramFiles = getParamFiles(paramName, moveToDirectory); + if (paramFiles != null) { + return (List) Arrays.asList(paramFiles); + } + return null; } /** * 获得上传的附件 - * @param paramName 参数名 + * + * @param paramName 参数名 * @param moveToDirectory 保存到指定的目录下 * @return FastFile * @throws FastFileException 抛出文件异常 */ public > T[] getParamFiles(String paramName, String moveToDirectory) throws FastFileException, IOException { - FastFile[] paramToFiles= getParamFiles(paramName); - for (FastFile paramToFile : paramToFiles) { - paramToFile = paramToFile.moveFile(moveToDirectory); + FastFile[] paramToFiles = getParamFiles(paramName); + if (paramToFiles != null && FastStringUtils.isNotEmpty(moveToDirectory)) { + for (FastFile paramToFile : paramToFiles) { + paramToFile = paramToFile.moveFile(moveToDirectory); + } } return (T[]) paramToFiles; } - /** * 获得上传的附件集合 + * * @return List<FastFile<?>> */ public > List getParamListFile() { @@ -1472,6 +1660,7 @@ public abstract class FastAction { /** * 获得提交的xml数据 + * * @return Document * @throws Exception 抛出异常 */ @@ -1484,6 +1673,7 @@ public abstract class FastAction { /** * 获得提交的string数据 + * * @return String * @throws Exception 抛出异常 */ @@ -1493,6 +1683,7 @@ public abstract class FastAction { /** * 获得提交的string数据 + * * @param encoding 编码格式 * @return String * @throws Exception 抛出异常 @@ -1504,6 +1695,7 @@ public abstract class FastAction { /** * 响应数据 + * * @param out 响应对象 */ public void response(FastOut out) { @@ -1515,6 +1707,7 @@ public abstract class FastAction { /** * 响应Http状态码 + * * @param status 状态码 */ public void responseStatus(int status) { @@ -1523,6 +1716,7 @@ public abstract class FastAction { /** * 响应404界面 + * * @param message 404的消息提醒 */ public void response404(String message) { @@ -1531,6 +1725,7 @@ public abstract class FastAction { /** * 响应500界面 + * * @param throwable 异常信息 */ public void response500(Throwable throwable) { @@ -1546,6 +1741,7 @@ public abstract class FastAction { /** * 响应502界面 + * * @param message 502的消息提醒 */ public void response502(String message) { @@ -1555,6 +1751,7 @@ public abstract class FastAction { /** * 响应json数据 + * * @param data 数据 */ public void responseJson(Object data) { @@ -1563,6 +1760,7 @@ public abstract class FastAction { /** * 响应json数据 + * * @param jsonFile json文件 */ public void responseJson(File jsonFile) { @@ -1572,9 +1770,10 @@ public abstract class FastAction { /** * 响应指定格式的json数据,格式为:{code: *,success: *,message:*,data:*} - * @param code 错误码 0 为正常 + * + * @param code 错误码 0 为正常 * @param message 消息提示 - * @param data 响应的数据 + * @param data 响应的数据 */ public void responseJson(int code, String message, Object... data) { Map json = new HashMap<>(); @@ -1594,6 +1793,7 @@ public abstract class FastAction { /** * 响应文本 + * * @param data 数据 */ public void responseText(Object data) { @@ -1602,8 +1802,9 @@ public abstract class FastAction { /** * 响应文本 + * * @param status 响应状态码 - * @param data 数据 + * @param data 数据 */ public void responseText(int status, Object data) { response(FastChar.getOverrides().newInstance(FastOutText.class).setData(data).setStatus(status)); @@ -1611,7 +1812,8 @@ public abstract class FastAction { /** * 响应文本 - * @param data 数据 + * + * @param data 数据 * @param contentType 响应格式,例如:image/jpeg */ public void responseText(Object data, String contentType) { @@ -1620,8 +1822,9 @@ public abstract class FastAction { /** * 响应文本 - * @param status 状态码 - * @param data 数据 + * + * @param status 状态码 + * @param data 数据 * @param contentType 响应格式,例如:image/jpeg */ public void responseText(int status, Object data, String contentType) { @@ -1630,6 +1833,7 @@ public abstract class FastAction { /** * 响应xml + * * @param data 数据 */ public void responseXml(Object data) { @@ -1638,6 +1842,7 @@ public abstract class FastAction { /** * 响应xml + * * @param xmlFile xml文件 */ public void responseXml(File xmlFile) { @@ -1646,6 +1851,7 @@ public abstract class FastAction { /** * 响应参数错误 + * * @param paramName 参数名 */ public void responseParamError(String paramName) { @@ -1654,8 +1860,9 @@ public abstract class FastAction { /** * 响应参数错误 + * * @param paramName 参数名 - * @param message 错误消息 + * @param message 错误消息 */ public void responseParamError(String paramName, String message) { response(FastChar.getOverrides().newInstance(FastOutParamError.class) @@ -1665,6 +1872,7 @@ public abstract class FastAction { /** * 响应网页 + * * @param html 网页内容 */ public void responseHtml(Object html) { @@ -1672,9 +1880,9 @@ public abstract class FastAction { } - /** * 响应文件 + * * @param file 文件 */ public void responseFile(File file) { @@ -1683,7 +1891,8 @@ public abstract class FastAction { /** * 响应文件 - * @param file 文件 + * + * @param file 文件 * @param fileName 文件名,一般用作下载时浏览器保存的文件名 */ public void responseFile(File file, String fileName) { @@ -1692,7 +1901,8 @@ public abstract class FastAction { /** * 响应文件 - * @param file 文件 + * + * @param file 文件 * @param disposition 是否提示浏览器下载 */ public void responseFile(File file, boolean disposition) { @@ -1701,6 +1911,7 @@ public abstract class FastAction { /** * 响应文件 + * * @param filePath 文件本地路径 */ public void responseFile(String filePath) { @@ -1709,7 +1920,8 @@ public abstract class FastAction { /** * 响应文件 - * @param filePath 文件本地路径 + * + * @param filePath 文件本地路径 * @param disposition 是否提示浏览器下载 */ public void responseFile(String filePath, boolean disposition) { @@ -1718,6 +1930,7 @@ public abstract class FastAction { /** * 响应文件 + * * @param filePath 文件本地路径 * @param fileName 文件名,一般用作下载时浏览器保存的文件名 */ @@ -1727,8 +1940,9 @@ public abstract class FastAction { /** * 响应文件 - * @param filePath 文件本地路径 - * @param fileName 文件名,一般用作下载时浏览器保存的文件名 + * + * @param filePath 文件本地路径 + * @param fileName 文件名,一般用作下载时浏览器保存的文件名 * @param disposition 是否提示浏览器下载 */ public void responseFile(String filePath, String fileName, boolean disposition) { @@ -1742,6 +1956,7 @@ public abstract class FastAction { /** * 响应jsp + * * @param jspPath jsp文件路径 */ public void responseJsp(String jspPath) { @@ -1750,6 +1965,7 @@ public abstract class FastAction { /** * 响应Freemaker模板,使用Freemaker模板引擎 + * * @param filePath 模板路径 */ public void responseFreemarker(String filePath) { @@ -1758,7 +1974,8 @@ public abstract class FastAction { /** * 响应Freemaker模板,使用Freemaker模板引擎 - * @param filePath 模板路径 + * + * @param filePath 模板路径 * @param contentType 响应格式,例如:image/jpeg */ public void responseFreemarker(String filePath, String contentType) { @@ -1767,6 +1984,7 @@ public abstract class FastAction { /** * 响应Thymeleaf模板,使用Thymeleaf模板引擎 + * * @param filePath 模板路径 */ public void responseThymeleaf(String filePath) { @@ -1775,7 +1993,8 @@ public abstract class FastAction { /** * 响应Thymeleaf模板,使用Thymeleaf模板引擎 - * @param filePath 模板路径 + * + * @param filePath 模板路径 * @param contentType 响应格式,例如:image/jpeg */ public void responseThymeleaf(String filePath, String contentType) { @@ -1784,6 +2003,7 @@ public abstract class FastAction { /** * 响应Velocity模板,使用Velocity模板引擎 + * * @param filePath 模板路径 */ public void responseVelocity(String filePath) { @@ -1792,7 +2012,8 @@ public abstract class FastAction { /** * 响应Velocity模板,使用Velocity模板引擎 - * @param filePath 模板路径 + * + * @param filePath 模板路径 * @param contentType 响应格式,例如:image/jpeg */ public void responseVelocity(String filePath, String contentType) { @@ -1808,6 +2029,7 @@ public abstract class FastAction { /** * 响应图片 + * * @param image 图片流 */ public void responseImage(RenderedImage image) { @@ -1816,17 +2038,18 @@ public abstract class FastAction { /** * 响应图片 - * @param image 图片流 - * @param formatName 图片格式 * + * @param image 图片流 + * @param formatName 图片格式 */ - public void responseImage(RenderedImage image,String formatName) { + public void responseImage(RenderedImage image, String formatName) { response(FastChar.getOverrides().newInstance(FastOutImage.class).setData(image).setFormatName(formatName).setStatus(this.status)); } /** * 判断验证码是否正确 + * * @param code 图片验证码 * @return boolean */ @@ -1849,6 +2072,7 @@ public abstract class FastAction { /** * 重定向请求 + * * @param url 路径 */ public void redirect(String url) { @@ -1857,6 +2081,7 @@ public abstract class FastAction { /** * 重定向请求,响应状态码为:301 + * * @param url 路径 */ public void redirect301(String url) { @@ -1866,6 +2091,7 @@ public abstract class FastAction { /** * 转发请求 + * * @param url 路径 */ public void forward(String url) { @@ -1875,6 +2101,7 @@ public abstract class FastAction { /** * 获得请求的类型,POST或GET + * * @return String */ public final String getRequestMethod() { @@ -1883,6 +2110,7 @@ public abstract class FastAction { /** * 获得请求的contentType + * * @return String */ public String getContentType() { @@ -1891,6 +2119,7 @@ public abstract class FastAction { /** * 获取Session对象 + * * @return HttpSession */ public final HttpSession getSession() { @@ -1901,8 +2130,9 @@ public abstract class FastAction { /** * 获取Session属性值 + * * @param attr 属性 - * @param 泛型 + * @param 泛型 * @return T */ public T getSession(String attr) { @@ -1911,7 +2141,8 @@ public abstract class FastAction { /** * 设置session - * @param attr 属性名 + * + * @param attr 属性名 * @param value 属性值 */ public void setSession(String attr, Object value) { @@ -1921,6 +2152,7 @@ public abstract class FastAction { /** * 删除session + * * @param attr 属性名 */ public void removeSession(String attr) { @@ -1929,7 +2161,8 @@ public abstract class FastAction { /** * 设置Request属性值 - * @param attr 属性名 + * + * @param attr 属性名 * @param value 属性值 * @return 当前对象 */ @@ -1940,6 +2173,7 @@ public abstract class FastAction { /** * 设置Request属性值 + * * @param attrs 属性map集合 * @return 当前对象 */ @@ -1952,6 +2186,7 @@ public abstract class FastAction { /** * 获取Request属性值 + * * @param attr 属性名 * @return 属性值 */ @@ -1962,6 +2197,7 @@ public abstract class FastAction { /** * 删除Request属性 + * * @param attr 名称 */ public void removeRequestAttr(String attr) { @@ -1971,6 +2207,7 @@ public abstract class FastAction { /** * 获取请求的头信息 + * * @param name 名称 * @return 字符串 */ @@ -1980,6 +2217,7 @@ public abstract class FastAction { /** * 获取请求的头信息 + * * @param name 名称 * @return Enumeration<String> */ @@ -1989,6 +2227,7 @@ public abstract class FastAction { /** * 获取请求的头信息 + * * @return Enumeration<String> */ public Enumeration getRequestHeaderNames() { @@ -1998,10 +2237,11 @@ public abstract class FastAction { /** * 设置cookie - * @param name 名称 - * @param value 值 + * + * @param name 名称 + * @param value 值 * @param maxAge 有效期,单位:秒 - * @param path 路径 + * @param path 路径 * @param domain 域名 * @return 当前对象 */ @@ -2011,10 +2251,11 @@ public abstract class FastAction { /** * 设置cookie - * @param name 名称 - * @param value 值 + * + * @param name 名称 + * @param value 值 * @param maxAge 有效期,单位:秒 - * @param path 路径 + * @param path 路径 * @return 当前对象 */ public FastAction setCookie(String name, Object value, int maxAge, String path) { @@ -2023,10 +2264,11 @@ public abstract class FastAction { /** * 设置cookie - * @param name 名称 - * @param value 值 - * @param maxAge 有效期,单位:秒 - * @param path 路径 + * + * @param name 名称 + * @param value 值 + * @param maxAge 有效期,单位:秒 + * @param path 路径 * @param httpOnly 是否启用HttpOnly,启用后将无法通过js获取当前cookie值 * @return 当前对象 */ @@ -2036,9 +2278,10 @@ public abstract class FastAction { /** * 设置cookie - * @param name 名称 - * @param value 值 - * @param maxAge 有效期,单位:秒 + * + * @param name 名称 + * @param value 值 + * @param maxAge 有效期,单位:秒 * @param httpOnly 是否启用HttpOnly,启用后将无法通过js获取当前cookie值 * @return 当前对象 */ @@ -2048,8 +2291,9 @@ public abstract class FastAction { /** * 设置cookie - * @param name 名称 - * @param value 值 + * + * @param name 名称 + * @param value 值 * @param maxAge 有效期,单位:秒 * @return 当前对象 */ @@ -2059,7 +2303,8 @@ public abstract class FastAction { /** * 设置cookie - * @param name 名称 + * + * @param name 名称 * @param value 值 * @return 当前对象 */ @@ -2069,8 +2314,9 @@ public abstract class FastAction { /** * 设置cookie - * @param name 名称 - * @param value 值 + * + * @param name 名称 + * @param value 值 * @param httpOnly 是否启用HttpOnly,启用后将无法通过js获取当前cookie值 * @return 当前对象 */ @@ -2081,11 +2327,12 @@ public abstract class FastAction { /** * 设置cookie - * @param name 名称 - * @param value 值 - * @param maxAge 有效期,单位:秒 - * @param path 路径 - * @param domain 域名 + * + * @param name 名称 + * @param value 值 + * @param maxAge 有效期,单位:秒 + * @param path 路径 + * @param domain 域名 * @param httpOnly 是否启用HttpOnly,启用后将无法通过js获取当前cookie值 * @return 当前对象 */ @@ -2111,7 +2358,8 @@ public abstract class FastAction { /** * 获得cookie值 - * @param name 名称 + * + * @param name 名称 * @param defaultValue 默认值 * @return String */ @@ -2122,6 +2370,7 @@ public abstract class FastAction { /** * 获得cookie值 + * * @param name 名称 * @return String */ @@ -2131,6 +2380,7 @@ public abstract class FastAction { /** * 获得cookie值 + * * @param name 名称 * @return int */ @@ -2140,7 +2390,8 @@ public abstract class FastAction { /** * 获得cookie值 - * @param name 名称 + * + * @param name 名称 * @param defaultValue 默认值 * @return int */ @@ -2151,6 +2402,7 @@ public abstract class FastAction { /** * 获得cookie值 + * * @param name 名称 * @return double */ @@ -2160,7 +2412,8 @@ public abstract class FastAction { /** * 获得cookie值 - * @param name 名称 + * + * @param name 名称 * @param defaultValue 默认值 * @return double */ @@ -2171,6 +2424,7 @@ public abstract class FastAction { /** * 获得cookie值 + * * @param name 名称 * @return long */ @@ -2180,7 +2434,8 @@ public abstract class FastAction { /** * 获得cookie值 - * @param name 名称 + * + * @param name 名称 * @param defaultValue 默认值 * @return long */ @@ -2191,6 +2446,7 @@ public abstract class FastAction { /** * 获得cookie值 + * * @param name 名称 * @return boolean */ @@ -2200,7 +2456,8 @@ public abstract class FastAction { /** * 获得cookie值 - * @param name 名称 + * + * @param name 名称 * @param defaultValue 默认值 * @return boolean */ @@ -2211,6 +2468,7 @@ public abstract class FastAction { /** * 获得cookie + * * @param name 名称 * @return Cookie */ @@ -2250,8 +2508,8 @@ public abstract class FastAction { /** * 删除cookie * - * @param name 名称 - * @param path 相对路径 + * @param name 名称 + * @param path 相对路径 * @param domain domain * @return 当前对象 */ @@ -2272,6 +2530,7 @@ public abstract class FastAction { /** * 获得cookie数组 + * * @return Cookie[] */ public Cookie[] getCookieObjects() { @@ -2281,6 +2540,7 @@ public abstract class FastAction { /** * 获取响应对象 + * * @return HttpServletResponse */ public HttpServletResponse getResponse() { @@ -2289,6 +2549,7 @@ public abstract class FastAction { /** * 获取路径参数,例如实际路径为:/user 请求路径为:/user/1/abc 那么路径参数为:[1,abc] + * * @return List<String> */ public List getUrlParams() { @@ -2297,6 +2558,7 @@ public abstract class FastAction { /** * 获取路径参数,例如实际路径为:/user 请求路径为:/user/1/abc 那么路径参数为:[1,abc] + * * @param index 索引 * @return String */ @@ -2309,6 +2571,7 @@ public abstract class FastAction { /** * 获取当前Action的路由对象 + * * @return FastRoute */ public FastRoute getFastRoute() { @@ -2317,6 +2580,7 @@ public abstract class FastAction { /** * 获取最终响应的类型 + * * @return FastOut */ public FastOut getFastOut() { @@ -2325,6 +2589,7 @@ public abstract class FastAction { /** * 获取转发到当前action的action + * * @return FastAction */ public FastAction getForwarder() { @@ -2333,6 +2598,7 @@ public abstract class FastAction { /** * 是否打印日志 + * * @return 布尔值,默认:true */ public boolean isLog() { @@ -2341,6 +2607,7 @@ public abstract class FastAction { /** * 设置是否打印日志 + * * @param log 布尔值 * @return 当前对象 */ @@ -2351,6 +2618,7 @@ public abstract class FastAction { /** * 是否打印响应日志 + * * @return 布尔值 */ public boolean isLogResponse() { @@ -2359,6 +2627,7 @@ public abstract class FastAction { /** * 设置是否打印响应日志 + * * @param logResponse 布尔值 * @return 当前对象 */ @@ -2369,6 +2638,7 @@ public abstract class FastAction { /** * 获取设置的响应状态码 + * * @return 状态码 */ public int getStatus() { @@ -2377,6 +2647,7 @@ public abstract class FastAction { /** * 设置响应状态码 + * * @param status 状态码 * @return 当前对象 */ @@ -2387,6 +2658,7 @@ public abstract class FastAction { /** * 获取对方的ip地址 + * * @return String */ public String getRemoteIp() { @@ -2422,9 +2694,9 @@ public abstract class FastAction { } - /** * 获得request的user-agent + * * @return String */ public final String getUserAgent() { @@ -2434,6 +2706,7 @@ public abstract class FastAction { /** * 添加参数验证,会触发IFastValidator验证码器,只对getParam*相关方法有效 + * * @param validator 验证标识 * @return 当前对象 */ @@ -2443,11 +2716,12 @@ public abstract class FastAction { /** * 添加参数验证,会触发IFastValidator验证码器,只对getParam*相关方法有效 + * * @param validator 验证标识 - * @param index 插入指定位置 + * @param index 插入指定位置 * @return 当前对象 */ - public FastAction check(int index,String validator) { + public FastAction check(int index, String validator) { return fastCheck.check(index, validator); } diff --git a/src/main/java/com/fastchar/core/FastChar.java b/src/main/java/com/fastchar/core/FastChar.java index 325bbb5..0e9afb9 100644 --- a/src/main/java/com/fastchar/core/FastChar.java +++ b/src/main/java/com/fastchar/core/FastChar.java @@ -2,7 +2,6 @@ package com.fastchar.core; import com.fastchar.database.FastDb; import com.fastchar.interfaces.*; - import javax.servlet.ServletContext; /** @@ -158,8 +157,13 @@ public final class FastChar { return FastEngine.instance().getProperties(fileName); } + public static FastFindClass getFindClass() { + return FastEngine.instance().getFindClass(); + } public static boolean isMain() { return FastEngine.instance().isMain(); } + + } diff --git a/src/main/java/com/fastchar/core/FastConstant.java b/src/main/java/com/fastchar/core/FastConstant.java index e93eada..f87d5df 100644 --- a/src/main/java/com/fastchar/core/FastConstant.java +++ b/src/main/java/com/fastchar/core/FastConstant.java @@ -8,13 +8,14 @@ import java.util.*; /** * 系统全局配置 + * * @author 沈建(Janesen) */ public class FastConstant { /** * FastChar框架的版本 */ - public static final String FAST_CHAR_VERSION = "1.5.4"; + public static final String FAST_CHAR_VERSION = "1.5.5"; /** * 数据库xml配置文件的前缀 @@ -62,7 +63,7 @@ public class FastConstant { private boolean logHeaders = false;//打印请求的header信息 private boolean logRemoteAddress = false;//打印远程请求的地址 private boolean logInterceptorUseTotal = false;//打印拦截器的耗时时间 - private boolean logFilterResponseTime =false;//是否只打印 超时的路由日志 + private boolean logFilterResponseTime = false;//是否只打印 超时的路由日志 private boolean logSql = true;//是否打印sql语句日志 private boolean logExtract = false;//是否打印解压jar包的文件日志 private boolean logSameJar = false;//是否打印不同版本的jar包 @@ -83,6 +84,9 @@ public class FastConstant { private boolean webStarted;//web服务器是否已启动 private boolean webStopped;//web服务器是否已停止 + private boolean decodeUploadFileName = true;//是否使用URLDecoder解码上传文件的名称 + private String decodeUploadFileNameEncoding = encoding;//URLDecoder解码时的编码 + private int sessionMaxInterval = 30 * 60;//session失效时间,单位秒 默认30分钟 @@ -604,6 +608,7 @@ public class FastConstant { /** * 添加允许跨域的域名 + * * @param domains 域名地址 支持匹配符* * @return 当前对象 */ @@ -624,6 +629,7 @@ public class FastConstant { /** * 获取允许跨域的域名地址 + * * @return Set<String> */ public Set getCrossAllowDomains() { @@ -632,6 +638,7 @@ public class FastConstant { /** * 是否只打印请求响应时间超过配置的maxUseTotalLog时间日志 + * * @return 布尔值 */ public boolean isLogFilterResponseTime() { @@ -640,6 +647,7 @@ public class FastConstant { /** * 设置是否只打印请求响应时间超过配置的maxResponseTime时间日志 + * * @param logFilterResponseTime 布尔值 * @return 当前对象 */ @@ -650,6 +658,7 @@ public class FastConstant { /** * 是否打印sql语句 + * * @return 布尔值 */ public boolean isLogSql() { @@ -658,6 +667,7 @@ public class FastConstant { /** * 设置是否打印sql语句 + * * @param logSql 布尔值 * @return 当前对象 */ @@ -668,6 +678,7 @@ public class FastConstant { /** * 获取session失效时间,默认 30分钟 + * * @return 时间(秒) */ public int getSessionMaxInterval() { @@ -676,6 +687,7 @@ public class FastConstant { /** * 设置session失效时间 + * * @param sessionMaxInterval 时间(秒) * @return 当前对象 */ @@ -686,6 +698,7 @@ public class FastConstant { /** * 是否打印解压jar包的文件日志 + * * @return 布尔值 */ public boolean isLogExtract() { @@ -694,6 +707,7 @@ public class FastConstant { /** * 设置是否打印解压jar包的文件日志 + * * @param logExtract 布尔值 * @return 当前对象 */ @@ -704,6 +718,7 @@ public class FastConstant { /** * 是否打印远程请求的地址 + * * @return 布尔值 */ public boolean isLogRemoteAddress() { @@ -712,6 +727,7 @@ public class FastConstant { /** * 设置是否打印远程请求接口的地址 + * * @param logRemoteAddress 布尔值 * @return 当前对象 */ @@ -722,6 +738,7 @@ public class FastConstant { /** * 是否允许系统使用System.out输出打印 + * * @return 布尔值 */ public boolean isSystemOutPrint() { @@ -730,6 +747,7 @@ public class FastConstant { /** * 配置是否允许系统使用System.out输出打印 + * * @param systemOutPrint 布尔值 * @return 当前对象 */ @@ -740,6 +758,7 @@ public class FastConstant { /** * 获取项目的Web服务器是否已启动 + * * @return 布尔值 */ public boolean isWebStarted() { @@ -748,6 +767,7 @@ public class FastConstant { /** * 设置项目的Web服务器是否已启动 + * * @param webStarted 布尔值 * @return 当前对象 */ @@ -759,6 +779,7 @@ public class FastConstant { /** * 是否打印不同版本的JAR包 + * * @return 布尔值 */ public boolean isLogSameJar() { @@ -767,6 +788,7 @@ public class FastConstant { /** * 设置是否打印不同版本的JAR包 + * * @param logSameJar 布尔值 * @return 当前对象 */ @@ -775,6 +797,24 @@ public class FastConstant { return this; } + public boolean isDecodeUploadFileName() { + return decodeUploadFileName; + } + + public FastConstant setDecodeUploadFileName(boolean decodeUploadFileName) { + this.decodeUploadFileName = decodeUploadFileName; + return this; + } + + public String getDecodeUploadFileNameEncoding() { + return decodeUploadFileNameEncoding; + } + + public FastConstant setDecodeUploadFileNameEncoding(String decodeUploadFileNameEncoding) { + this.decodeUploadFileNameEncoding = decodeUploadFileNameEncoding; + return this; + } + @Override public String toString() { return "FastConstant{" + @@ -811,6 +851,8 @@ public class FastConstant { ", propertiesName='" + propertiesName + '\'' + ", webStarted=" + webStarted + ", webStopped=" + webStopped + + ", decodeUploadFileName=" + decodeUploadFileName + + ", decodeUploadFileNameEncoding='" + decodeUploadFileNameEncoding + '\'' + ", sessionMaxInterval=" + sessionMaxInterval + '}'; } diff --git a/src/main/java/com/fastchar/core/FastDatabases.java b/src/main/java/com/fastchar/core/FastDatabases.java index ceacf7b..d01abcf 100644 --- a/src/main/java/com/fastchar/core/FastDatabases.java +++ b/src/main/java/com/fastchar/core/FastDatabases.java @@ -209,6 +209,9 @@ public final class FastDatabases { } for (FastTableInfo table : databaseInfo.getTables()) { + if (table.getName().contains("*")) { + continue; + } if (table.getBoolean("enable", true) && table.isFromXml()) { if (!databaseOperate.checkTableExists(databaseInfo, table)) { if (notifyListener(1, databaseInfo, table, null)) { diff --git a/src/main/java/com/fastchar/core/FastEngine.java b/src/main/java/com/fastchar/core/FastEngine.java index 63a859f..0010c3b 100644 --- a/src/main/java/com/fastchar/core/FastEngine.java +++ b/src/main/java/com/fastchar/core/FastEngine.java @@ -73,7 +73,6 @@ public final class FastEngine { System.setErr(new FastErrorPrintStream(System.out, true)); observable.addObserver(FastDatabaseObserver.class); - constant.addCrossHeaders("Content-Type", "Access-Control-Allow-Headers", "Authorization", "X-Requested-With", "token"); } diff --git a/src/main/java/com/fastchar/core/FastEntity.java b/src/main/java/com/fastchar/core/FastEntity.java index 51ab675..63f61d5 100644 --- a/src/main/java/com/fastchar/core/FastEntity.java +++ b/src/main/java/com/fastchar/core/FastEntity.java @@ -645,7 +645,7 @@ public abstract class FastEntity> extends ConcurrentHash /** * 设置数据到数据库中,根据指定的检测属性,如果不存在则添加,存在则修改 * - * @param handler 操作句柄,可根据code判断数据最终是添加还是更新 0:添加 1:更新 + * @param handler 操作句柄,可根据code判断数据最终是添加还是更新 【0:添加 1:更新】 * @param checks 检测属性名,用作where判断 * @return 布尔值 */ @@ -1184,6 +1184,17 @@ public abstract class FastEntity> extends ConcurrentHash return getMapWrap().isNull(attr); } + /** + * 是否不为null + * + * @param attr 属性名 + * @return 布尔值 + */ + public boolean isNotNull(String attr) { + return getMapWrap().isNotNull(attr); + } + + /** * 是否为Timestamp类型 * diff --git a/src/main/java/com/fastchar/core/FastFile.java b/src/main/java/com/fastchar/core/FastFile.java index 08ef0b9..09efe5a 100644 --- a/src/main/java/com/fastchar/core/FastFile.java +++ b/src/main/java/com/fastchar/core/FastFile.java @@ -10,7 +10,9 @@ import com.fastchar.utils.FastStringUtils; import java.io.File; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.lang.reflect.Constructor; +import java.net.URLDecoder; import java.util.LinkedHashMap; import java.util.concurrent.ConcurrentHashMap; @@ -33,17 +35,20 @@ public class FastFile { public static FastFile newInstance(String attachDirectory, String fileName) { return FastChar.getOverrides().newInstance(FastFile.class) - .setAttachDirectory(attachDirectory).setFileName(fileName); + .setAttachDirectory(attachDirectory).setFileName(fileName).setParamName(fileName); } public static FastFile newInstance( String fileName) { return FastChar.getOverrides().newInstance(FastFile.class) .setAttachDirectory(FastChar.getConstant().getAttachDirectory()) + .setParamName(fileName) .setFileName(fileName); } public static FastFile newInstance(File file) { - return FastChar.getOverrides().newInstance(FastFile.class) + return FastChar.getOverrides() + .newInstance(FastFile.class) .setAttachDirectory(file.getParent()) + .setParamName(file.getName()) .setFileName(file.getName()); } @@ -104,6 +109,15 @@ public class FastFile { public FastFile setUploadFileName(String uploadFileName) { this.uploadFileName = uploadFileName; + if (FastChar.getConstant().isDecodeUploadFileName()) { + if (FastStringUtils.isNotEmpty(this.uploadFileName)) { + try { + this.uploadFileName = URLDecoder.decode(this.uploadFileName, FastChar.getConstant().getDecodeUploadFileNameEncoding()); + } catch (Exception e) { + e.printStackTrace(); + } + } + } return this; } diff --git a/src/main/java/com/fastchar/core/FastMapWrap.java b/src/main/java/com/fastchar/core/FastMapWrap.java index ae79571..c8e09ff 100644 --- a/src/main/java/com/fastchar/core/FastMapWrap.java +++ b/src/main/java/com/fastchar/core/FastMapWrap.java @@ -149,6 +149,15 @@ public class FastMapWrap { return "".equalsIgnoreCase(String.valueOf(value)); } + /** + * 是否不为null + * @param attr 属性名 + * @return 布尔值 + */ + public boolean isNotNull(String attr) { + return !isNull(attr); + } + /** * 是否为Timestamp类型 * @param attr 属性名 diff --git a/src/main/java/com/fastchar/core/FastRequestParam.java b/src/main/java/com/fastchar/core/FastRequestParam.java index e4176de..8bbdf88 100644 --- a/src/main/java/com/fastchar/core/FastRequestParam.java +++ b/src/main/java/com/fastchar/core/FastRequestParam.java @@ -3,6 +3,7 @@ package com.fastchar.core; public class FastRequestParam { private String name; private String value; + private boolean doSet; public String getName() { return name; @@ -21,4 +22,13 @@ public class FastRequestParam { this.value = value; return this; } + + public boolean isDoSet() { + return doSet; + } + + public FastRequestParam setDoSet(boolean doSet) { + this.doSet = doSet; + return this; + } } diff --git a/src/main/java/com/fastchar/core/FastScanner.java b/src/main/java/com/fastchar/core/FastScanner.java index 5d502c1..21ac670 100644 --- a/src/main/java/com/fastchar/core/FastScanner.java +++ b/src/main/java/com/fastchar/core/FastScanner.java @@ -307,7 +307,8 @@ public final class FastScanner { extract = scannerJar.getExtract(); } if (extract) { - String logInfo = FastChar.getLocal().getInfo(FastCharLocal.SCANNER_ERROR1, scannerJar.getJarFileName()); + String logInfo = FastChar.getLocal().getInfo(FastCharLocal.SCANNER_ERROR1, + scannerJar.getJarFileName() + " (" + FastFileUtils.getFileSize(scannerJar.getJarFile()) + ") "); FastChar.getLog().info(logInfo); } @@ -405,7 +406,8 @@ public final class FastScanner { } } if (extract) { - FastChar.getLog().info(FastChar.getLocal().getInfo(FastCharLocal.SCANNER_ERROR2, scannerJar.getJarFileName())); + FastChar.getLog().info(FastChar.getLocal().getInfo(FastCharLocal.SCANNER_ERROR2, + scannerJar.getJarFileName() + " (" + FastFileUtils.getFileSize(scannerJar.getJarFile()) + ") ")); } } } @@ -648,7 +650,6 @@ public final class FastScanner { private final String jarVersion; private String jarName; - public File getJarFile() { return jarFile; } diff --git a/src/main/java/com/fastchar/database/FastDatabaseXml.java b/src/main/java/com/fastchar/database/FastDatabaseXml.java index 5b854b7..c9eb216 100644 --- a/src/main/java/com/fastchar/database/FastDatabaseXml.java +++ b/src/main/java/com/fastchar/database/FastDatabaseXml.java @@ -166,7 +166,7 @@ public final class FastDatabaseXml { public static class DatabaseInfoHandler extends DefaultHandler { - private File xmlFile; + private final File xmlFile; private Locator locator; private FastDatabaseInfo databaseInfo; private FastTableInfo tableInfo; diff --git a/src/main/java/com/fastchar/database/info/FastDatabaseInfo.java b/src/main/java/com/fastchar/database/info/FastDatabaseInfo.java index ed3cb8a..fd21233 100644 --- a/src/main/java/com/fastchar/database/info/FastDatabaseInfo.java +++ b/src/main/java/com/fastchar/database/info/FastDatabaseInfo.java @@ -151,6 +151,17 @@ public class FastDatabaseInfo extends FastBaseInfo { return (List) tables; } + public > List findTables(String name) { + List findTales = new ArrayList<>(); + for (FastTableInfo table : tables) { + if (table.getName().contains(name)) { + findTales.add((T) table); + } + } + return findTales; + } + + public FastDatabaseInfo setTables(List> tables) { this.tables = tables; return this; @@ -337,6 +348,20 @@ public class FastDatabaseInfo extends FastBaseInfo { public void validate() throws FastDatabaseException { + //合并 * 号匹配的表格 + + List> matchesTableList = findTables("*"); + for (FastTableInfo matchesTable : matchesTableList) { + for (FastTableInfo table : this.tables) { + if (table.isLock()) { + continue; + } + if (FastStringUtils.matches(matchesTable.getName(), table.getName())) { + table.merge(matchesTable, true); + } + } + } + List> tables = new ArrayList<>(getTables()); for (FastTableInfo table : tables) { for (FastColumnInfo column : table.getColumns()) { @@ -348,6 +373,8 @@ public class FastDatabaseInfo extends FastBaseInfo { table.validate(); } } + + } } diff --git a/src/main/java/com/fastchar/database/info/FastTableInfo.java b/src/main/java/com/fastchar/database/info/FastTableInfo.java index 1fa70f7..5a72ede 100644 --- a/src/main/java/com/fastchar/database/info/FastTableInfo.java +++ b/src/main/java/com/fastchar/database/info/FastTableInfo.java @@ -6,6 +6,7 @@ import com.fastchar.core.FastMapWrap; import com.fastchar.exception.FastDatabaseException; import com.fastchar.local.FastCharLocal; +import com.fastchar.utils.FastBooleanUtils; import com.fastchar.utils.FastClassUtils; import com.fastchar.utils.FastStringUtils; @@ -27,6 +28,8 @@ public class FastTableInfo extends FastBaseInfo { private String comment = ""; private String data; private boolean ignoreCase = true; + private String lock ;//锁定表格,不能*匹配表格合并 + private List> columns = new ArrayList<>(); private FastMapWrap mapColumn; @@ -106,6 +109,15 @@ public class FastTableInfo extends FastBaseInfo { return this; } + public boolean isLock() { + return FastBooleanUtils.formatToBoolean(lock); + } + + public FastTableInfo setLock(boolean lock) { + this.lock = String.valueOf(lock); + return this; + } + public > List getPrimaries() { if (mapPrimary != null) { return new ArrayList((Collection) mapPrimary.getMap().values()); @@ -148,17 +160,22 @@ public class FastTableInfo extends FastBaseInfo { public FastTableInfo merge(FastTableInfo info) { - for (String key : info.keySet()) { - if ("columns".equals(String.valueOf(key))) { - continue; + return merge(info, false); + } + public FastTableInfo merge(FastTableInfo info,boolean onlyColumns) { + if (!onlyColumns) { + for (String key : info.keySet()) { + if ("columns".equals(String.valueOf(key))) { + continue; + } + this.set(key, info.get(key)); + } + if (FastStringUtils.isNotEmpty(info.getFileName())) { + setFileName(info.getFileName()); + } + if (info.getLineNumber() != 0) { + setLineNumber(info.getLineNumber()); } - this.set(key, info.get(key)); - } - if (FastStringUtils.isNotEmpty(info.getFileName())) { - setFileName(info.getFileName()); - } - if (info.getLineNumber() != 0) { - setLineNumber(info.getLineNumber()); } for (FastColumnInfo column : info.getColumns()) { FastColumnInfo existColumn = this.getColumnInfo(column.getName()); diff --git a/src/main/java/com/fastchar/database/operate/FastMySqlDatabaseOperateProvider.java b/src/main/java/com/fastchar/database/operate/FastMySqlDatabaseOperateProvider.java index 81b5977..5c6edb1 100644 --- a/src/main/java/com/fastchar/database/operate/FastMySqlDatabaseOperateProvider.java +++ b/src/main/java/com/fastchar/database/operate/FastMySqlDatabaseOperateProvider.java @@ -361,7 +361,7 @@ public class FastMySqlDatabaseOperateProvider implements IFastDatabaseOperate { fastDb.setLog(true).setDatabase(databaseInfo.getName()).update(deleteIndexStr); } String createIndexSql = String.format("alter table %s add %s index %s (%s%s)", tableName, convertIndex, - indexName, columnName, getIndexMaxLength(getType(columnInfo))); + indexName, columnName, getIndexMaxLength(getLength(columnInfo), getType(columnInfo))); fastDb.setLog(true).setDatabase(databaseInfo.getName()).update(createIndexSql); FastChar.getLog().info(FastMySqlDatabaseOperateProvider.class, FastChar.getLocal().getInfo(FastCharLocal.DB_TABLE_INFO4, databaseInfo.getName(), tableName, columnInfo.getName(), indexName)); @@ -511,7 +511,7 @@ public class FastMySqlDatabaseOperateProvider implements IFastDatabaseOperate { } - public String getIndexMaxLength(String type) { + public String getIndexMaxLength(String length,String type) { if ("fulltext".equals(type.toLowerCase())) { return ""; } @@ -523,7 +523,11 @@ public class FastMySqlDatabaseOperateProvider implements IFastDatabaseOperate { || FastType.isByteArrayType(type)) { return ""; } - return "(155)"; + int numberLength = FastNumberUtils.formatToInt(length); + if (numberLength == 0) { + numberLength = 50; + } + return "(" + Math.min(numberLength, 155) + ")"; } diff --git a/src/main/java/com/fastchar/database/operate/FastOracleDatabaseOperateProvider.java b/src/main/java/com/fastchar/database/operate/FastOracleDatabaseOperateProvider.java index de75e0e..0d100f4 100644 --- a/src/main/java/com/fastchar/database/operate/FastOracleDatabaseOperateProvider.java +++ b/src/main/java/com/fastchar/database/operate/FastOracleDatabaseOperateProvider.java @@ -337,7 +337,7 @@ public class FastOracleDatabaseOperateProvider implements IFastDatabaseOperate { fastDb.setLog(true).setDatabase(databaseInfo.getName()).update(deleteIndexStr); } String createIndexSql = String.format("alter table %s add %s index %s (%s%s)", tableName, convertIndex, - indexName, columnName, getIndexMaxLength(getType(columnInfo))); + indexName, columnName, getIndexMaxLength(getLength(columnInfo), getType(columnInfo))); fastDb.setLog(true).setDatabase(databaseInfo.getName()).update(createIndexSql); FastChar.getLog().info(FastMySqlDatabaseOperateProvider.class, FastChar.getLocal().getInfo(FastCharLocal.DB_TABLE_INFO4, databaseInfo.getName(), tableName, columnInfo.getName(), indexName)); @@ -487,7 +487,7 @@ public class FastOracleDatabaseOperateProvider implements IFastDatabaseOperate { } - public String getIndexMaxLength(String type) { + public String getIndexMaxLength(String length,String type) { if ("fulltext".equals(type.toLowerCase())) { return ""; } @@ -499,7 +499,11 @@ public class FastOracleDatabaseOperateProvider implements IFastDatabaseOperate { || FastType.isByteArrayType(type)) { return ""; } - return "(155)"; + int numberLength = FastNumberUtils.formatToInt(length); + if (numberLength == 0) { + numberLength = 50; + } + return "(" + Math.min(numberLength, 155) + ")"; } } diff --git a/src/main/java/com/fastchar/database/sql/FastSql.java b/src/main/java/com/fastchar/database/sql/FastSql.java index 4b0d285..367239a 100644 --- a/src/main/java/com/fastchar/database/sql/FastSql.java +++ b/src/main/java/com/fastchar/database/sql/FastSql.java @@ -10,6 +10,7 @@ import com.fastchar.exception.FastSqlException; import com.fastchar.interfaces.IFastColumnSecurity; import com.fastchar.local.FastCharLocal; import com.fastchar.utils.FastArrayUtils; +import com.fastchar.utils.FastNumberUtils; import com.fastchar.utils.FastStringUtils; import java.lang.reflect.Array; diff --git a/src/main/java/com/fastchar/extend/ehcache/FastEhCache2Provider.java b/src/main/java/com/fastchar/extend/ehcache/FastEhCache2Provider.java index 10f1004..a34e9aa 100644 --- a/src/main/java/com/fastchar/extend/ehcache/FastEhCache2Provider.java +++ b/src/main/java/com/fastchar/extend/ehcache/FastEhCache2Provider.java @@ -79,12 +79,16 @@ public class FastEhCache2Provider implements IFastCache { @Override public void set(String tag, String key, Object data) { - if (FastStringUtils.isEmpty(tag)||FastStringUtils.isEmpty(key)) { + if (FastStringUtils.isEmpty(tag) || FastStringUtils.isEmpty(key)) { return; } Cache cache = getCache(tag); - Element element = new Element(key, data); - cache.put(element); + if (data == null) { + cache.remove(key); + } else { + Element element = new Element(key, data); + cache.put(element); + } } @Override diff --git a/src/main/java/com/fastchar/extend/ehcache/FastEhCache3Provider.java b/src/main/java/com/fastchar/extend/ehcache/FastEhCache3Provider.java index febe197..379d6cc 100644 --- a/src/main/java/com/fastchar/extend/ehcache/FastEhCache3Provider.java +++ b/src/main/java/com/fastchar/extend/ehcache/FastEhCache3Provider.java @@ -86,7 +86,7 @@ public class FastEhCache3Provider implements IFastCache { @Override public void set(String tag, String key, Object data) { - if (FastStringUtils.isEmpty(tag)||FastStringUtils.isEmpty(key)) { + if (FastStringUtils.isEmpty(tag) || FastStringUtils.isEmpty(key)) { return; } Cache cache = getCache(tag); diff --git a/src/main/java/com/fastchar/extend/redis/FastRedisConfig.java b/src/main/java/com/fastchar/extend/redis/FastRedisConfig.java index f3580e1..d25a59f 100644 --- a/src/main/java/com/fastchar/extend/redis/FastRedisConfig.java +++ b/src/main/java/com/fastchar/extend/redis/FastRedisConfig.java @@ -23,7 +23,9 @@ public class FastRedisConfig implements IFastConfig { private JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); public FastRedisConfig() { - jedisPoolConfig.setSoftMinEvictableIdleTimeMillis(1800000); + jedisPoolConfig.setSoftMinEvictableIdleTimeMillis(60000); + jedisPoolConfig.setMinEvictableIdleTimeMillis(60000); + jedisPoolConfig.setTestWhileIdle(true); } public String getPassword() { diff --git a/src/main/java/com/fastchar/extend/redis/FastRedisNormalProvider.java b/src/main/java/com/fastchar/extend/redis/FastRedisNormalProvider.java index 15273ce..c4867f9 100644 --- a/src/main/java/com/fastchar/extend/redis/FastRedisNormalProvider.java +++ b/src/main/java/com/fastchar/extend/redis/FastRedisNormalProvider.java @@ -72,7 +72,9 @@ public class FastRedisNormalProvider implements IFastCache { return false; } try (Jedis jedis = getJedis()) { - return jedis.exists(wrapKey(tag, key)); + return jedis.get(wrapKey(tag, key)) != null; + } catch (Exception e) { + return false; } } @@ -97,7 +99,11 @@ public class FastRedisNormalProvider implements IFastCache { return; } try (Jedis jedis = getJedis()) { - jedis.set(wrapKey(tag, key).getBytes(), FastSerializeUtils.serialize(data)); + if (data == null) { + jedis.del(wrapKey(tag, key).getBytes()); + }else{ + jedis.set(wrapKey(tag, key).getBytes(), FastSerializeUtils.serialize(data)); + } } } diff --git a/src/main/java/com/fastchar/local/FastCharLocal.java b/src/main/java/com/fastchar/local/FastCharLocal.java index 3aac399..144cbfe 100644 --- a/src/main/java/com/fastchar/local/FastCharLocal.java +++ b/src/main/java/com/fastchar/local/FastCharLocal.java @@ -92,6 +92,14 @@ public final class FastCharLocal { public static final String PARAM_ERROR2 = "Param_Error2"; + /** + * 描述模板: + * 参数{0}值错误! + */ + public static final String PARAM_ERROR3 = "Param_Error3"; + + + /** * 描述模板: * 请求前置的拦截器{0}没有执行response或invoke方法! diff --git a/src/main/java/com/fastchar/local/FastCharLocal_CN.java b/src/main/java/com/fastchar/local/FastCharLocal_CN.java index d25cce3..b184c46 100644 --- a/src/main/java/com/fastchar/local/FastCharLocal_CN.java +++ b/src/main/java/com/fastchar/local/FastCharLocal_CN.java @@ -28,6 +28,7 @@ public class FastCharLocal_CN extends FastCharBaseLocal { //参数相关错误 private final String Param_Error1 = "参数{0}不可为空!"; private final String Param_Error2 = "参数{0}值错误!"; + private final String Param_Error3 = "参数异常!"; private final String Interceptor_Error1 = "请求前置的拦截器{0}没有执行response或invoke方法!"; private final String Interceptor_Error2 = "请求后置的拦截器{0}没有执行response或invoke方法!"; diff --git a/src/main/java/com/fastchar/multipart/FastMultipartRequest.java b/src/main/java/com/fastchar/multipart/FastMultipartRequest.java index bc25666..0c69f7f 100644 --- a/src/main/java/com/fastchar/multipart/FastMultipartRequest.java +++ b/src/main/java/com/fastchar/multipart/FastMultipartRequest.java @@ -4,7 +4,7 @@ import com.fastchar.core.FastChar; import com.fastchar.core.FastFile; import com.fastchar.exception.FastFileException; import com.fastchar.local.FastCharLocal; -import com.fastchar.utils.FastHttpUtils; +import com.fastchar.utils.FastRequestUtils; import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; @@ -56,7 +56,7 @@ public class FastMultipartRequest { MultipartParser parser = new MultipartParser(request, maxPostSize, true, true, encoding); Vector existingValues; if (request.getQueryString() != null) { - Hashtable queryParameters = FastHttpUtils.parseQueryString(request.getQueryString()); + Hashtable queryParameters = FastRequestUtils.parseQueryString(request.getQueryString()); Enumeration queryParameterNames = queryParameters.keys(); while (queryParameterNames.hasMoreElements()) { diff --git a/src/main/java/com/fastchar/out/FastOutError.java b/src/main/java/com/fastchar/out/FastOutError.java index e94176f..7d74c09 100644 --- a/src/main/java/com/fastchar/out/FastOutError.java +++ b/src/main/java/com/fastchar/out/FastOutError.java @@ -28,11 +28,11 @@ public class FastOutError extends FastOut { .replace("\t", "        "); String html = ""; if (getStatus() == 404) { - html = "404
HTTP Status:404
HttpMethod:"+action.getRequestMethod()+"
Message:Http url does not exist!
Description:" + description + "
Powered By:" + POWERED_BY + "
Version:" + FastConstant.FAST_CHAR_VERSION + "
"; + html = "404
HTTP Status:404
HTTP Method:"+action.getRequestMethod()+"
Message:Http url does not exist!
Description:" + description + "
Powered By:" + POWERED_BY + "
Version:" + FastConstant.FAST_CHAR_VERSION + "
"; } else if (getStatus() == 502) { - html = "502
HTTP Status:502
HttpMethod:"+action.getRequestMethod()+"
Message:The Http response is not received!
Description:" + description + "
Powered By:" + POWERED_BY + "
Version:" + FastConstant.FAST_CHAR_VERSION + "
"; + html = "502
HTTP Status:502
HTTP Method:"+action.getRequestMethod()+"
Message:The Http response is not received!
Description:" + description + "
Powered By:" + POWERED_BY + "
Version:" + FastConstant.FAST_CHAR_VERSION + "
"; } else { - html = "" + getStatus() + "
HTTP Status:500
HttpMethod:"+action.getRequestMethod()+"
Message:An error occurred on the server!
Description:" + description + "
Powered By:" + POWERED_BY + "
Version:" + FastConstant.FAST_CHAR_VERSION + "
"; + html = "" + getStatus() + "
HTTP Status:500
HTTP Method:"+action.getRequestMethod()+"
Message:An error occurred on the server!
Description:" + description + "
Powered By:" + POWERED_BY + "
Version:" + FastConstant.FAST_CHAR_VERSION + "
"; } return html; } diff --git a/src/main/java/com/fastchar/out/FastOutFreemarker.java b/src/main/java/com/fastchar/out/FastOutFreemarker.java index 8f160cb..edff2b8 100644 --- a/src/main/java/com/fastchar/out/FastOutFreemarker.java +++ b/src/main/java/com/fastchar/out/FastOutFreemarker.java @@ -1,5 +1,6 @@ package com.fastchar.out; +import com.fastchar.annotation.AFastClassFind; import com.fastchar.core.FastAction; import com.fastchar.core.FastChar; import freemarker.template.Template; @@ -14,6 +15,7 @@ import java.util.Map; /** * 响应Freemarker模板 */ +@AFastClassFind(value = "freemarker.template.Template", url = "https://mvnrepository.com/artifact/org.freemarker/freemarker") public class FastOutFreemarker extends FastOut { public FastOutFreemarker() { diff --git a/src/main/java/com/fastchar/out/FastOutThymeleaf.java b/src/main/java/com/fastchar/out/FastOutThymeleaf.java index 183de8c..6d5f5d0 100644 --- a/src/main/java/com/fastchar/out/FastOutThymeleaf.java +++ b/src/main/java/com/fastchar/out/FastOutThymeleaf.java @@ -1,5 +1,6 @@ package com.fastchar.out; +import com.fastchar.annotation.AFastClassFind; import com.fastchar.core.FastAction; import com.fastchar.core.FastChar; import org.thymeleaf.context.WebContext; @@ -13,6 +14,7 @@ import java.util.Map; /** * 响应输出Thymeleaf模板 */ +@AFastClassFind(value = "org.thymeleaf.context.WebContext", url = "https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf") public class FastOutThymeleaf extends FastOut { public FastOutThymeleaf() { this.contentType = "text/html"; diff --git a/src/main/java/com/fastchar/out/FastOutVelocity.java b/src/main/java/com/fastchar/out/FastOutVelocity.java index 85dd6b8..f708b37 100644 --- a/src/main/java/com/fastchar/out/FastOutVelocity.java +++ b/src/main/java/com/fastchar/out/FastOutVelocity.java @@ -1,5 +1,6 @@ package com.fastchar.out; +import com.fastchar.annotation.AFastClassFind; import com.fastchar.core.FastAction; import com.fastchar.core.FastChar; import com.fastchar.local.FastCharLocal; @@ -16,6 +17,7 @@ import java.util.Map; /** * 响应输出Velocity模板 */ +@AFastClassFind(value = "org.apache.velocity.VelocityContext", url = "https://mvnrepository.com/artifact/org.apache.velocity/velocity-engine-core") public class FastOutVelocity extends FastOut { public FastOutVelocity() { @@ -24,6 +26,7 @@ public class FastOutVelocity extends FastOut { /** * 响应数据 + * * @param action */ @Override @@ -51,15 +54,15 @@ public class FastOutVelocity extends FastOut { context.put(key, finalContext.get(key)); } - for (Enumeration attrs = request.getAttributeNames(); attrs.hasMoreElements();) { + for (Enumeration attrs = request.getAttributeNames(); attrs.hasMoreElements(); ) { String attrName = attrs.nextElement(); context.put(attrName, request.getAttribute(attrName)); } - for (Enumeration attrs = request.getSession().getAttributeNames(); attrs.hasMoreElements();) { + for (Enumeration attrs = request.getSession().getAttributeNames(); attrs.hasMoreElements(); ) { String attrName = attrs.nextElement(); context.put(attrName, request.getSession().getAttribute(attrName)); } - try (PrintWriter writer = response.getWriter()){ + try (PrintWriter writer = response.getWriter()) { template.merge(context, writer); writer.flush(); } diff --git a/src/main/java/com/fastchar/utils/FastDateUtils.java b/src/main/java/com/fastchar/utils/FastDateUtils.java index 9e6cb7f..86ef900 100644 --- a/src/main/java/com/fastchar/utils/FastDateUtils.java +++ b/src/main/java/com/fastchar/utils/FastDateUtils.java @@ -13,7 +13,7 @@ public class FastDateUtils { return parse(date, pattern, null); } - public static Date parse(String date, String pattern, Date defaultValue){ + public static Date parse(String date, String pattern, Date defaultValue) { try { if (FastStringUtils.isEmpty(date)) { return defaultValue; @@ -45,7 +45,6 @@ public class FastDateUtils { } - public static Date addYears(Date date, int amount) { return add(date, 1, amount); } @@ -141,7 +140,7 @@ public class FastDateUtils { return ""; } SimpleDateFormat sdf2 = new SimpleDateFormat(timePattern); - int subDay = diffDay(dateTime, new Date()); + int subDay = (int) diffDay(dateTime, new Date()); switch (subDay) { case 0: return FastChar.getLocal().getInfo(FastCharLocal.DATE_ERROR1) + sdf2.format(dateTime); @@ -153,43 +152,42 @@ public class FastDateUtils { return format(dateTime, "yyyy-MM-dd ") + sdf2.format(dateTime); } - public static int diffDay(Date first, Date two) { + public static double diffDay(Date first, Date two) { try { - return (int) Math.abs( (first.getTime() - two.getTime()) / (60 * 60 * 1000 * 24)); + return Math.abs(first.getTime() - two.getTime()) / (60.0 * 60 * 1000 * 24); } catch (Exception e) { e.printStackTrace(); } return 0; } - public static int diffHour(Date first, Date two) { + public static double diffHour(Date first, Date two) { try { - return (int) Math.abs((first.getTime() - two.getTime()) / (60 * 60 * 1000)); + return Math.abs(first.getTime() - two.getTime()) / (60.0 * 60 * 1000); } catch (Exception e) { e.printStackTrace(); } return 0; } - public static int diffMinute(Date first, Date two) { + public static double diffMinute(Date first, Date two) { try { - return (int) Math.abs((first.getTime() - two.getTime()) / (60 * 1000)); + return Math.abs(first.getTime() - two.getTime()) / (60.0 * 1000); } catch (Exception e) { e.printStackTrace(); } return 0; } - public static int diffSecond(Date first, Date two) { + public static double diffSecond(Date first, Date two) { try { - return (int) Math.abs((first.getTime() - two.getTime()) / (1000)); + return Math.abs(first.getTime() - two.getTime()) / 1000.0; } catch (Exception e) { e.printStackTrace(); } return 0; } - public static int diffYear(Date first, Date two) { try { Calendar firstCal = Calendar.getInstance(); diff --git a/src/main/java/com/fastchar/utils/FastEnumUtils.java b/src/main/java/com/fastchar/utils/FastEnumUtils.java index c4a41e8..ae7193e 100644 --- a/src/main/java/com/fastchar/utils/FastEnumUtils.java +++ b/src/main/java/com/fastchar/utils/FastEnumUtils.java @@ -4,11 +4,11 @@ import java.lang.reflect.Array; import java.util.ArrayList; import java.util.List; -@SuppressWarnings("unchecked") +@SuppressWarnings({"unchecked", "rawtypes"}) public class FastEnumUtils { - public static T formatToEnum(Class clazz, int index){ + public static T formatToEnum(Class clazz, int index) { return formatToEnum(clazz, index, null); } @@ -25,7 +25,7 @@ public class FastEnumUtils { } - public static T formatToEnum(Class clazz, String name){ + public static T formatToEnum(Class clazz, String name) { return formatToEnum(clazz, name, null); } @@ -38,6 +38,9 @@ public class FastEnumUtils { if (index >= 0) { return formatToEnum(clazz, index, defaultValue); } + if (FastNumberUtils.isNumber(name)) { + return null; + } return (T) Enum.valueOf(clazz, name); } catch (Exception e) { e.printStackTrace(); @@ -82,7 +85,12 @@ public class FastEnumUtils { return enumList.toArray((T[]) Array.newInstance(targetClass, enumList.size())); } - public static Integer[] getEnumOrdinals(Class> targetClass, String... keys) { + public static > T[] getEnumValuesOr(Class targetClass, String... keys) { + return getEnumValues(targetClass, keys); + } + + + public static Integer[] getEnumOrdinals(Class> targetClass, String... keys) { List enumList = new ArrayList<>(); Enum[] enumConstants = targetClass.getEnumConstants(); for (Enum enumConstant : enumConstants) { @@ -97,7 +105,7 @@ public class FastEnumUtils { } - public static Integer[] getEnumOrdinalsAnd(Class> targetClass, String... keys) { + public static Integer[] getEnumOrdinalsAnd(Class> targetClass, String... keys) { List enumList = new ArrayList<>(); Enum[] enumConstants = targetClass.getEnumConstants(); for (Enum enumConstant : enumConstants) { @@ -116,4 +124,7 @@ public class FastEnumUtils { return enumList.toArray(new Integer[]{}); } + public static Integer[] getEnumOrdinalsOr(Class> targetClass, String... keys) { + return getEnumOrdinals(targetClass, keys); + } } diff --git a/src/main/java/com/fastchar/utils/FastFileUtils.java b/src/main/java/com/fastchar/utils/FastFileUtils.java index f32c00e..cec78f6 100644 --- a/src/main/java/com/fastchar/utils/FastFileUtils.java +++ b/src/main/java/com/fastchar/utils/FastFileUtils.java @@ -11,6 +11,7 @@ import java.net.URLConnection; import java.nio.channels.FileChannel; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.text.DecimalFormat; import java.util.*; import java.util.regex.Pattern; import java.util.zip.ZipEntry; @@ -76,7 +77,6 @@ public class FastFileUtils { } - public static boolean isImageFileByMimeType(String mimeType) { String[] mimeTypes = new String[]{ "image/bmp", @@ -93,6 +93,7 @@ public class FastFileUtils { return isTargetFileByMimeType(mimeType, mimeTypes); } + public static boolean isMP4FileByMimeType(String mimeType) { String[] extensions = new String[]{ "video/mp4" @@ -121,6 +122,7 @@ public class FastFileUtils { }; return isTargetFileByMimeType(mimeType, extensions); } + public static boolean isExcelFileByMimeType(String mimeType) { String[] extensions = new String[]{ "application/vnd.ms-excel", @@ -128,6 +130,7 @@ public class FastFileUtils { }; return isTargetFileByMimeType(mimeType, extensions); } + public static boolean isWordFileByMimeType(String mimeType) { String[] extensions = new String[]{ "application/msword", @@ -171,7 +174,6 @@ public class FastFileUtils { } - public static FileInputStream openInputStream(File file) throws IOException { if (file.exists()) { if (file.isDirectory()) { @@ -826,7 +828,7 @@ public class FastFileUtils { return urlType; } InputStream inputStream = conn.getInputStream(); - String guessType = HttpURLConnection.guessContentTypeFromStream( new BufferedInputStream(inputStream)); + String guessType = HttpURLConnection.guessContentTypeFromStream(new BufferedInputStream(inputStream)); if (FastStringUtils.isEmpty(guessType)) { return urlType; } @@ -837,8 +839,6 @@ public class FastFileUtils { } - - public static void writeByteArrayToFile(File file, byte[] data) throws IOException { writeByteArrayToFile(file, data, false); } @@ -856,4 +856,21 @@ public class FastFileUtils { } + public static String getFileSize(File file) { + if (file == null || !file.exists()) { + return "0B"; + } + if (file.length() < 1024) { + return file.length() + "B"; + } + long size = (long) Math.ceil(file.length() / 1024.0); + if (size < 1024) { + return size + "KB"; + } else { + double endSize = size / 1024.0; + return FastNumberUtils.formatToDouble(endSize, 1) + "MB"; + } + } + + } diff --git a/src/main/java/com/fastchar/utils/FastLockUtils.java b/src/main/java/com/fastchar/utils/FastLockUtils.java index 0207644..060aa5d 100644 --- a/src/main/java/com/fastchar/utils/FastLockUtils.java +++ b/src/main/java/com/fastchar/utils/FastLockUtils.java @@ -9,7 +9,7 @@ import java.util.concurrent.locks.ReentrantLock; */ public class FastLockUtils { - private static ConcurrentHashMap lockMap = new ConcurrentHashMap(); + private static final ConcurrentHashMap LOCK_MAP = new ConcurrentHashMap(); /** @@ -18,13 +18,12 @@ public class FastLockUtils { * @return ReentrantLock */ public static ReentrantLock getLock(String key) { - ReentrantLock lock = lockMap.get(key); + ReentrantLock lock = LOCK_MAP.get(key); if (lock != null) { return lock; } - lock = new ReentrantLock(); - ReentrantLock previousLock = lockMap.putIfAbsent(key, lock); + ReentrantLock previousLock = LOCK_MAP.putIfAbsent(key, lock); return previousLock == null ? lock : previousLock; } @@ -34,7 +33,7 @@ public class FastLockUtils { * @param key 唯一key */ public static void removeLock(String key) { - lockMap.remove(key); + LOCK_MAP.remove(key); } } diff --git a/src/main/java/com/fastchar/utils/FastHttpUtils.java b/src/main/java/com/fastchar/utils/FastRequestUtils.java similarity index 98% rename from src/main/java/com/fastchar/utils/FastHttpUtils.java rename to src/main/java/com/fastchar/utils/FastRequestUtils.java index 8326860..0cf7d50 100644 --- a/src/main/java/com/fastchar/utils/FastHttpUtils.java +++ b/src/main/java/com/fastchar/utils/FastRequestUtils.java @@ -12,12 +12,12 @@ import java.util.StringTokenizer; * @author 沈建(Janesen) * @date 2020/8/6 17:46 */ -public class FastHttpUtils { +public class FastRequestUtils { private static final String LSTRING_FILE = "javax.servlet.http.LocalStrings"; private static final ResourceBundle L_STRINGS = ResourceBundle.getBundle("javax.servlet.http.LocalStrings"); - public FastHttpUtils() { + public FastRequestUtils() { } public static Hashtable parseQueryString(String s) { diff --git a/src/main/java/com/fastchar/validators/FastBaseValidator.java b/src/main/java/com/fastchar/validators/FastBaseValidator.java index 0d9ef7a..5e90152 100644 --- a/src/main/java/com/fastchar/validators/FastBaseValidator.java +++ b/src/main/java/com/fastchar/validators/FastBaseValidator.java @@ -1,6 +1,7 @@ package com.fastchar.validators; import com.fastchar.interfaces.IFastValidator; +import com.fastchar.local.FastCharLocal; import java.text.MessageFormat; import java.util.*; @@ -9,6 +10,9 @@ import java.util.regex.Pattern; public abstract class FastBaseValidator implements IFastValidator { + private boolean securityMessage; + + @Override public Set pluckKeys(String validator) { Set keys = new HashSet<>(); @@ -23,7 +27,7 @@ public abstract class FastBaseValidator implements IFastValidator { } - protected boolean checkKey(String validator, String key) { + protected boolean checkKey(String validator, String key) { if (validator.contains("#")) { return validator.contains("#" + key); } @@ -31,9 +35,21 @@ public abstract class FastBaseValidator implements IFastValidator { } - protected String formatMessage(String message, String key) { + protected String formatMessage(String message, String key) { + if (isSecurityMessage()) { + return FastCharLocal.PARAM_ERROR3; + } message = message.replaceAll("#.*", ""); return MessageFormat.format(message, key); } + + public boolean isSecurityMessage() { + return securityMessage; + } + + public FastBaseValidator setSecurityMessage(boolean securityMessage) { + this.securityMessage = securityMessage; + return this; + } } diff --git a/src/main/java/com/fastchar/validators/FastNullValidator.java b/src/main/java/com/fastchar/validators/FastNullValidator.java index 9d94ce8..a5e3076 100644 --- a/src/main/java/com/fastchar/validators/FastNullValidator.java +++ b/src/main/java/com/fastchar/validators/FastNullValidator.java @@ -16,7 +16,6 @@ import java.util.regex.Pattern; */ public class FastNullValidator extends FastBaseValidator { - @Override public String validate(String validator, String key, Object value) { if (checkKey(validator, key)) { diff --git a/src/main/java/readme.txt b/src/main/java/readme.txt index 272d7f8..55931fd 100644 --- a/src/main/java/readme.txt +++ b/src/main/java/readme.txt @@ -142,4 +142,13 @@ V1.5.5 3、优化AFastAction和AFastRoute注解,新增拦截器允许配置! 4、优化FastDateUtils类! 5、优化FastSerializeUtils类! -6、优化FastEntity类,新增getColumns方法! \ No newline at end of file +6、优化FastEntity类,新增getColumns方法! +7、优化FastEnumUtils类! +8、新增表格xml配置名称"*"可通用配置所有表格列! +9、新增setParam方法,可以强制设置提交的参数! +10、优化FastFile类! + +V1.5.6 +1、优化FastAction的获取附件方法。 +2、优化FastBaseValidator验证器! +3、优化Jedis读取Redis问题! \ No newline at end of file