MyBatis Association Table Association and its solutions for common use with rowbounds

Source: Internet
Author: User

As stated in the MyBatis manual, there are two implementations of association, nested queries and nested result mappings. As described in the manual, the Select method brings up the problem of n+1 queries, and it is recommended to use nested result mappings for efficiency issues. However, nested result mappings are reported Mapped statements with nested result mapping cannot is safely constrained by R when using Rowbounds for paging Owbounds exception. After testing found that there is a conflict between rowbounds and resultmap-association, fish and bear can not have both, I think it is best to choose to give up rowbounds. After all, you can add variables to the SQL statement to implement paging.

Solution:
 <  select  id  = "Selectbyowner"   ParameterType  = "int"   Resultmap  = "Topicresultmap"   ResultsetType  = "Forward_only"  >   
Select T.tid as Tid, t.uid as Tuid, t.content as content, T.commentcount as Commentcount, t.pptime as Pptime,
U.uid as UID, u.email as email, u.nickname as nickname, U.login as login, u.pass as pass, u.pic as PIC
from topic as T left JOIN user as u on t.uid = U.uid
where t.uid = #{o} limit #{offset},#{limit}
</ select >

#{o} represents the original parameter. This allows the paging task to be handed to the database for completion.

=====================

Or do not rowbounds, direct the offset and pagesize into the DAO, and then add the limit #{offset},#{limit} after SQL

 

MyBatis Association Table Association and its solutions for common use with rowbounds

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.