-----------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