package com.qxueyou.scc.base.util;
|
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Set;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import com.qxueyou.scc.base.model.Param;
|
|
public class ParamsUtils {
|
|
/**
|
* »ñÈ¡²éѯÌõ¼þµÄ¹«Ó÷½·¨
|
*
|
* @param request HttpServletRequest
|
* @param strSupportQueryArray ¶¨Òå×Ô¼º¹¦ÄÜÄ£¿éÖ§³Ö²éѯµÄÌõ¼þÊý×鼯ºÏ
|
* @param lstQueryCondition ²éѯÌõ¼þ
|
*/
|
public static void getAllQueryCondition(HttpServletRequest request, String[] strSupportQueryArray,
|
List<Param> lstParams) {
|
Map<String, String[]> mapParams = request.getParameterMap();
|
Set<Map.Entry<String, String[]>> entryseSet = mapParams.entrySet();
|
String strKey = "";
|
String strValue = "";
|
List<String> lstSupportQuery = Arrays.asList(strSupportQueryArray);
|
/**
|
* Ìõ¼þ·ÖΪÒÔϼ¸ÖÖÇé¿ö: 1¡¢¹Ø¼ü×Ö²éѯ 2¡¢µ¥Ñ¡°´Å¥µÄÊý¾Ý×ÖµäÖµ 3¡¢¸´Ñ¡Êý×飬±ÈÈçÀàÐÍ
|
* 4¡¢Ê±¼ä·¶Î§£¬±ÈÈ翪ʼʱ¼äºÍ½áÊøÊ±¼ä 5¡¢Êý×Ö·¶Î§£¬ 6¡¢ÆäËüÀàÐÍ
|
*/
|
for (Map.Entry<String, String[]> entry : entryseSet) {
|
/** »ñÈ¡²ÎÊýÖеļüÖµ¶Ô */
|
strKey = entry.getKey().toString();
|
strValue = entry.getValue()[0];
|
/** ²»Ö§³ÖµÄÌõ¼þ½«»á±»¹ýÂË */
|
if (lstSupportQuery.contains(strKey) && StringUtils.isNotBlank(strValue)) {
|
// È¥¿Õ¸ñ
|
strValue = strValue.trim();
|
if (strValue.matches("^[0-9]*[0-9][0-9]*$")) {// µ¥Ñ¡ Êý×Ö
|
lstParams.add(new Param(strKey, " = ", strValue));
|
} else if (strValue.contains(",")) {// ¸´Ñ¡ Êý×Ö
|
if (strValue.replace(",", "").matches("^-?[0-9]*$")){
|
lstParams.add(new Param(strKey, " in ", strValue ));
|
}
|
} else if (strValue.contains("~")) {// ʱ¼ä·¶Î§
|
|
}else if (strValue.contains("-")) {// Êý×Ö·¶Î§
|
|
} else {// ÆäËü
|
lstParams.add(new Param(strKey, " LIKE ", "%"+strValue+"%"));
|
}
|
}
|
}
|
}
|
|
}
|