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 use parentheses to nest queries in mybatisplus where QueryWrapper

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Most people do not understand the knowledge points of this article "mybatisplus where QueryWrapper how to add parentheses nested query", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "mybatisplus where QueryWrapper how to add parentheses nested query" article.

Where QueryWrapper nested query in parentheses

The previous code looks like this:

QueryWrapper wrapper = new QueryWrapper (); wrapper.eq ("phoneNumber", phone); if (StringUtils.isEmpty (scenetype)) {wrapper.isNull ("scenetype"). Or (). Eq ("scenetype", ");} wrapper.eq (" delFlag "," 0 ")

The corresponding SQL statement is as follows:

WHERE (phoneNumber = 156 million dollars) AND scenetype IS NULL OR scenetype = "" AND delFlag = 0)

This is not the sql statement I want, and the data for the query is incorrect. The query for scenetype should be enclosed and meet one of its conditions, that is:

WHERE (phoneNumber = 156 million dollars) 8888 AND (scenetype IS NULL OR scenetype = ") AND delFlag = 0)

The corresponding code should be written like this:

QueryWrapper wrapper = new QueryWrapper (); wrapper.eq ("phoneNumber", phone); if (StringUtils.isEmpty (scenetype)) {wrapper.and (e-> e.isNull ("scenetype") .or (). Eq ("scenetype", "));} wrapper.eq (" delFlag "," 0 "); mybatisplus query statement with parentheses (.or (), .and ())

Java Code:

QueryWrapper wrapper = new QueryWrapper (); wrapper.ne ("id", param.getId ()) wrapper.and (QueryWrapper-> QueryWrapper.eq ("name", name). Or (). Eq ("mark", mark); entityMapper.selectList (wrapper)

Equivalent sql

SELECT id FROM t_entity WHERE (id? AND (name =? OR mark =?))

Each and is equivalent to a parenthesis

The above is about "mybatisplus where QueryWrapper how to add parentheses nested query" this article content, I believe we all have a certain understanding, I hope the editor to share the content to help you, if you want to know more related knowledge, please pay attention to 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