博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jqgrid查找
阅读量:6763 次
发布时间:2019-06-26

本文共 3456 字,大约阅读时间需要 11 分钟。

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("utf-8"); //这里不设置编码会有乱码response.setContentType("text/html;charset=utf-8");response.setHeader("Cache-Control", "no-cache"); int rows = Integer.valueOf(request.getParameter("rows")); //每页中显示的记录行数int page = Integer.valueOf(request.getParameter("page")); //当前的页码String sord = request.getParameter("sord");//排序方式String sidx = request.getParameter("sidx");//排序列名Boolean search =(request.getParameter("_search").equals("true"))?true:false;//是否用于查询请求List
allList = new LinkedList
();//返回结果集String keys="";//查询条件字符串if(search){keys=" WHERE ";String filters = request.getParameter("filters");//具体的条件System.out.println(filters);//传入数据的格式是类似这样的:"{"groupOp":"AND","rules":[{"field":"id","op":"eq","data":"1"},{"field":"type","op":"ew","data":"2"}]}"JSONObject jsonObject = JSONObject.fromObject(filters);String groupOp = "AND";//每个规则之间的关系(and/or)if (jsonObject.getString("groupOp")!=null&&!"".equals(jsonObject.getString("groupOp"))) {if (jsonObject.getString("groupOp").equals("OR")) {groupOp = "OR";}}JSONArray rulesjson = jsonObject.getJSONArray("rules");//遍历每个条件for (int z=0; z < rulesjson.size(); z++) {Object t = rulesjson.get(z);JSONObject rulejson = JSONObject.fromObject(t);String field = rulejson.getString("field");String op = rulejson.getString("op");String data = rulejson.getString("data");String string = "";//用于存储单个条件sql语句片段//开始转化为sql语句switch (op) {case "eq"://相等string=" = '"+data+"' ";break;case "ne"://不相等string=" <> '"+data+"' ";break;case "li"://小于string=" < '"+data+"' ";break;case"le"://小于等于string=" <= '"+data+"' ";break;case"gt"://大于string=" > '"+data+"' ";break;case "ge"://大于等于string=" >= '"+data+"' ";break;case "bw"://在...之间{if (data.split(",").length==2) {string=" BETWEEN '"+data.split(",")[0]+"' AND '"+data.split(",")[1]+"' ";}else {string=" = '"+data+"' ";//数据错误时处理}} break;case"bn"://不在...之间{if (data.split(",").length==2) {string=" NOT BETWEEN '"+data.split(",")[0]+"' AND '"+data.split(",")[1]+"' ";}else {string=" <> '"+data+"' ";//数据错误时处理}}break;case"ew"://以...结束string=" LIKE '%"+data+"' ";break;case "en"://不以...结束string=" NOT LIKE '%"+data+"' ";break;case "cn"://包含string=" LIKE '%"+data+"%' ";break;case "nc"://不包含string=" NOT LIKE '%"+data+"%' ";break;case "in"://在{string=" IN ( ";String[] datas = data.split(",");for (int i = 0; i < datas.length; i++) {string+= " '"+datas[i]+"' ";if (i!=datas.length-1) {string += ",";}else {string += " ) ";}}}break;case "ni"://不在{string=" NOT IN ( ";String[] datas = data.split(",");for (int i = 0; i < datas.length; i++) {string+= " '"+datas[i]+"' ";if (i!=datas.length-1) {string += ",";}else {string += " ) ";}}}break;default:op=null;System.out.println("OP符号错误");//OP符号错误}if (op!=null) {if (z==rulesjson.size()-1) {keys+=" "+field+" "+string +" ";}else {keys+=" "+field+" "+string +" "+groupOp+" ";}}}}//升降序SQL语句转换if (sidx!=null&&!"".equals(sidx)) {System.out.println(sidx);keys += " ORDER BY " + sidx;System.out.println("sord="+sord);if (!sord.equals("asc")) {keys += " DESC ";}}allList = Factory.getDemoDAOInstance().doSearch(keys);//分页部分int total=0; total=(allList.size()%rows==0)?(allList.size()/rows):((allList.size()/rows)+1);int j = 0;int m = (page-1)*rows;int n = (page-1)*rows+rows;JSONArray jArray = new JSONArray();for (j=m; j

转自脚本之家

转载于:https://www.cnblogs.com/bingoing/p/5636882.html

你可能感兴趣的文章
Scala的bounds
查看>>
Zookeeper之——关于Zookeeper的那些事
查看>>
LAMP- CentOS 7平台三机FastCGI模型
查看>>
解决docker pull镜像速度慢的问题
查看>>
扒一扒JVM的垃圾回收机制,下次面试你准备好了吗
查看>>
七周二次课(5月7日)
查看>>
我的友情链接
查看>>
MySQL删除idb文件引发的思考
查看>>
SQL Server 2012 管理新特性:AlwaysOn 可用性组
查看>>
lamp-安装脚本-修订版1
查看>>
linux 之lvm 逻辑卷管理详解
查看>>
什么是序列化?为什么要序列化?
查看>>
iOS设置frame的简单方法
查看>>
复合型序列的分解预测
查看>>
CentOS 6.3 安装配置drbd8.3.13+heartbeat3.0.4
查看>>
linux 下动态链接库的制作与使用
查看>>
关于hadoop配置hosts文件的问题
查看>>
计算机操作系统发展历史
查看>>
scp
查看>>
java项目中logger一般使用 static final
查看>>