s2s3m3架构整合

struts2.1.8,spring3.1.1,mybatis3.1.1整合

s2s3m3架构整合 - 周行天下 - zz的博客

 

s2s3m3架构整合 - 周行天下 - zz的博客

 

s2s3m3架构整合 - 周行天下 - zz的博客
 

 mybatis 与spring整合最重要的包。mybatis-spring-1.1.1.jar

bean包中User实体。


 private int id;
 
 private String name;
 
 private String password;
 
 private Date birthDate;

get。。。set。。。方法。。

iface包中。。

interface IUserDao

public List<User> selectUserById(int id);

 

public class IUserDaoImpl  extends SqlSessionDaoSupport implements IUserDao{

 public List<User> selectUserById(int id) {
  return getSqlSession().selectList("selectUserById", id);
 }

service包中。

 interface IUserService

 public List<User> selectUserById(int id);


public class IUserServiceImpl implements IUserService{

 
 private IUserDao serviceUserDao;

 public IUserDao getServiceUserDao()
 {
   return serviceUserDao;
 }
 public void setServiceUserDao(IUserDao serviceUserDao)
 {
   this.serviceUserDao = serviceUserDao;
 }
 

 public List<User> selectUserById(int id) {
  return serviceUserDao.selectUserById(id);
 }

}

mybatis-config.xml文件:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC 
"-//mybatis.org//DTD Config 3.0//EN" 
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>
  <typeAlias alias="User" type="com.zz.bean.User"/>
</typeAliases>
<mappers>
  <mapper resource="sqlMap/User.xml" />
</mappers>
</configuration>

sqlMap包下面User.xml

<?xml version="1.0" encoding="UTF-8" ?>  
<!DOCTYPE mapper PUBLIC 
"-//mybatis.org//DTD Mapper 3.0//EN" 
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="user">  
  
    <resultMap type="User" id="userResultMap">  
        <id property="id" column="ID"/>  
        <result property="name" column="NAME"/>  
        <result property="password" column="PASSWORD"/>  
        <result property="birthDate" column="birthDate" javaType="java.util.Date"/>  
    </resultMap>  
        
<select id="selectUserById" parameterType="java.lang.String" resultType="User">
  <![CDATA[  
            SELECT * FROM USER SU  
                WHERE SU.ID = #{id}
        ]]> 
</select>
</mapper> 

application 文件中。。。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:jee="http://www.springframework.org/schema/jee"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:context="http://www.springframework.org/schema/context"
 xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd
     http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.5.xsd
     http://www.springframework.org/schema/jeehttp://www.springframework.org/schema/jee/spring-jee-2.5.xsd
     http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsd"
 default-lazy-init="true">
 

 
  <!-- 数据源属性配置文件 -->
  
<context:property-placeholder location="classpath:dataSource.properties"/>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
  <property name="driverClass" value="${jdbc.driverClassName}" />
  <property name="jdbcUrl" value="${jdbc.url}" />
  <property name="user" value="${jdbc.username}" />
  <property name="password" value="${jdbc.password}" />
  <property name="autoCommitOnClose" value="true"/>
  <property name="checkoutTimeout" value="${cpool.checkoutTimeout}"/>
  <property name="initialPoolSize" value="${cpool.minPoolSize}"/>
  <property name="minPoolSize" value="${cpool.minPoolSize}"/>
  <property name="maxPoolSize" value="${cpool.maxPoolSize}"/>
  <property name="maxIdleTime" value="${cpool.maxIdleTime}"/>
  <property name="acquireIncrement" value="${cpool.acquireIncrement}"/>
  <property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}"/>
</bean>
<!-- 数据连接管理 -->

<!-- 数据库事务 -->

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource" />
</bean>


<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  <property name="configLocation" value="classpath:mybatis-config.xml"/>
  <property name="dataSource" ref="dataSource"/>
</bean>
 

  <bean id="userServices" parent="transactionProxy">
          <property name="target">
   <bean class="com.zz.service.IUserServiceImpl">
    <property name="serviceUserDao">
     <ref bean="mapperDao" />
    </property>
   </bean>
  </property>
   </bean>
   

   <bean id="transactionProxy"
  class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
  abstract="true">
  <property name="transactionManager"
   ref="transactionManager" />
  <property name="transactionAttributes">
   <props>
    <prop key="create*">
     PROPAGATION_REQUIRED,-Exception
    </prop>
    <prop key="delete*">
     PROPAGATION_REQUIRED,-Exception
    </prop>
    <prop key="update*">
     PROPAGATION_REQUIRED,-Exception
    </prop>
    <prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
    <prop key="dispatch*">
     PROPAGATION_REQUIRED,-Exception
    </prop>
    <prop key="receive*">
     PROPAGATION_REQUIRED,-Exception
    </prop>
    <prop key="revert*">
     PROPAGATION_REQUIRED,-Exception
    </prop>
    <prop key="reply*">
     PROPAGATION_REQUIRED,-Exception
    </prop>
    <prop key="insert*">
     PROPAGATION_REQUIRED,-Exception
    </prop>
    <prop key="repair*">
     PROPAGATION_REQUIRED,-Exception
    </prop>
    
    <prop key="*">
     PROPAGATION_REQUIRED,ISOLATION_DEFAULT
    </prop>
   </props>
  </property>
 </bean>
 
   
   <bean id="mapperDao" class="com.zz.iface.IUserDaoImpl">
        
           <property name="sqlSessionFactory" ref="sqlSessionFactory"/> 
 
</bean>
 
</beans>

dataSource.properties文件:

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ruixi?characterEncoding=GBK
jdbc.username=root
jdbc.password=root
cpool.checkoutTimeout=5000
cpool.minPoolSize=20
cpool.maxPoolSize=50
cpool.maxIdleTime=7200
cpool.maxIdleTimeExcessConnections=1800
cpool.acquireIncrement=10

struts.properties

struts.objectFactory=spring
struts.enable.DynamicMethodInvocation=false
struts.devMode=false
struts.locale=zh_CN
struts.i18n.encoding=GBK

其它只要使用过s2sh架构的,都很清楚,几乎一样。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值