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

Implementation of Multi-conditional query in mybatis collection

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Implementation of Multi-conditional query in mybatis collection

Foreword:

The business needs to return nested sets through mybatis query, which is too troublesome to query many times. Solve the problem with its own advanced query. Here is the code, which has passed the test.

To talk about my own understanding, it is a main query result set in which the result set of a subquery is nested, which can be multiple subqueries. The conditions of each subquery are obtained from the main query result set, and the return values are respectively defined. The property of the collection tag is the name of the collection in the main query. If there are more than one, write a collection,column as the parameter of the subquery. The single parameter directly writes the main query and returns the result. For example, write user_id directly. If the field of the database is encapsulated under multiple conditions, such as {userId=user_id,theme=theme}, then the parameterType of the subquery writes "java.util.Map". It seems that the multi-conditional query can only be found after mybatis3.0. Unverified, ofType is an object in the collection, and select corresponds to the following statement

Implementation code:

Select * from user_message where user_id = # {userId,jdbcType=INTEGER} select * from user_message_detail where user_id = # {userId,jdbcType=INTEGER} and message = # {theme,jdbcType=VARCHAR}

SelectUserMessageById, this is the main query. Only private List userMessageDetailList is added to VO.

For this property, the following is a screenshot of the structure of the return value

If you have any questions, please leave a message or go to the community to exchange and discuss, thank you for reading, hope to help you, thank you for your support!

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

Database

Wechat

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

12
Report