通用型 控制层接受参数方法
来源:互联网 发布:c语言100以内的素数 编辑:程序博客网 时间:2024/05/29 17:16
* 获取提交参数并转为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;
}
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;
}
- 通用型 控制层接受参数方法
- 通用型Dao层简单化查询通用方法
- Struts2 接受参数方法
- struts2_8_接受显示层传递的参数
- 创建接受可变数目参数的方法
- Struts2中action接受参数方法
- MyBatis接受参数的两种方法
- 赛码网常见接受参数的方法
- 赛码网常见接受参数的方法
- MFC接受参数的三种方法
- Service层getParameter方法接受字符转换成int类型
- springboot 控制层参数校验插件
- Spring MVC 控制层处理各种参数
- javascript在静态页面上接受参数的方法
- 几种JavaScript接受URL参数的方法
- structs2 接受参数的三种方法(转载)
- require方法接受以下几种参数的传递:
- Struts2的Action接受参数的方法介绍
- AlphaGo 开源项目研究(1)
- 安卓学习之获取QQ登录账户和密码并发送短信
- 写了一个将数据分片的工具,还请大神指正问题(目前只支持list,没搞太复杂)
- T-TPOJ3083
- poj1426
- 通用型 控制层接受参数方法
- Windows上Eclipse远程调用Hadoop2.6.0
- 杭电1392-凸包
- 字符串输入处理
- 扒扒数据库长长知识(下载资源组合看)之05 (多行函数_分组数据_分组过滤)
- [ShareSDK] QuickIntegrater.jar文件各种打不开
- POJ2299 分治法
- Android 开发过程中总计的一些经验教z
- 大话设计模式-简单工厂模式