Chinaunix首页 | 论坛 | 博客
  • 博客访问: 475349
  • 博文数量: 111
  • 博客积分: 3146
  • 博客等级: 中校
  • 技术积分: 939
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-07 11:23
个人简介

Nathing

文章分类

全部博文(111)

文章存档

2016年(2)

2015年(1)

2014年(31)

2012年(2)

2011年(9)

2010年(36)

2009年(30)

我的朋友

分类: Java

2010-11-01 13:54:52

1.spring配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
     xmlns:xsi=""
     xmlns:aop=""
     xmlns:tx=""
     xsi:schemaLocation=" /spring-beans-2.0.xsd
            /spring-aop-2.0.xsd
            /spring-tx-2.0.xsd"
>
    
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://127.0.0.1/d2school"/>
        <property name="username" value="root"/>
        <property name="password" value="root"/>
    </bean>
    
    <!-- 配置事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    
    <!-- 配置事务的传播特性 -->
     <tx:advice id="txAdvice" transaction-manager="transactionManager" >
         <tx:attributes>
             <!-- 在开发的时候可以这样定义,但部署的时候一定要详细定义 -->
             <tx:method name="*" propagation="REQUIRED"/>
              <!--
             <tx:method name="add*" propagation="REQUIRED"/>
             <tx:method name="del*" propagation="REQUIRED"/>
             <tx:method name="update*" propagation="REQUIRED"/>
             <tx:method name="deploy*" propagation="REQUIRED"/>
             <tx:method name="*" read-only="true"/>
             -->
         </tx:attributes>
     </tx:advice>
     
     <!-- 配置哪些类哪些方法使用事务 -->
     <aop:config>
         <aop:pointcut id="allServiceMethod" expression="execution(* com.jj.serializ.manager.*.*(..))"/>
         <aop:advisor advice-ref="txAdvice" pointcut-ref="allServiceMethod"/>
     </aop:config>
    
    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="configLocation"><value>classpath:sqlMapConfig.xml</value></property>
    </bean>
    
    <bean id="reportDAO" class="com.jj.serializ.dao.impl.ReportDAOImpl">
        <property name="sqlMapClient" ref="sqlMapClient"></property>
    </bean>
   
</beans>


2.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"">
<!-- Always ensure to use the correct XML header as above! -->
<sqlMapConfig>
    
    <sqlMap resource="com/jj/serializ/model/Report.xml" />
    
</sqlMapConfig>


3.model.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
     PUBLIC "-//ibatis.apache.org//DTD SQL Mao 2.0//EN"
     "">
     
<sqlMap>     
    
    <typeAlias alias="Report" type="com.jj.serializ.model.Report"/>
    
    <select id="selectAllReport" resultClass="Report">
        select *
        from champions_2008
    </select>
    
</sqlMap>


4.DAO

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.jj.serializ.dao.ReportDAO;
import com.jj.serializ.model.Report;

public class ReportDAOImpl extends SqlMapClientDaoSupport implements ReportDAO
{
    @SuppressWarnings("unchecked")
    public List<Report> list()
    {
        return getSqlMapClientTemplate().queryForList("selectAllReport");
    }
}


阅读(560) | 评论(1) | 转发(0) |
0

上一篇:spring集成struts1

下一篇:Ibtis

给主人留下些什么吧!~~

chinaunix网友2010-11-01 17:46:09

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com