}
public Integer getParaToInt(String name, Integer defaultValue) {
return toInt(getHttpServletRequest().getParameter(name), defaultValue);
}
/**
* Returns the value of a request parameter as a String, or default value if the parameter does not exist.
* @param name a String specifying the name of the parameter
* @param defaultValue a String value be returned when the value of parameter is null
* @return a String representing the single value of the parameter
*/
public String getPara(String name) {
String result = getHttpServletRequest().getParameter(name);
return result != null && !"".equals(result) ? result : "";
}
//--------------------------------bootstrap table--------------------------------
public static int PAGE_SIZE=10; //默认每页条数
public static final String LIMIT="limit"; //分页条数
public static final String OFFSET="offset"; //从第offset条开始查询
public static final String SEARCH="search"; //查询关键字
public static final String SORT="sort"; //排序字段
public static final String ORDER="order"; //排序类型 asc desc
public static final String PAGENUM="pagenum"; //页码
public static final String PAGESIZE="pagesize"; //页数
/**
* 获取提交参数并转为map(分页)
* @return
*/
public Map<String, Object> getPageInfo(){
Map<String, Object> map =new HashMap<String, Object>();
Map<String, String[]> parasMap = getHttpServletRequest().getParameterMap();
for (Entry<String, String[]> e : parasMap.entrySet()) {
String key = e.getKey();
String[] values = e.getValue();
try {
// Object value = Converter.convert(colType, paraValue != null ? paraValue[0] : null);
Object value = values[0]!= null?values[0]:null;
map.put(key, value);
} catch (Exception ex) {
ex.printStackTrace();
}
}
//获取页码信息
// map.put(PAGESIZE,getPageSize());
// map.put(PAGENUM,getPageNumber());
int firstRow=getParaToInt(OFFSET,0);
int lastRow=firstRow+getPageSize();
map.put("firstRow",firstRow);
map.put("lastRow",lastRow);
String sort=getPara(SORT,"");
//获取关键字信息
map.put(SEARCH,getPara(SEARCH));
//获取排序信息
if(sort!=null&&!"".equals(sort)){
map.put("orderBy", "order by "+sort+" "+getPara(ORDER,""));
}
return map;
}
/**
* 获取每页条数
* @param name
* @return
*/
public Integer getPageSize() {
int pageSize=getParaToInt(LIMIT,PAGE_SIZE);
return pageSize;
}
/**
* 获取当前页码
* @param name
* @return
*/
public Integer getPageNumber() {
int pageSize=getPageSize();
int offset=getParaToInt(OFFSET,0);
int pageNumber=offset/pageSize;
return pageNumber;
}
/**
* 获取排序信息
* @param name
* @return
*/
public OrderPart getOrderPart() {
return OrderPart.newInstance().and(getPara(SORT),getPara(ORDER));
}
private static Integer toInt(String value, Integer defaultValue) {
if (value == null || "".equals(value.trim()))
return defaultValue;
if (value.startsWith("N") || value.startsWith("n"))
return -Integer.parseInt(value.substring(1));
return Integer.parseInt(value);
}
/**
* Returns the value of a request parameter and convert to Integer with a default value if it is null.
* @param name a String specifying the name of the parameter
* @return a Integer representing the single value of the parameter
*/
public Integer getParaToInt(String name, Integer defaultValue) {
return toInt(getHttpServletRequest().getParameter(name), defaultValue);
}
/**
* Returns the value of a request parameter as a String, or default value if the parameter does not exist.
* @param name a String specifying the name of the parameter
* @param defaultValue a String value be returned when the value of parameter is null
* @return a String representing the single value of the parameter
*/
public String getPara(String name) {
String result = getHttpServletRequest().getParameter(name);
return result != null && !"".equals(result) ? result : "";
}
/**
* Returns the value of a request parameter as a String, or default value if the parameter does not exist.
* @param name a String specifying the name of the parameter
* @param defaultValue a String value be returned when the value of parameter is null
* @return a String representing the single value of the parameter
*/
public String getPara(String name, String defaultValue) {
String result = getHttpServletRequest().getParameter(name);
return result != null && !"".equals(result) ? result : defaultValue;
}