struts2+easyui实现根据条件检索信息



根据不同条件或组合条件检索信息是很常用的需求,下面将在struts2+easyui的datagrid显示列表信息的前提下实现单条件或组合条件检索信息。 

一、编辑控制器 
Java代码   收藏代码
  1. //显示员工信息列表  
  2.     public void listEmpl() throws IOException{  
  3.            //设置响应格式  
  4.            resp.setCharacterEncoding("UTF-8");  
  5.              
  6.            //获取当前用户的id  
  7.            Empl currEmpl = (Empl) session.getAttribute("emp1");  
  8.            int currId = currEmpl.getEid();  
  9.              
  10.            //当前页  
  11.            int offset=!"".equals(req.getParameter("page"))&&null!=(req.getParameter("page"))?Integer.parseInt(req.getParameter("page")):1;  
  12.              
  13.            //查询条件:员工名称、职位、部门名称、状态  
  14.            Pager<Object[]> pager=empService.search(empl,ajob,adept,ajobStatus,currId,offset);  
  15.               
  16.            //将数据存入list中,它存入的是map,这样在easyui的datagrid才能以键值对的形式获取到具体的数据  
  17.            List<Map<String,String>> list = new ArrayList<>();  
  18.            Map<String,String> map0 = null;  
  19.            for (Object[] e : pager.getList()) {  
  20.                map0=new HashMap<String, String>();  
  21.                //在datagrid中显示的数据  
  22.                map0.put("eid", String.valueOf(e[0]));  
  23.                map0.put("ename", String.valueOf(e[1]));  
  24.                map0.put("birthday", String.valueOf(e[3]));  
  25.                map0.put("hiredate", String.valueOf(e[6]));  
  26.                map0.put("jname", String.valueOf(e[5]));//职位  
  27.                map0.put("dname", String.valueOf(e[4]));  
  28.                map0.put("status", String.valueOf(e[7]));  
  29.                //在datagrid中隐藏的数据(部门编号、职位编号、在职状态编号)  
  30.                map0.put("did", String.valueOf(e[8]));  
  31.                map0.put("jid", String.valueOf(e[9]));  
  32.                map0.put("jsid", String.valueOf(e[10]));  
  33.                list.add(map0);  
  34.            }  
  35.              
  36.            //设置总行数,行数据。  
  37.            Map<String,Object> map = new HashMap<String, Object>();  
  38.            map.put("total", pager.getSumRows());  
  39.            map.put("rows", list);  
  40.              
  41.            //将map转换为json格式  
  42.            String s = JSON.toJSONString(map);  
  43.            PrintWriter out = resp.getWriter();  
  44.            out.println(s);  
  45.     }  


二、编辑模型层 
1.service 
Java代码   收藏代码
  1. public Pager<Object[]> search(Empl empl,Job job,Dept dept,JobStatus jobStatus,int currId,int offset){  
  2.         return emplDaoImpl.search(empl,job,dept,jobStatus,currId,offset);  
  3.     }  

2.emplDaoImpl 
Java代码   收藏代码
  1. //分页查询员工信息  
  2.     public Pager<Object[]> search(Empl empl,Job job,Dept dept,JobStatus jobStatus,int currId,int offset) {  
  3.         List<Object> params=new ArrayList<>();  
  4.         StringBuffer sql=new StringBuffer();  
  5.         sql.append("SELECT A.*, ROWNUM RN from (select e.eid,e.ename,e.sex,to_char(e.birthday,'yyyy-mm-dd'),d.dname,j.jname,to_char(e.hiredate,'yyyy-mm-dd'),js.status, d.did,j.jid,js.jsid "  
  6.                 + "from t_empl e,t_dept d,t_job j,t_jobstatus js "  
  7.                 + "where e.deptno=d.did and e.job=j.jid and e.status=js.jsid  and e.eid!="+currId+" and j.jname!='董事长'");  
  8.         if(empl!=null){  
  9.             if(empl.getEname()!=null&&!"".equals(empl.getEname().trim())){  
  10.                 sql.append(" and e.ename like ?");  
  11.                 params.add("%"+empl.getEname()+"%");  
  12.             }  
  13.         }  
  14.         if(job!=null){  
  15.             if(job.getJname()!=null&&!"请选择该用户所属职位".equals(job.getJname().trim())){  
  16.                 sql.append(" and j.jname like ?");  
  17.                 params.add("%"+job.getJname()+"%");  
  18.             }  
  19.         }  
  20.         if(dept!=null){  
  21.             if(dept.getDname()!=null&&!"请选择该用户所属部门".equals(dept.getDname().trim())){  
  22.                 sql.append(" and d.dname like ?");  
  23.                 params.add("%"+dept.getDname()+"%");  
  24.             }  
  25.         }  
  26.         if(jobStatus!=null){  
  27.             if(jobStatus.getStatus()!=null&&!"请选择该用户所属状态".equals(jobStatus.getStatus().trim())){  
  28.                 sql.append(" and js.status like ?");  
  29.                 params.add("%"+jobStatus.getStatus()+"%");  
  30.             }  
  31.         }  
  32.         sql.append(" order by eid) A ");  
  33.           
  34.         return listAsObjectArrayHaveParam(sql.toString(), offset, 10, params.toArray());  
  35.     }  

