web获取参数值东西(改善,运用Callback)ITeye - 乐橙lc8

web获取参数值东西(改善,运用Callback)ITeye

2019年03月01日09时20分29秒 | 作者: 博耘 | 标签: 获取,回来,一切办法 | 浏览: 517

public static int getIntValue(HttpServletRequest request, String paramName, int defaultValue, boolean notNull) { return getValue(request, paramName, defaultValue, notNull, new WebUtilsCallback Integer (){ public Integer doAction(String paramValue) { return Integer.valueOf(paramValue); * 一切办法的底层完成 * @param T * @param request * @param paramName * @param defaultValue * @param notNull * @param action * @return * @throws ParamCheckException public static T T getValue(HttpServletRequest request, String paramName, T defaultValue, boolean notNull, WebUtilsCallback T action) throws ParamCheckException { String paramValue = request.getParameter(paramName); checkValue(paramName, paramValue, notNull); if (paramValue != null) { return action.doAction(paramValue); return defaultValue; * 辅佐办法 * @param paramValue * @param notNull private static void checkValue(String paramName, String paramValue, boolean notNull) throws ParamCheckException { if (notNull StringUtils.isBlank(paramValue)) { throw new ParamCheckException("请传递参数:" + paramName); * 获取int值 * @param request * @param paramName * @param defaultValue * @return public static int getIntValue(HttpServletRequest request, String paramName) { return getIntValue(request, paramName, -1, false); * 获取int值 * @param request * @param paramName * @param defaultValue * @return public static int getIntValue(HttpServletRequest request, String paramName, int defaultValue) { return getIntValue(request, paramName, defaultValue, false); * 获取int值 * @param request * @param paramName * @param notNull * @return public static int getIntValue(HttpServletRequest request, String paramName, boolean notNull) { return getIntValue(request, paramName, -1, false); * 回来字符串,默许回来"" * @param request * @param paramName * @return public static String getStringValue(HttpServletRequest request, String paramName) { return getStringValue(request, paramName, false); * 获取String值 * @param request * @param paramName * @param notNull * @return public static String getStringValue(HttpServletRequest request, String paramName, boolean notNull) throws ParamCheckException { return getValue(request, paramName, "", notNull, new WebUtilsCallback String (){ public String doAction(String paramValue) { return paramValue; * 获取double值 * @param request * @param paramName * @param defaultValue * @return public static double getDoubleValue(HttpServletRequest request, String paramName, double defaultValue) { return getDoubleValue(request, paramName, defaultValue, false); * 获取double值 * @param request * @param paramName * @param defaultValue * @return public static double getDoubleValue(HttpServletRequest request, String paramName, double defaultValue, boolean notNull) throws ParamCheckException { return getValue(request, paramName, defaultValue, notNull, new WebUtilsCallback Double (){ public Double doAction(String paramValue) { return Double.valueOf(paramValue); public static double getDoubleValue(HttpServletRequest request, String paramName, boolean notNull) throws ParamCheckException { return getDoubleValue(request, paramName, -1, notNull); * 获取double值 * @param request * @param paramName * @return public static double getDoubleValue(HttpServletRequest request, String paramName) { return getDoubleValue(request, paramName, 0); * 获取boolean值 * @param request * @param paramName * @param defaultValue * @return public static boolean getBooleanValue(HttpServletRequest request, String paramName, boolean defaultValue) { return getBooleanValue(request, paramName, defaultValue, false); * 获取boolean值 * @param request * @param paramName * @param defaultValue * @param notNull * @return public static boolean getBooleanValue(HttpServletRequest request, String paramName, boolean defaultValue, boolean notNull) { return getValue(request, paramName, defaultValue, notNull, new WebUtilsCallback Boolean (){ public Boolean doAction(String paramValue) { if (paramValue.equals("true")) { return true; if (paramValue.equals("false")) { return false; if (paramValue.equals("1")) { return true; if (paramValue.equals("0")) { return false; return false; * 获取long值 * @param request * @param paramName * @param defaultValue * @param notNull * @return public static Long getLongValue(HttpServletRequest request, String paramName, long defaultValue, boolean notNull) { return getValue(request, paramName, defaultValue, notNull, new WebUtilsCallback Long (){ public Long doAction(String paramValue) { return Long.valueOf(paramValue); * 获取long值 * @param request * @param paramName * @param notNull * @return public static Long getLongValue(HttpServletRequest request, String paramName, boolean notNull) { return getLongValue(request, paramName, -1l, notNull); * 获取long值 * @param request * @param paramName * @param defaultValue * @return public static Long getLongValue(HttpServletRequest request, String paramName, long defaultValue) { return getLongValue(request, paramName, defaultValue, false); * 获取boolean值 * @param request * @param paramName * @return public static boolean getBooleanValue(HttpServletRequest request, String paramName) { return getBooleanValue(request, paramName, false);
版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表乐橙lc8立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章