3、jeecg 笔记之 模糊查询

博客地址:http://www.cnblogs.com/niceyoo

1、前言

jeecg 考虑到默认模糊查询的话,会增加系统压力,导致查询慢,本来系统就挺那啥的...

2、方式一之实体赋值

实体重新赋值查询,用 * %% * 实现,我们知道 sql 中通常使用 % 去模糊查询的,jeecg 中 datagrid 方法里判断实体属性是否为空,不为空则重新赋值即可。

至于 是不是用 % ,使用几个 % 根据自己情况选择,比如: "*" + xxx + "*" 、"*%" + xxx + "*"

3、方式二之cq实现

将值赋值给 CriteriaQuery 

复制代码
    @RequestMapping(params = "datagrid")
    public void datagrid(BaseDevice device, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {   
        
        String devicecode = device.getDevicecode();
        String devicename = device.getDevicename();
        String status = device.getStatus();
        
        CriteriaQuery cq = new CriteriaQuery(BaseDevice.class,dataGrid);
        if(StringUtils.isNotEmpty(devicecode)){
            cq.add(Restrictions.sqlRestriction("devicecode like '%" + devicecode + "%'"));
        }
        if(StringUtils.isNotEmpty(devicename)){
            cq.add(Restrictions.sqlRestriction("devicename like '%" + devicename + "%'"));
        }
        if(StringUtils.isNotEmpty(status)){
            cq.add(Restrictions.sqlRestriction("status like '%" + status + "%'"));
        }
        
        this.systemService.getDataGridReturn(cq, true);
        TagUtil.datagrid(response, dataGrid);
    }
复制代码

4、其他方式

https://my.oschina.net/u/2538398/blog/757841

博客地址:http://www.cnblogs.com/niceyoo

原文地址:https://www.cnblogs.com/Jeely/p/11309296.html