This is the 16th day of my participation in the August More Text Challenge. For details, see: August More Text Challenge

AbstractWrapper encapsulates a query condition

QueryWrapper(LambdaQueryWrapper) and UpdateWrapper(LambdaUpdateWrapper) are derived from AbstractWrapper.AbstractWrapper wrapper: AbstractWrapper wrapper:

  • Is equal to: =
eq(R column, Object val) 
// eq("name", "123")`--->`name = '123'
Copy the code
  • Is not the same as < >
ne(R column, Object val)
// ne("name", "123")--->`name <> '123'
Copy the code
  • More than >
gt(R column, Object val)
// gt("age", 18)--->`age > 18`
Copy the code
  • Greater than or equal to greater than or equal to
ge(R column, Object val)
// ge("age", 18)--->`age >= 18`
Copy the code
  • < <
lt(R column, Object val)
// lt("age", 18)`--->`age < 18`
Copy the code
  • BETWEEN values 1 AND 2(notBetween is similar to this)
between(R column, Object val1, Object val2)
// between("age", 18, 30)`--->`age between 18 and 30
Copy the code
  • LIKE ‘% % values’
Like (R column, Object val) / / like ` (" name ", "the king") -- - > ` name like '% % king' `Copy the code

(notLike, likeLeft, likeRight and like are similar, but the matching data is different)

  • Field IS NULL
isNull(R column)
// isNull("name")--->`name is null`
Copy the code

(isNotNull similar)

  • IN (value.get(0), value.get(1),…)
in(R column, Collection<? > value) / / ` in (" age ", {1, 2, 3}) ` - > ` age in ` (1, 2, 3)Copy the code

(NOT IN)

  • Field IN (SQL statement) This is intended to be more flexible than IN above
InSql (R column, String inValue) / / ` inSql (" age ", "6") ` - > ` age in (6) ` / / ` inSql (" id ", "select id from table where id < 3")`--->`id in (select id from table where id < 3)`Copy the code

(字段 NOT IN ( sql语句 ) 类似)

  • GROUP BY field,…
groupBy(R... columns)
// `groupBy("id", "name")`--->`group by id,name`
Copy the code

ORDER BY field… DESC

orderByDesc(R... columns)
// `orderByDesc("id", "name")`--->`order by id DESC,name DESC`

Copy the code

(orderByDesc,orderBy is similar to above where orderBy defaults to ASC order)

  • Joining together the OR

This is something to keep in mind during redevelopment: an active call to or means that the next method is not connected with and! (If you do not call or, use the and connection by default)

Post a picture:

  • Summary: The above query conditions are often used in the redevelopment process, which also proves a feature of MyBatis – Plus: more powerful conditional constructor, to meet all kinds of use requirements. These query conditions basically include our commonly used queries. However, for complex business query statements, it is not recommended to use query conditions to complete the query. You can directly write SQL query statements in the mapper. XML file. Annotations can also be used

QueryWrapper

Inheriting AbstractWrapper, its own internal entity attribute is also used to generate the WHERE condition//eg: select(“id”, “name”, “age”);

UpdateWrapper

Supplement:

  • SQL SET field

// set(“name”, “123”)

conclusion

Write SQL we usually combined with a variety of conditions, and conditions of the constructor is precisely to help me to simplify the operation, we can directly call conditions these method in the constructor with the query, this article is mainly to share how to invoke the query conditions, use a few times more familiar, more detailed you can view the official document.