伦理片 http://www.dotdy.com/
三、编辑jsp 
Html代码   收藏代码
  1. <head>  
  2. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  3. <!-- 1.页面引入样式 -->  
  4. <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/jquery-easyui-1.4.2/themes/metro/easyui.css">  
  5. <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/jquery-easyui-1.4.2/themes/icon.css">  
  6. <!-- 2.页面引入脚本 -->  
  7. <script type="text/javascript"src="${pageContext.request.contextPath }/jquery-easyui-1.4.2/jquery-1.8.0.min.js"></script>  
  8. <script type="text/javascript"src="${pageContext.request.contextPath }/jquery-easyui-1.4.2/jquery.easyui.min.js"></script>  
  9. <script type="text/javascript"src="${pageContext.request.contextPath }/jquery-easyui-1.4.2/datagrid-detailview.js"></script>  
  10. <script type="text/javascript" src="${pageContext.request.contextPath }/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>   
  11. <!-- 3.页面引入自定义脚本 -->  
  12. <script type="text/javascript" src="${pageContext.request.contextPath }/js/userManager.js" ></script>  
  13. <script type="text/javascript" src="${pageContext.request.contextPath }/js/validate.js" ></script>  
  14. <!-- 4.页面引入其他脚本 -->  
  15. <link href="${pageContext.request.contextPath }/myDatePicker_2.2/datePicker.css" type="text/css" rel="stylesheet" />  
  16. <script type="text/javascript" src="${pageContext.request.contextPath }/myDatePicker_2.2/jquery.datePicker-min.js"></script>  
  17.   
  18. <title>用户管理</title>  
  19. <style type="text/css">  
  20.   
  21. .dv-label{  
  22.     font-weight: bolder;  
  23.     color:#15428B;  
  24. }  
  25. /*datagrid行高设置*/  
  26. .datagrid-btable tr{  
  27.     height:30px;     
  28. }  
  29. </style>  
  30. ...  
  31. <form id="searchForm">  
  32.                     员工姓名:<input type="text" id="ename" name="empl.ename"/>    
  33.                     职位:<select id="job" name="ajob.eid" class="easyui-combobox" panelHeight="auto" >  
  34.                             <option  value="-1">请选择该用户所属职位</option>  
  35.                             <c:forEach items="${job }" var="v">  
  36.                                 <option value="${v.jid}">${v.jname }</option>  
  37.                             </c:forEach>  
  38.                          </select>    
  39.                     所属部门:<select id="dept" name="adept.did"  class="easyui-combobox" panelHeight="auto" >  
  40.                                 <option  value="-1">请选择该用户所属部门</option>  
  41.                                 <c:forEach items="${dept }" var="v">  
  42.                                     <option value="${v.did }">${v.dname }</option>  
  43.                                 </c:forEach>  
  44.                             </select>    
  45.                     员工状态:<select id="jobStatus" name="ajobStatus.jsid" class="easyui-combobox" panelHeight="auto" >  
  46.                                 <option selected value="-1">请选择该用户所属状态</option>  
  47.                                 <c:forEach items="${jobStatus }" var="v">  
  48.                                     <option value="${v.jsid }">${v.status }</option>  
  49.                                 </c:forEach>  
  50.                             </select>        
  51.                <a id="search" href="#" class="easyui-linkbutton" iconCls="icon-ok">筛选</a>  
  52.            </form>   
  53. ...  


四、编辑js 
Js代码   收藏代码
  1. //搜索的点击事件  
  2.     $('#search').bind('click',function(){  
  3.         //重载datagrid.注:1.会向控制器发送请求,请求地址为在datagrid指定的url。2.参数:向控制器发送请求时包含的数据,struts2会将它们封装成相应bean对象。  
  4.         $('#dg').datagrid('load',   
  5.                 {  
  6.                   'empl.ename':$('#ename').val(),  
  7.                   'ajob.jname':$('#job').combobox('getText'),  
  8.                   'adept.dname':$('#dept').combobox('getText'),  
  9.                   'ajobStatus.status':$('#jobStatus').combobox('getText')  
  10.                 }  
  11.         );  
  12.           
  13.         //清空、还原搜索表单中的默认选项  
  14.         $('#ename').val('')  
  15.         $('#job').combobox('setValue','-1')  
  16.         $('#dept').combobox('setValue','-1')  
  17.         $('#jobStatus').combobox('setValue','-1')  
  18.     })  


大功告成,效果如下: 





基于bert实现关系三元组抽取python源码+数据集+项目说明.zip基于bert实现关系三元组抽取python源码+数据集+项目说明.zip基于bert实现关系三元组抽取python源码+数据集+项目说明.zip基于bert实现关系三元组抽取python源码+数据集+项目说明.zip基于bert实现关系三元组抽取python源码+数据集+项目说明.zip 个人大四的毕业设计、课程设计、作业、经导师指导并认可通过的高分设计项目,评审平均分达96.5分。主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者,也可作为课程设计、期末大作业。 [资源说明] 不懂运行,下载完可以私聊问,可远程教学 该资源内项目源码是个人的毕设或者课设、作业,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96.5分,放心下载使用! 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),供学习参考。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值