1.HibernateDao的用法:
[java]
public void betch_update_category(Long[] goodsIds,Long destCategoryId){ String hql = "update com.prl.entity.Goods set category = :category where goodsId in (:goodsIdStr)";
Category category = categoryManager.get(destCategoryId);
Map param = new HashMap();
param.put("category", category);
param.put("goodsIdStr", goodsIds);
goodsDAO.batchExecute(hql,param);
}
[/java]
2.NamedParameterJdbcTemplate的用法:
[java]
NamedParameterJdbcTemplate namedParameterJdbcTemplate = (NamedParameterJdbcTemplate)applicationContext.getBean("namedParameterJdbcTemplate");
List subtractDb = new ArrayList();
subtractDb.add(1L);
SqlParameterSource deleteParamSource = new MapSqlParameterSource().addValue("goodsId",goodsId).addValue("giftIdCollecton",subtractDb);
namedParameterJdbcTemplate.update("delete from goods_gift where goods_id = :goodsId and gift_Id in (:giftIdCollecton)", deleteParamSource);
[/java]
看到区别没?HibernateDao中集合的表示形式须为数组,而NamedParameterJdbcTemplate则为列表,而且必须是这样的,如果HibernateDao中传递的参数为list,而NamedParameterJdbcTemplate传递成array,得到的结果永远为空.
转自:http://peirenlei.iteye.com/blog/752822