Recently used MySQL and mybatis to combine common knowledge points to sit down and organize

Source: Internet
Author: User

1. When using the set in (X,x ... The parameters can be single or multiple when they are single:

Findbyids (list<long> IDs), or Findbyids (Long [] IDs)

<select id= "Findbyidsmap" resultmap= "Baseresultmap" >

Select
<include refid= "Base_column_list"/>
From Jria where ID in

Open= "(" separator= "," close= ")" >
#{item}
</foreach>

collection= "Array" when an array is set

2 When there are multiple parameters for a query, such as Findbyids (String name, long[] IDs)

This situation requires special attention, when passing parameters, be sure to use the map mode, so that the collection property can specify the name
Here is an example
map<string, object> params = new hashmap<string, object> (2);
Params.put ("name", name);
Params.put ("IDs", IDS);
Mapper.findbyidsmap (params);
<select id= "Findbyidsmap" resultmap= "Baseresultmap" >
Select
<include refid= "Base_column_list"/>
From Jria where ID in
<foreach item= "item" index= "index" collection= "IDs "
open= "(" separator= "," close= ")" >
#{item}
</foreach>

</select>

Recently used MySQL and mybatis to combine common knowledge points to sit down and organize

Related Article

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.