ibatis中sqlmap参数map中还需要套list的情况如何写? MYBATIS


Java代码

1
2
3
4
5
6
7
8
9
Map<String,Object> ibatisParam = new HashMap<String, Object>( );
ibatisParam.put( "keyA","valueA" );
List<String> list = new ArrayList<String>( );
list.add( "namespace1" );
list.add( "namespace2" );
ibatisParam.put( "namespaces",list );
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<select id="listNodeByCriteria" parameterClass="java.util.Map" resultMap="NodeWithPropertyResult">
select <include refid="NodeColumnsWithId"/> from node
<dynamic prepend=" where ">
<isNotNull property="namespaces">
namespace in
<iterate property="namespaces" open="(" conjunction="," close=")">
#namespaces[]#
</iterate>
</isNotNull>
</dynamic>
order by id
limit #querySize# offset #startRow#
</select>

list 对象版本

1
2
3
4
5
6
<iterate property="namespaces" open="(" conjunction="," close=")">
<!--每一个NameSpace实例的name属性通过namespaces[].name获取-->
#namespaces[].name#
</iterate>

MYBATIS

xml

1
2
3
4
5
6
7
8
9
10
11
<!--List:forech中的collection属性类型是List,collection的值必须是:list,item的值可以随意,Dao接口中参数名字随意 -->
<select id="getEmployeesListParams" resultType="Employees">
select *
from EMPLOYEES e
where e.EMPLOYEE_ID in
<foreach collection="list" item="employeeId" index="index"
open="(" close=")" separator=",">
#{employeeId}
</foreach>
</select>