zoukankan      html  css  js  c++  java
  • easyUI 条件查询 跟分页数据展示写在了一起的

    js方法  讲form表单的数据 序列化返回obj对象     调用dataGrid的  load 方法

    //查询按钮
    $('#search').click(function(){
    $('#chance').datagrid('load',serializeForm($('#searchForm')));
    });

    //js序列化表单返回 obj 对象
    function serializeForm(form){
    var obj = { };
    $.each(form.serializeArray(),function(index){
    if(obj[this['name']]){
    obj[this['name']] = obj[this['name']] + ','+this['value'];
    }else {
    obj[this['name']] =this['value'];
    }
    });
    return obj;
    }

    =========================Action层  方法跟数据展示一个方法体内=====================

    //页面显示+条件查询
    public void chanceList() throws Exception{
    int pageNo = Integer.parseInt(ServletActionContext.getRequest().getParameter("page"));//当前页
    int pageSize = Integer.parseInt(ServletActionContext.getRequest().getParameter("rows"));//每页有几条记录
    //条件查询传递的参数
    String khname = ServletActionContext.getRequest().getParameter("khname") == null ?"":ServletActionContext.getRequest().getParameter("khname");
    String createtime = ServletActionContext.getRequest().getParameter("createtime")== null ?"":ServletActionContext.getRequest().getParameter("createtime");
    String contact = ServletActionContext.getRequest().getParameter("contact")== null ?"":ServletActionContext.getRequest().getParameter("contact");
    String telephone = ServletActionContext.getRequest().getParameter("telephone")== null ?"":ServletActionContext.getRequest().getParameter("telephone");
    //将查询条件放到Map中
    Map<String ,Object> m = new HashMap<String ,Object>();
    m.put("khname", khname);
    m.put("createtime", createtime);
    m.put("contact", contact);
    m.put("telephone", telephone);
    //页面数据显示
    //int total = chanceService.chanceCount();
    //System.out.println(total);
    List<Chance> chanceList = chanceService.findByPage(pageNo, pageSize,m);
    List<Chance> list = chanceService.findAll();
    String json = "{"total":"+list.size()+","rows":"+JSONArray.fromObject(chanceList).toString()+"}";
    ServletActionContext.getResponse().getWriter().write(json);
    }

    ==================Dao层  根据PageSize PageNo Map 参数查数据拼接SQL ==================================

    //分页查询数据+ 条件查询
    public List<Chance> findByPage(int pageNo,int pageSize,Map<String,Object> m){
    String hql = " from Chance where 1 =1 ";
    Set<Entry<String, Object>> set = m.entrySet();
    Iterator io = set.iterator();
    while(io.hasNext()){
    Map.Entry<String, Object> me = (Map.Entry<String, Object>) io.next();
    if("khname".equals(me.getKey())&& !"".equals(me.getValue())){
    hql +=" and "+me.getKey()+" like '%"+me.getValue()+"%' ";
    }
    if("createtime".equals(me.getKey())&& !"".equals(me.getValue())){
    hql +=" and "+me.getKey()+" = '"+me.getValue()+"'";
    }
    if("contact".equals(me.getKey())&& !"".equals(me.getValue())){
    hql +=" and "+me.getKey()+" like '%"+me.getValue()+"%'";
    }
    if("telephone".equals(me.getKey())&& !"".equals(me.getValue())){
    hql +=" and "+me.getKey()+" ='"+me.getValue()+"' ";
    }
    }
    Query query = this.getSession().createQuery(hql);
    //Hibernate数据库分页算法
    query.setFirstResult((pageNo - 1) * pageSize);
    query.setMaxResults(pageSize);
    return query.list();
    }

  • 相关阅读:
    LeetCode 链表题总结
    分布式系统 MIT 6.824 Lab 1: MapReduce 准备
    Consul 入门(二)
    Consul 入门
    IDEA批量修改变量快捷键
    Spring源码解析-JdbcTemplate
    SpringMVC源码解析-HTTP请求处理和分发
    SpringMVC源码解析-DispatcherServlet启动流程和初始化
    发现一个网站可以看英文版的harry potter小说,好东西分享一下哈
    TypeSrcript如何引入第三方库 如果加d.ts以及async await如何使用 demo,只有代码,文字后续补充
  • 原文地址:https://www.cnblogs.com/liuliang-wifi/p/4508281.html
Copyright © 2011-2022 走看看