关于通用mapper的weekendCriteria用法

https://www.cnblogs.com/grey-wolf/p/8435723.html;

Weekend<User> weekend = new Weekend<>(User.class);
        //关键字查询部分
        String keyword = pageReq.getKeyword();
        WeekendCriteria<User, Object> keywordCriteria = weekend.weekendCriteria();
        if (StringUtils.isNotEmpty(keyword)) {
            keywordCriteria.orLike(User::getUserName, keyword).orLike(User::getPoliceNo, keyword).orLike(User::getRealName, keyword);
        //此处不需要再用下面这一句了,不然上面这个条件组合会重复一次
            //weekend.and(keywordCriteria)
        }
        //部门查询部分
        Example example = new Example(User.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("departmentId", departmentId);
        weekend.and(criteria);

        PageHelper.startPage(pageReq.getPageIndex(), pageReq.getPageSize());
        List<User> users = userMapper.selectByExample(weekend);
相当于
WHERE ( user_name = ? OR police_no = ? OR real_name = ? ) AND (department_id = ?)

posted on 2019-09-21 19:50  Cherishforchen  阅读(4167)  评论(0编辑  收藏  举报

导航