jeecg自定义CriteriaQuery查询组装

Posted baixiuhua

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jeecg自定义CriteriaQuery查询组装相关的知识,希望对你有一定的参考价值。

@RequestMapping(params = "datagrid")
    public void datagrid(TbTendUserEntity tbTendUser, HttpServletRequest request, HttpServletResponse response,
            DataGrid dataGrid) {
        
        CriteriaQuery cq = new CriteriaQuery(TbTendUserEntity.class, dataGrid);
        // 查询条件组装器
        org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, tbTendUser, request.getParameterMap());
        try {
            String sql1=" SELECT t.id,t.create_name createName,t.create_by createBy,t.create_date createDate, " + 
                    "t.update_name updateName,t.update_by updateBy,t.update_date updateDate,t.sys_org_code sysOrgCode, " + 
                    "t.sys_company_code sysCompanyCode,t.bpm_status bpmStatus,t.tend_user_id tendUserId,t.user_name userName, " + 
                    "t.pass_word passWord,t.begin_date beginDate,t.end_date endDate,t.id_card_num idCardNum,t.fingerprint_data fingerprintData, " + 
                    "t.photograph_data photographData,t.sex,t.age,t.duty,t.`status`,t.will1,t.will2,t.will3,t.user_real userReal, " + 
                    "t.schedule_status scheduleStatus,t.group_status groupStatus,t.domicile_location domicileLocation,t.work_location workLocation " + 
                    "FROM tb_tend_user t where 1=1 ";
            String sql2=" SELECT COUNT(1) FROM tb_tend_user t where 1=1 ";
            if(StringUtil.isNotEmpty(tbTendUser.getDomicileLocation())) {//户籍所在地过滤
                sql1+="and (domicile_location <> ‘"+tbTendUser.getDomicileLocation()+"‘ or domicile_location is null) ";
                sql2+="and (domicile_location <> ‘"+tbTendUser.getDomicileLocation()+"‘ or domicile_location is null) ";
            }
            if(StringUtil.isNotEmpty(tbTendUser.getWorkLocation())) {//工作地过滤
                sql1+="and (work_location <> ‘"+tbTendUser.getWorkLocation()+"‘ or work_location is null) ";
                sql2+="and (work_location <> ‘"+tbTendUser.getWorkLocation()+"‘ or work_location is null) ";
            }
            if(StringUtil.isNotEmpty(tbTendUser.getGroupStatus())) {//分组状态
                sql1+="and (group_status = ‘"+tbTendUser.getGroupStatus()+"‘ or group_status is null) ";
                sql2+="and (group_status = ‘"+tbTendUser.getGroupStatus()+"‘ or group_status is null) ";
            }
            if(StringUtil.isNotEmpty(tbTendUser.getUserReal())) {//姓名
                sql1+="and (user_real = ‘"+tbTendUser.getUserReal()+"‘) ";
                sql2+="and (user_real = ‘"+tbTendUser.getUserReal()+"‘) ";
            }
            /*获取总数,用于分页使用*/
            long countMwo = systemService.getCountForJdbc(sql2);
            /*转换为 int 整形*/
            int allCounts = (int)countMwo;
            
            int pageSize = cq.getPageSize();/*每页显示数*/
            int curPageNO = PagerUtil.getcurPageNo(allCounts, cq.getCurPage(),pageSize);/*当前页*/
            
            /*获取数据列表,参数一:查询的sql、参数二三:当前页码、数据总数*/
            List<Map<String, Object>> listMwo=systemService.findForJdbc(sql1, curPageNO, pageSize);
            
            cq.getDataGrid().setResults(listMwo);
            cq.getDataGrid().setTotal(allCounts);
            
        } catch (Exception e) {
            throw new BusinessException(e.getMessage());
        }
        TagUtil.datagrid(response, dataGrid);
    }

以上是关于jeecg自定义CriteriaQuery查询组装的主要内容,如果未能解决你的问题,请参考以下文章

JEECG中datagrid方法自定义查询条件

jeecg 扩展封装查询条件 时间段查询

JEECG技术博文JEECG简单实例讲解自定义表单功能

JEECG中修改时间相关自定义定时器

jeecg自定义编辑页面

Jeecg-Boot 表单之自定义按钮和Sql增强