Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use apply, last and select of mybatis QueryWrapper

Shulou Source: shulou.com Published: 2022-06-01 04:16:58 09月21日 Update

This article "mybatis QueryWrapper apply, last, select how to use" most people do not understand, so the editor summarized the following content, detailed, clear steps, with a certain reference value, I hope you can get something after reading this article, let's take a look at this "mybatis QueryWrapper apply, last, select how to use" article.

Apply, last, select of QueryWrapper conditional Construction

Scenario: when querying a database to limit the number of entries

Limit on mysql uses QueryWrapper needSyn = new QueryWrapper (); needSyn.ge ("ModifyDate", lmtSynRec.getLatestDate ()); needSyn.last ("limit 200"); List needData = cusCarInfoMapper.selectList (needSyn)

If it is oracle, you can use apply.

NeedSyn.apply ("rownum"

< {0}" , 200);如果是sqlserver 建议自己写sql查询语句 select top ${top} * from CUS_CAR_INFO t where t.ModifyDate >

Cast (# {latestDate} as datetime) orderBy t.ModifyDate ascList getSynList (int top, Date latestDate)

Or use QueryWrapper's select

QueryWrapper wrapper = new QueryWrapper (); wrapper.select ("top 200 *"); return this.list (wrapper)

The above is to query top data according to the latest time

The field passed in is of time type and is received with a # {} placeholder. If it is a specific number or character, you can receive it with ${}.

Conditional constructor QueryWrapper instance

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: Query employee content female case mailbox condition instance that is age data article date time knowledge article scope salary department constructor Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn macOS Docker Apple MySQL