Enter a list in SQL and return a list

Source: Internet
Author: User

-----------Incoming array------returns list<string>----------string[] sendpersonidarr =  Sendpersonid.split (","); List<string> list = staffinfoservice.listphonesbyids (Sendpersonidarr);<!--  Query employee's phone via userids--><select id= "Listphonesbyids"  parametertype= "string"  resulttype= "string "> select h.telphone from hr_staff_info h left join sys_user u  on h.STAFFINFO_ID=u.STAFF_ID where  u.id in   <foreach  collection= "Array"  index= "index"  item= "Item"  open= "("  separator= ","  close= ")" >  #{item}</foreach></select>-----Incoming list<string>----return list<user>------ public  list<user> findbyuseridlist (list<string> userlist)  throws Exception  {return  (list<user>)  dao.findforlist ("Usermapper.findbyuseridlist",  userlist);} <!--  Li with useridSt to inquire userlist --><select id= "Findbyuseridlist"  parametertype= "Java.util.List"   resultmap= "Userresultmap"  >select * from sys_user  where id in   <foreach collection= "List"   item= "item"  index= "Index"  open= "(  Separator= ","  close= ")" >   #{item}</foreach></select>


In SQL we can pass in a list or an array and return a list.

This uses the in of SQL and uses the traversal in SQL.


When we want to pass the string parameter to Mapper.xml, we need to set it in SQL

Parametertype= "String"

Also make sure that the parameter names in the Impl and the names in SQL are identical.

As follows:

@Overridepublic user Findbyue (String userId) throws Exception{return (user) Dao.findforobject ("Usermapper.findbyid", USERID);} Sql:u.id = #{userid}




Enter a list in SQL and return a list

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.