您好,登錄后才能下訂單哦!
這篇文章主要介紹了mybatis-plus QueryWrapper排序的坑案例分析的相關知識,內容詳細易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇mybatis-plus QueryWrapper排序的坑案例分析文章都會有所收獲,下面我們一起來看看吧。
大致可以總結成上面的兩句話。
我們再搞幾個實例來深入理解下條件構造器QueryWrapper的用法:
查詢姓李的,并且出生日期范圍是1993-02-09到1994-04-09的員工
sql實現:
SELECT * FROM t_employee WHERE DATE_FORMAT(birthday,'%Y-%m-%d')>='1993-02-09' AND DATE_FORMAT(birthday,'%Y-%m-%d')<='1994-04-09' AND NAME LIKE '李%'
mp實現:
/** * 查詢姓李的,并且出生日期范圍是1993-02-09到1994-04-09的員工 * sql:SELECT * FROM t_employee WHERE DATE_FORMAT(birthday,'%Y-%m-%d')>='1993-02-09' AND DATE_FORMAT(birthday,'%Y-%m-%d')<='1994-04-09' AND NAME LIKE '李%' */ @Test public void selectByQueryWrapper3(){ QueryWrapper<Employee> queryWrapper=new QueryWrapper(); // QueryWrapper<Employee> queryWrapper2=Wrappers.<Employee>query(); queryWrapper.apply("DATE_FORMAT(birthday,'%Y-%m-%d')>={0} and DATE_FORMAT(birthday,'%Y-%m-%d')<={1}","1993-02-09","1994-04-09").likeRight("name","李"); List<Employee> employeeList = employeeMapper.selectList(queryWrapper); System.out.println(employeeList); }
查詢姓李的或者郵箱不為空并且是女性的員工
sql實現:
SELECT * FROM t_employee WHERE NAME LIKE '李%' OR (email IS NOT NULL AND gender ='女')
mp實現:
/** * 查詢姓李的或者郵箱不為空并且是女性的員工 * sql:SELECT * FROM t_employee WHERE NAME LIKE '李%' OR (email IS NOT NULL AND gender ='女') */ @Test public void selectByQueryWrapper4(){ QueryWrapper<Employee> queryWrapper=new QueryWrapper(); // QueryWrapper<Employee> queryWrapper2=Wrappers.<Employee>query(); queryWrapper.likeRight("name","李").or(wq->wq.isNotNull("email").eq("gender","女")); List<Employee> employeeList = employeeMapper.selectList(queryWrapper); System.out.println(employeeList); }
查詢姓李的并且郵箱不為空或者是女性的員工
sql實現:
SELECT * FROM t_employee WHERE NAME LIKE '李%' AND (email IS NOT NULL OR gender ='女')
mp實現:
/** * 查詢姓李的并且郵箱不為空或者是女性的員工 * sql:SELECT * FROM t_employee WHERE NAME LIKE '李%' AND (email IS NOT NULL OR gender ='女') */ @Test public void selectByQueryWrapper5(){ QueryWrapper<Employee> queryWrapper=new QueryWrapper(); // QueryWrapper<Employee> queryWrapper2=Wrappers.<Employee>query(); queryWrapper.likeRight("name","李").and(wq->wq.isNotNull("email").or().eq("gender","女")); List<Employee> employeeList = employeeMapper.selectList(queryWrapper); System.out.println(employeeList); }
查詢屬于編號1,2,3部門的并且薪水小于等于3500的員工 根據年齡從大到小排序顯示
sql實現:
SELECT * FROM t_employee WHERE salary<=3500 AND departmentId IN (1,2,3) ORDER BY birthday ASC
mp實現:
/** * 查詢屬于編號1,2,3部門的并且薪水小于等于3500的員工 根據年齡從大到小排序顯示 * sql:SELECT * FROM t_employee WHERE salary<=3500 AND departmentId IN (1,2,3) ORDER BY birthday ASC */ @Test public void selectByQueryWrapper6(){ QueryWrapper<Employee> queryWrapper=new QueryWrapper(); // QueryWrapper<Employee> queryWrapper2=Wrappers.<Employee>query(); queryWrapper.likeRight("name","李").and(wq->wq.isNotNull("email").or().eq("gender","女")); List<Employee> employeeList = employeeMapper.selectList(queryWrapper); System.out.println(employeeList); }
關于“mybatis-plus QueryWrapper排序的坑案例分析”這篇文章的內容就介紹到這里,感謝各位的閱讀!相信大家對“mybatis-plus QueryWrapper排序的坑案例分析”知識都有一定的了解,大家如果還想學習更多知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。