码迷,mamicode.com
首页 > 数据库 > 详细

sql中出入一个list,返回一个list

时间:2017-11-28 19:53:35      阅读:684      评论:0      收藏:0      [点我收藏+]

标签:sql遍历

-----------传入数组------返回list<string>---------- String[] sendPersonIdArr = sendPersonId.split(","); List<String> list = staffInfoService.ListPhonesByIds(sendPersonIdArr); <!-- 通过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> -----传入List<string>----返回List<User>------   public List<User> findByUserIdList(List<String> userlist) throws Exception { return (List<User>) dao.findForList("UserMapper.findByUserIdList", userlist); } <!-- 通过userId的list来查询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>


sql中我们可以传入一个list或者一个数组,返回一个list。

这里用到了sql中的 In,用到了sql中的遍历。


在我们要向mapper.xml中传递String参数的时候,需要sql中设置

parameterType="String"

同时 要保证impl中的参数名和sql中的名字要一致。

如下:

@Override
	public User findByUE(String userId)throws Exception{
		return (User)dao.findForObject("UserMapper.findById",userId);
	}
	
	sql :
	u.id = #{userId}




sql中出入一个list,返回一个list

标签:sql遍历

原文地址:http://blog.51cto.com/jianboli/2045357

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!