mybatis的xml中用foreach分隔逗号的写法

<select id="getUserListByUsernames" parameterType="java.lang.String"  resultType="org.jeecg.modules.system.entity.SysUser">
		select * from  sys_user  where username in
		<foreach item="item" index="index" collection="usernames.split(',')"  open="(" separator="," close=")">
			'${item}'
		</foreach>
		 and del_flag = '0'
	</select>

 

注意:

  1. parameterType="java.lang.String"   传进来的是这种形式:'1,2,3,4,5',很明显,这样在in中遍历会报错,所以需要逗号分隔结果变成这种形式'1','2','3','4';

2.resultType="org.jeecg.modules.system.entity.SysUser",你自己的返回的结果集类型;

3.重中之重:collection="usernames.split(',')",这里的usernames代表你传过来的那个参数;

4.'${item}' ,要用美元符号,并且要加引号

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章