在使用IBATIS进行SQL语句配置查询时,我们一定会遇到通过IN查询的地方,在使用IN查询时我们可以有两种方式进行配置参数:String和List。具体使用方式如下:
1.String:定义一个String的参数userIds,把这个参数传入IBATIS的sql配置文件,sql语句就可以这样写:
<select id="getForms" parameterClass="MisInvTransHeaderInterfaceForm" resultClass="MisInvTransHeaderInterfaceForm">
<![CDATA[
SELECT USER_NAME userName,ADDRESS address
FROM FND_USER
WHERE USER_ID IN
]]>
<iterate property="userIds" conjunction="," open="(" close=")">
#userIds[]#
</iterate>
</select>
2.List:定义一个List的参数userIdArr,把这个参数传入IBATIS的sql配置文件,sql语句就可以这样写:
<select id="getForms" parameterClass="MisInvTransHeaderInterfaceForm" resultClass="MisInvTransHeaderInterfaceForm">
<![CDATA[
SELECT USER_NAME userName,ADDRESS address
FROM FND_USER
WHERE USER_ID IN
]]>
<iterate property="userIdArr" conjunction="," open="(" close=")">
$userIdArr[]$
</iterate>
</select>