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 in query in mybatis-plus

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

Share

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

This article is about how to use in queries in mybatis-plus. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The steps are as follows:

/ query the list collection List userList = userService.selectById (id); / / result set List resultList = new ArrayList (); / / traverse the collection with the value userList .forEach (item- > {resultList.add (item.getYouNeedId ());}); / / conditional constructor in uses QueryWrapper qw = new QueryWrapper (); qw.in ("you_need_id", resultList) / / there is a paged query, or you can use other methods encapsulated in mybatisplus IPage userIPage = userMapper.selectPage (page, qw) without paging; / / return the query results, getRecords is also the method encapsulated in mybatisplus return contractRecordIPage.getRecords (); add: the use of the in () method when Mybatis Plus queries through QueryWrapper

UserId class:

@ Datapublic class UserId {/ * user id Collection * / private JSONArray userIdList;}

Test class:

Public class Test {public JSONArray getUserStatusList (UserId userId) {/ / add a non-empty check. If the JsonArray object is null or the length is 0, it will be returned directly without executing sql if (userId.getUserIdList () = = null | | userId.getUserIdList (). Size () = 0) {return new JSONArray ();} / / create query Wrapper object QueryWrapper wrapper = new QueryWrapper (); wrapper.in ("user_id", userId.getUserIdList ()); List list = baseMapper.selectObjs (wrapper) Return JSONArray.parseArray (JSON.toJSONString (list));}}

Note: if the non-null check is not added, the SQL exception will be reported when the collection is empty.

Thank you for reading! This is the end of this article on "how to use in queries in mybatis-plus". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

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