“This is the 27th day of my participation in the Gwen Challenge in November. See details of the event: The Last Gwen Challenge in 2021”

Hi, family, I’m bug bug, here I go again. Today we are going to talk about something. OK, let’s continue with the SpringBoot Zero-basics tutorial series. Help beginners better entry!

If you think the article is good, you are welcome to like it, bookmark it, comment on it, and share it with us. Remember to give the bug bacteria a one-button three-link ~~

Ok, let’s start the main body of this issue.

One, foreword

After the last phase of mybatis-plus introductory teaching, I think everyone is not very strange to it, this period, I mainly around the following points, focus on the inside of the conditional constructor to introduce you to play, although it is easier to get started, but I will do every sentence is the key! I hope you can have a good time and have a good time!

This teaching period is quite dry! It has good teaching value. I hope you can gain something from this article. I suggest you collect it first and then read it.

How to use constructors

Preface:

The QueryWrapper(LambdaQueryWrapper) and UpdateWrapper(LambdaUpdateWrapper) parent class is AbstractWrapper, The Entity property is also used to generate WHERE conditions for SQL. Note: The WHERE condition generated by entity has no behavior associated with the WHERE condition generated using the various apis.

Note the difference between the two:

1). QueryWrapper: Entity object encapsulates the operation class.

2). UpdateWrapper: Update conditional wrapper for Entity object Update operation.

QueryWrapper is used for general query construction conditions and UpdateWrapper is used for changing types

Code walkthrough: QueryWrapper and UpdateWrapper are used for parameter passing.

