public List<Asset> findUpAssetsByIds(List<Long> ids)
throws PortalMSException
{
return (List<Asset>)this.getSqlMapClientTemplate()
.queryForList("Asset.findUpAssetsByIds", ids);
}
<!-- 查询上架关系查询媒资和栏目id -->
<select id="Asset.findUpAssetsByIds" parameterClass="java.util.List" resultMap="AssetResult3">
SELECT cp.resource_id,
cp.column_id
FROM t_res_cloumn_map cp
WHERE cp.id IN
<iterate conjunction="," open="(" close=")" >
#ids[]#
</iterate>
</select>
当ids为空时报错
org.springframework.jdbc.BadSqlGrammarException: SqlMapClient operation; bad SQL grammar []; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred while applying a parameter map.
--- Check the Asset.findUpAssetsByIds-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLException: ORA-00936: 缺失表达式
改为:
@SuppressWarnings("unchecked")
public List<Asset> findUpAssetsByIds(List<Long> ids)
throws PortalMSException
{
Map<String, List<Long>> map = new HashMap<String, List<Long>>();
map.put("ids", ids);
return (List<Asset>)this.getSqlMapClientTemplate()
.queryForList("Asset.findUpAssetsByIds", map);
}
<!-- 查询上架关系查询媒资和栏目id -->
<select id="Asset.findUpAssetsByIds" parameterClass="java.util.HashMap" resultMap="AssetResult3">
SELECT cp.resource_id,
cp.column_id
FROM t_res_cloumn_map cp
<isNotEmpty property="ids">
WHERE cp.id IN
<iterate conjunction="," open="(" close=")" property="ids">
#ids[]#
</iterate>
</isNotEmpty>
<isEmpty property="ids">
where 1 != 1
</isEmpty>
</select>