2 changed files with 113 additions and 0 deletions
@ -0,0 +1,66 @@ |
|||
package cn.chjyj.szwh.utils.pay; |
|||
|
|||
import java.net.URLDecoder; |
|||
import java.util.Map; |
|||
import java.util.Set; |
|||
import java.util.TreeMap; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
|
|||
import com.alibaba.fastjson2.JSONObject; |
|||
|
|||
public class HttpUtil { |
|||
|
|||
private static final String UTF_8 = "utf-8"; |
|||
|
|||
/** |
|||
* 映射为map |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
public static JSONObject getParamTreeMap_Utf8(HttpServletRequest request) { |
|||
Map map = request.getParameterMap(); |
|||
JSONObject jsonObject = new JSONObject(); |
|||
Set keys = map.keySet(); |
|||
for (Object key : keys) { |
|||
try { |
|||
jsonObject.put(key.toString(), getString_UrlDecode_UTF8(request, key.toString())); |
|||
} catch (Exception e) { |
|||
jsonObject.put(key.toString(), ""); |
|||
} |
|||
} |
|||
return jsonObject; |
|||
} |
|||
|
|||
/** |
|||
* 根据参数名从HttpRequest中获取String类型的参数值,无值则返回"" . |
|||
* |
|||
* @param key |
|||
* . |
|||
* @return String . |
|||
*/ |
|||
public static String getString_UrlDecode_UTF8(HttpServletRequest request, String key) { |
|||
try { |
|||
return URLDecoder.decode(getString(request, key), UTF_8); |
|||
} catch (Exception e) { |
|||
return ""; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 根据参数名从HttpRequest中获取String类型的参数值,无值则返回null . |
|||
* |
|||
* @param key |
|||
* . |
|||
* @return String or null . |
|||
*/ |
|||
public static String getString(HttpServletRequest request, String key) { |
|||
String param = request.getParameter(key); |
|||
if (StringUtil.isEmpty(param)) { |
|||
return param; |
|||
} else { |
|||
return param.trim(); |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
package cn.chjyj.szwh.utils.pay; |
|||
|
|||
import java.text.SimpleDateFormat; |
|||
import java.util.Date; |
|||
import java.util.regex.Matcher; |
|||
import java.util.regex.Pattern; |
|||
|
|||
public class StringUtil { |
|||
|
|||
public static boolean isEmpty(String str){ |
|||
if(null == str || "".equals(str) || "".equals(str.trim())){ |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
public static boolean isEmail(String email){ |
|||
if(isEmpty(email))return false; |
|||
boolean bool = true; |
|||
String regex = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"; |
|||
Pattern pattern = Pattern.compile(regex); |
|||
Matcher matcher = pattern.matcher(email); |
|||
if(!matcher.matches()){ |
|||
bool = false; |
|||
} |
|||
return bool; |
|||
} |
|||
|
|||
public static boolean isNumeric(String number){ |
|||
if(number.matches("//d*")){ |
|||
return true; |
|||
}else{ |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
public static String getDateFormat(String format) { |
|||
Date date = new Date(); |
|||
return getTimestamp(date, format); |
|||
} |
|||
|
|||
public static String getTimestamp(Date date, String format) { |
|||
SimpleDateFormat sdf = new SimpleDateFormat(format); |
|||
String str = sdf.format(date); |
|||
return str; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue