jqGrid查询
这篇文章接着http://blog.csdn.net/dreamstar613/article/details/54615754
其中用到的实体类,表格,生成Pageable类对象的方法是一样的,这里只介绍表格的查询功能
这篇文章下接
html代码
<button type="button" value="查询" id="searchBtn" >查询</button>
js代码
$("#searchBtn").click(function() {
$("#list").jqGrid('setGridParam', {
url : "sensor/search",
datatype:'json',
postData : { //传递查询参数到后台
'search_name' : "name",
'search_code' : "code",
'search_sensorType' : "sensorType",
},
page : 1
}).trigger("reloadGrid"); //重新载入
});
① setGridParam用于设置jqGrid的options选项。返回jqGrid对象
② datatype为指定发送数据的格式;
③ postData为发送请求的数据,以key:value的形式发送,多个参数可以以逗号”,”间隔;
④ page为指定查询结果跳转到第一页;
⑤ trigger(“reloadGrid”);为重新载入jqGrid表格。
java代码
//注意接收参数的方法
@RequiresPermissions("sensor:view")
@ResponseBody
@RequestMapping(value = "/search", method = RequestMethod.POST)
public void getSensorsByCondition(Model model, @RequestParam(value = "page", defaultValue = "1") int pageNumber,
@RequestParam(value = "rows", defaultValue = Constants.PAGE_SIZE + "") int pageSize,
@RequestParam(value = "sord", defaultValue = "desc") String sord,
@RequestParam(value = "sidx", defaultValue = "id") String sidx, ServletRequest request,
ServletResponse response) throws IOException {
/*第1步通过ServletRequest 获取参数*/
String name= request.getParameter("search_name");
String code= request.getParameter("search_code");
String sensorType= request.getParameter("search_sensorType");
/**第2步:生成Pageable类对象*/
Sort sort = new Sort(Direction.fromString(sord), sidx);
Pageable pageable = buildPageRequest(pageNumber, pageSize, sort);
/**第3步:自定义函数,获取符合条件的所有传感器*/
Page<Sensor> sensor = sensorService.findSensorByCondition(name,code,sensorType,pageable);
/**第4步:返回到页面*/
response.setContentType("application/json;charset=UTF-8");
response.getWriter().print(JSON.toJSONString(sensor, SerializerFeature.DisableCircularReferenceDetect));
}
最后函数findSensorByCondition的实现方法可以参考
http://blog.csdn.net/dreamstar613/article/details/53582578
最后一段把查询的内容分页返回
findSensorByCondition(name,code,sensorType,pageable);