MyBatis SQL in query (MyBatis SQL statement passed in parameter is list) MyBatis in how to receive value when using in query

Source: Internet
Author: User

1.in when the query condition is List

<SelectId="getmultimomentscommentscounts"Resulttype="int">SelectMoment_comment_count fromTbl_moment_commentcountwhereMidinch<foreachitem="Item"index="Index"collection="List"open="("Separator=","Close=")">#{item}</foreach> </Select>

.1 if the type of the parameter is list, then when used, the collection property must be specified as a list

  1. <select id= "findbyidsmap" resultmap="Baseresultmap">
  2. Select
  3. <include refid="base_column_list" />
  4. From Jria where ID in
  5. <foreach item="item" index="index" collection="list" open="(" Separator="," close=")">
  6. #{item}
  7. </foreach>
  8. </Select>

2.in when the query condition is an enumeration value

By default, using the Select XXX where in (xx,xx) query, the returned results are sorted by primary key, and if you want to sort the values in the In () order, you can do this: select * from Talbe where ID in (3,2,4,1) Order by FI Nd_in_set (ID, ' 3,2,4,1 ')

MyBatis SQL in query (MyBatis SQL statement passed in parameter is list) MyBatis in how to receive value when using in query

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.