日期:2014-05-16 浏览次数:20455 次
1.HibernateDao的用法:
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); }
?
2.NamedParameterJdbcTemplate的用法:
NamedParameterJdbcTemplate namedParameterJdbcTemplate = (NamedParameterJdbcTemplate)applicationContext.getBean("namedParameterJdbcTemplate"); List<Long> subtractDb = new ArrayList<Long>(); 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);?
?
看到区别没?HibernateDao中集合的表示形式须为数组,而NamedParameterJdbcTemplate则为列表,而且必须是这样的,如果HibernateDao中传递的参数为list,而NamedParameterJdbcTemplate传递成array,你得到的结果永远为空,切记,这个问题困扰了我很久,特记于此