Get the App
SLTechnology News&Howtos  ›  Database  › 

Implementation of Multi-conditional query in mybatis collection

Shulou Source: shulou.com Published: 2022-06-01 04:37:52 09月14日 Update

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!

Tags: Query condition result code parameter multiple method advanced business size preface only name field object namely property screenshot data database Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Information MySQL NVidia Xiaomi