Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to customize SQL for MybatisPlus EntityWrapper

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces MybatisPlus EntityWrapper how to customize SQL, the article is very detailed, has a certain reference value, interested friends must read it!

EntityWrapper Custom SQL

In mybatis plus, it is convenient to build SQL queries based on conditional constructors, which can be used to write SQL instead of us. Let's look at a few examples.

First kind

Use T selectOne (Wrapper wrapper); we just need to pass in that we create an EntityWrapper () and concatenate the conditions.

For example, new EntityWrapper (). Eq ("id", "1") is to query this piece of data where id equals 1. It supports not only eq (), but also like,not like, group by, etc., almost everything you need in SQL.

The second kind

When we need to customize the columns for a single table query, we use the setSqlSelect method, as shown below:

/ * * this format means that the where condition is created after the requireParam parameter is passed. Please write the code according to this format * Object for your single table entity class * requireParam for the parameter entity class * EntityWrapper ew = new EntityWrapper (requireParam); to construct the where condition * I set the value to 1 for the state attribute of requireParam earlier, so the where condition is automatically concatenated here, and do not pass requireParam****/ EntityWrapper ew = new EntityWrapper (requireParam) if you don't need it. / * * set the column name to be queried * * / ew.setSqlSelect ("id,resource_id,user_id,username,content,createtime,parent_id," + "path,type,like_count") / * * sort method * * / .orderBy (false, "path", false)

As in the first case, various conditions can continue to be spliced later.

The third kind

EntityWrapper () splices the where condition, which is actually mentioned in the second case, which is based on whether we have input parameters when we created the EntityWrapper.

This is all we have used so far, and I will continue to update it when we meet.

MybatisPlus custom sql query public void reconciliationForConfirmOne (Integer Id, Integer payoffType) {List frList = financeReconciliationService.selectList (new EntityWrapper () .eq ("payoff_id", Id) .eq ("payoff_type", payoffType) .where ("(reconciliation_status 1 OR reconciliation_status IS NULL)")) For (FinanceReconciliationEntity fr: frList) {fr.setReconciliationStatus (1);} if (frList! = null & & frList.size () > 0) {financeReconciliationService.updateBatchById (frList);}} these are all the contents of the article "how to customize SQL by MybatisPlus EntityWrapper". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report