读书人

spring入门范例-DAO声明事务

发布时间: 2012-10-25 10:58:57 作者: rapoo

spring入门实例-DAO,声明事务

spring入门实例-DAO,事务

实例使用代理模式,使用DAO,并且添加事务功能

配置文件:

/** * use declarative transaction * @author logichina *  */public class DataSourceDAO{private DataSource dataSource;public void setDataSource(DataSource dataSource){this.dataSource = dataSource;this.jdbcTemplate = new JdbcTemplate(dataSource);}private JdbcTemplate jdbcTemplate;public void insertCustomer(){jdbcTemplate.update("insert into t_lpromis_yxgl_khxx(id,khqc) values('000023','testname4')");jdbcTemplate.update("insert into t_lpromis_yxgl_khxx(id,khqc) values('000024','testname5')");jdbcTemplate.update("insert into t_lpromis_yxgl_khxx(id,khqc) values('000023','testname6')");}public static void main(String[] args){ApplicationContext context = new ClassPathXmlApplicationContext("com/myspring/bussiness/declare/datasourceDAO.xml");DataSourceDAO bean = (DataSourceDAO) context.getBean("userDAOProxy");bean.insertCustomer();}}
?

?

?

?

读书人网 >软件架构设计

热点推荐