当前位置 : 主页 > 网页制作 > html >

关于通用mapper的weekendCriteria用法

来源:互联网 收集:自由互联 发布时间:2021-06-12
https://www.cnblogs.com/grey-wolf/p/8435723.html; WeekendUser weekend = new Weekend(User. class ); // 关键字查询部分 String keyword = pageReq.getKeyword(); WeekendCriteria User, Object keywordCriteria = weekend.weekendCriteria(); i

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 = ?)
网友评论