Get the App
SLTechnology News&Howtos  ›  Development  › 

A case study of pits sorted by mybatis-plus QueryWrapper

Shulou Source: shulou.com Published: 2022-06-01 19:22:31 09月30日 Update

This article mainly introduces the relevant knowledge of the pit case analysis of mybatis-plus QueryWrapper sorting, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this mybatis-plus QueryWrapper ranking pit case analysis article. Let's take a look at it.

Pit sorted by QueryWrapper

It can be summed up into the above two sentences.

Conditional constructor QueryWrapper

Let's take a few more examples to delve into the use of the conditional constructor QueryWrapper:

Case one

Check for employees surnamed Li with birth dates ranging from 1993-02-09 to 1994-04-09

Sql implementation:

SELECT * FROM t_employee WHERE DATE_FORMAT (birthday,'%Y-%m-%d') > = '1993-02-09' AND DATE_FORMAT (birthday,'%Y-%m-%d') = '1993-02-09' AND DATE_FORMAT (birthday,'%Y-%m-%d') wq.isNotNull ("email"). Eq ("gender", "female"); List employeeList = employeeMapper.selectList (queryWrapper); System.out.println (employeeList);} case three

Query employees surnamed Li and whose mailbox is not empty or female.

Sql implementation:

SELECT * FROM t_employee WHERE NAME LIKE 'Lee%' AND (email IS NOT NULL OR gender = 'female')

Mp implementation:

/ * query employees surnamed Li and whose mailbox is not empty or female * sql:SELECT * FROM t_employee WHERE NAME LIKE'Li% 'AND (email IS NOT NULL OR gender =' female') * / @ Testpublic void selectByQueryWrapper5 () {QueryWrapper queryWrapper=new QueryWrapper (); / / QueryWrapper queryWrapper2=Wrappers.query (); queryWrapper.likeRight ("name", "Li") .and (wq- > wq.isNotNull ("email"). Or (). Eq ("gender", "female")) List employeeList = employeeMapper.selectList (queryWrapper); System.out.println (employeeList);} case four

The employees whose salary is less than or equal to 3500 are displayed in the order of age, according to the order of age, which belongs to department No. 1 and 2, and whose salary is less than or equal to 3500.

Sql implementation:

SELECT * FROM t_employee WHERE salary

Tags: Cases employees queries sorting case studies analysis women mailboxes knowledge content age dates conditions articles scope salary departments constructors values examples Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Tech Info macOS MariaDB OPPO Reno