1.先看DAO层
public void updateList(List<AddService> oldAddServiceList) {
SqlSession session = sqlSessionFactory.openSession(ExecutorType.BATCH,true);
session.update("AddServiceMapper.batchUpdate",oldAddServiceList);
session.commit();
session.close();
}
当然DAO层最上方类中注入上sqlSessionFactory
@Resource(name = "sqlSessionFactory")
private SqlSessionFactory sqlSessionFactory;
sqlSessionFactory.openSession(ExecutorType.BATCH,true);
详细了解请点击 http://www.cnblogs.com/xcch/articles/2042298.html
2.再看XML配置文件
<update id="batchUpdate" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" separator=";">
update sp_add_service set
SERVICE_NAME = #{item.serviceName},
SERVICE_TYPE = #{item.serviceType},
PRICE = #{item.price},
DESCRIPTION = #{item.description},
PRICE_RATE = #{item.priceRate},
IS_REQUIRED = #{item.isRequired},
MODIFY_TIME = now()
where ID = #{item.id}
</foreach>
</update>
3.再看Service层
@Transactional
public void updateOldAddServces(List<AddService> oldAddServiceList) {
addServiceDao.updateList(oldAddServiceList);
}
加上事务注解,防止出异常。好让事务回滚