@override public List getUsersBySex(String sex) {// Conditional constructor QueryWrapper wrapper = new QueryWrapper<>(); //eq stands for "="; For example, eq("sex", "male ") --> sex = 'male '; Equivalent to the WHERE condition concatenated after the SQL statement. wrapper.eq("sex",sex); List = this.list(wrapper); // Return list; } @param userId userId */ public Boolean updateByUserId(String userId){conditional constructor UpdateWrapper wrapper = new UpdateWrapper<>(); // Pass the wrapper.eq("id",userId) condition; // Call the change method return this.update(wrapper); }Copy the code

Common conditional constructors

#eq

eq(R column, Object val)
eq(boolean condition, R column, Object val)
Copy the code
  • Equal to =
  • Ex. :Eq ("name", "Lao Wang ")—>Name = 'Lao Wang'

#ne

ne(R column, Object val)
ne(boolean condition, R column, Object val)
Copy the code
  • Is not the same as < >
  • Ex. :Ne ("name", "Lao Wang ")—>Name <> 'Lao Wang'

#gt

gt(R column, Object val)
gt(boolean condition, R column, Object val)
Copy the code
  • More than >
  • Ex. :gt("age", 18)—>age > 18

#ge

ge(R column, Object val)
ge(boolean condition, R column, Object val)
Copy the code
  • The value is greater than or equal to >=
  • Ex. :ge("age", 18)—>age >= 18

#lt

lt(R column, Object val)
lt(boolean condition, R column, Object val)
Copy the code
  • < <
  • Ex. :lt("age", 18)—>age < 18

#le

le(R column, Object val)
le(boolean condition, R column, Object val)
Copy the code
  • Less than or equal to <=
  • Ex. :le("age", 18)—>age <= 18

#between

between(R column, Object val1, Object val2)
between(boolean condition, R column, Object val1, Object val2)
Copy the code
  • BETWEEN values 1 AND 2
  • Ex. :between("age", 18, 30)—>age between 18 and 30

#like

like(R column, Object val)
like(boolean condition, R column, Object val)
Copy the code
  • LIKE ‘% % values’
  • Ex. :The like (" name ", "the king")—>Name like '% king %'

#notLike

notLike(R column, Object val)
notLike(boolean condition, R column, Object val)
Copy the code
  • NOT LIKE ‘% value %’

  • NotLike (“name”, “king “)– >name not like ‘% king %’

  • NotInSql (“id”, “select id from table where ID < 3”)– >id not in (select id from table where ID < 3)

    groupBy(R… columns) groupBy(boolean condition, R… columns)

  • Grouping: GROUP BY field…

  • Example: groupBy(“id”, “name”)– >group by id,name

#orderByAsc

orderByAsc(R... columns)
orderByAsc(boolean condition, R... columns)
Copy the code
  • Sort: ORDER BY… ASC
  • Ex. :orderByAsc("id", "name")—>order by id ASC,name ASC

#orderByDesc

orderByDesc(R... columns)
orderByDesc(boolean condition, R... columns)
Copy the code
  • Sort: ORDER BY… DESC
  • Ex. :orderByDesc("id", "name")—>order by id DESC,name DESC

#orderBy

orderBy(boolean condition, boolean isAsc, R... columns)
Copy the code
  • Sort: ORDER BY…
  • Ex. :orderBy(true, true, "id", "name")—>order by id ASC,name ASC

#or

or()
or(boolean condition)
Copy the code
  • Joining together the OR

    Matters needing attention:

    Calling or actively means that the next method is not joined with and! (Default to use and if you do not call OR)

  • Example: eq (” id “, 1) or (.) eq (” name “, “wang”) — – > id = 1 or name = ‘Lao wang’

. .

To learn more, please refer to mybatis- Plus website. Here are some of the common ones for the project.

4. Example demonstration

Build a Wrapper constructor and then play around with the common API with the SQL documentation I gave you for the common constructor. This behind the development of the project to write more easily!

All of the following wrapper methods:

5. Chain call lambda

  • To obtainLambdaWrapper

    QueryWrapperIs to get inLambdaQueryWrapper

    UpdateWrapperIs to get inLambdaUpdateWrapper

The code is shown as follows:

Public List getUsersByIdAndDate(Integer userId,Integer age){// LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); // Pass the querywrapper. eq(UserEntity::getId,userId); queryWrapper.eq(UserEntity::getAge,age); Return this.list(queryWrapper); }Copy the code

In essence, lambda play is the same, except that you need to get started with the new java8 feature lambda expression syntax. Here will not expand to speak, the rest depends on their own pondering cough up.

. .

OK, that’s all for this episode. If you have any questions, feel free to comment in the comments section. See you next time.

Vi. Previous recommendation

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Springboot< a >: zero basic entry Springboot and IDEA setup

Springboot< 2 >: zero basic entry yamL, properties configuration file introduction and actual use

Springboot< three >: multi-environment switch, profile example demonstration

Springboot< four >: Introduction to stater teaching

Springboot< 5 >: common annotations for Springboot

Springboot< six >:mysql configuration and database query, implement add, delete, change and check

Springboot< seven >: Mybatis -plus entry and actual use to achieve the increase, deletion, change and check

Springboot< 8 >: Mybatis -plus conditional constructor user manual

Springboot< 9 >: Mybatis – Plus custom SQL zero-based teaching

Springboot< ten >: Mybatis XML mapping file >, <= and other special symbols written

. .

If you want to learn more, you can pay attention to the bug bug column “SpringBoot Zero-based Introduction”, from scratch, from zero to one! Hope I can help you.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Be who you want to be, there is no time limit, you can start whenever you want,

You can change from now on, or you can stay the same. There are no rules, and you can be the best version of yourself.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

If this article has been helpful, please put your thumb in the bottom left corner of the article. (# ^. ^ #);

If you like the articles shared by Bug bug, please send bug bug a note! The danjun ‘ᴗ, you guys will have a cameo appearance with you.

If you have any questions about this article, please leave a comment below or join the group [Group number: 708072830].

In view of limited personal experience, all views and technical research points, if you have any objection, please directly reply to participate in the discussion (no offensive comments, thank you);

Copyright notice: This article is the blogger’s original article, reprint please attach the original source link and this article statement, all rights reserved, piracy will investigate! (* ^ del ^ *)