1、批量查询,并且是list作为传入参数,传出参数作为自定义对象
<select id="queryUserByName" resultMap="UserCnNameMapResult"
parameterType="<span style="color:#ff0000;"><strong>list</strong></span>">
select cn_name , NAME
from p_user u where name in
<foreach collection="<span style="color:#ff0000;"><strong>list</strong></span>" item="item" index="index" open="(" separator="," close=")" >
#{item}
</foreach>
</select>
注意:
1、parameterType = "list" ,一定要这么写
2、collection = "list" 一定要这么写
3、resultMap = "UserCnNameMapResult" , 返回的是自定对象,一定要写 resultMap
2、传出参数作为java自带类型
<select id="queryUserByDepCount" <strong><span style="color:#ff0000;">resultType</span></strong>="java.lang.Integer"
parameterType="com.letv.portal.domain.query.UserQuery">
select count(1)
from p_user
</select>
</pre><pre code_snippet_id="1801930" snippet_file_name="blog_20160802_4_5202691" name="code" class="html"><select id="queryUserByName1" resultType="java.lang.String"
parameterType="list">
select cn_name
from p_user u where name in
<foreach collection="list" item="item" index="index" open="(" separator="," close=")" >
#{item}
</foreach>
</select>
注意:
1、resultType = "java.lang.Integer" ,返回的类型一定要写resultType
3、批量查询,并且是数组(array)作为传入参数
<select id="queryUserByName1" resultMap="UserCnNameMapResult"
parameterType="list">
select cn_name , NAME
from p_user u where name in
<foreach <strong><span style="color:#ff6666;">collection="array"</span></strong> item="item" index="index" open="(" separator="," close=")" >
#{item}
</foreach>
</select>
注意:
1、collection = "array" 一定要这么写
推荐文章: http://zhuyuehua.iteye.com/blog/1717525