SSH 配置

web.xml

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/daoContext.xml,/WEB-INF/applicationContext.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

applicationContext.xml

<?xml version="1.0" encoding="GBK"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <!-- 定义数据源Bean,使用C3P0数据源实现 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <!-- 指定连接数据库的驱动 -->
        <property name="driverClass" value="com.mysql.jdbc.Driver"/>
        <!-- 指定连接数据库的URL -->
        <property name="jdbcUrl" value="jdbc:mysql://localhost/daydayup"/>
        <!-- 指定连接数据库的用户名 -->
        <property name="user" value="root"/>
        <!-- 指定连接数据库的密码 -->
        <property name="password" value="root"/>
        <!-- 指定连接数据库连接池的最大连接数 -->
        <property name="maxPoolSize" value="20"/>
        <!-- 指定连接数据库连接池的最小连接数 -->
        <property name="minPoolSize" value="1"/>
        <!-- 指定连接数据库连接池的初始化连接数 -->
        <property name="initialPoolSize" value="1"/>
        <!-- 指定连接数据库连接池的连接的最大空闲时间 -->
        <property name="maxIdleTime" value="20"/>
    </bean>

    <!--定义了Hibernate的SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="mappingResources">
            <list>
                <value>com/daydayup/model/User.hbm.xml</value>
                <value>com/daydayup/model/History.hbm.xml</value>
                <value>com/daydayup/model/Finance.hbm.xml</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.jdbc.batch_size">20</prop>
            </props>
        </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>


    <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
        <!--  事务拦截器bean需要依赖注入一个事务管理器 -->
        <property name="transactionManager" ref="transactionManager"/>
        <property name="transactionAttributes">
            <!--  下面定义事务传播属性-->
            <props>
                <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
                <prop key="*">PROPAGATION_REQUIRED</prop>
            </props>
        </property>
    </bean>

    <!-- 定义BeanNameAutoProxyCreator-->
    <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
        <!--  指定对满足哪些bean name的bean自动生成业务代理 -->
        <property name="beanNames">
            <!--  下面是所有需要自动创建事务代理的bean-->
            <list>
                <value>userMgr</value>
                <value>historyMgr</value>
                <value>financeMgr</value>
            </list>
            <!--  此处可增加其他需要自动创建事务代理的bean-->
        </property>
        <!--  下面定义BeanNameAutoProxyCreator所需的事务拦截器-->
        <property name="interceptorNames">
            <list>
                <!-- 此处可增加其他新的Interceptor -->
                <value>transactionInterceptor</value>
            </list>
        </property>
    </bean>
    
    <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
        <property name="host" value="smtp.sina.com.cn"/>
        <property name="javaMailProperties">
            <props>
                <prop key="mail.smtp.port">25</prop>
                <prop key="mail.smtp.auth">true</prop>
                <prop key="mail.smtp.timeout">25000</prop>
            </props>
        </property>
        <property name="username" value="shenjie8821@sina.com"/>
        <property name="password" value="shenjie8821"/>
    </bean>

    <bean id="mailMessage"  class="org.springframework.mail.SimpleMailMessage">
        <property name="from" value="shenjie8821@sina.com"/>
    </bean>
    
    <bean id="userMgr" class="com.daydayup.service.impl.UserServiceImpl">
        <property name="userDao" ref="userDao"/>
        <property name="mailSender" ref="mailSender"/>
        <property name="mailMessage" ref="mailMessage"/>
    </bean>
    <bean id="historyMgr" class="com.daydayup.service.impl.HistoryServiceImpl">
        <property name="historyDao" ref="historyDao"/>
    </bean>
    <bean id="financeMgr" class="com.daydayup.service.impl.FinanceServiceImpl">
        <property name="financeDao" ref="financeDao"/>
    </bean>

</beans>


public class UserServiceImpl implements UserService
{
    private UserDao userDao;
    private MailSender mailSender;
    private SimpleMailMessage mailMessage;
    public void setUserDao(UserDao userDao)    {
        this.userDao = userDao;
    }
    public void setMailSender(MailSender mailSender){
        this.mailSender = mailSender;
    }
    public void setMailMessage(SimpleMailMessage mailMessage) {
        this.mailMessage = mailMessage;
    }


Finance.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com.daydayup.model">
    <class name="Finance"    table="finance">

        <id name="id" column="finance_id">
            <generator class="identity"/>
        </id>

        <property name="inorout" column="finance_inorout" not-null="true" length="1"/>
        <property name="amount" column="finance_amount" not-null="true" type="double"/>
        <property name="purpose" column="finance_purpose" not-null="true"/>
        <property name="date" column="finance_date" type="java.sql.Date"/>
    
    </class>
</hibernate-mapping>


struts.xml

<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>

    <!-- Web应用的默认编码集 -->
    <constant name="struts.i18n.encoding" value="GBK"/>
    <!-- 国际化资源文件 -->    
    <constant name="struts.custom.i18n.resources" value="messageResource"/>
    <!-- 系统自动重新加载该文件, Struts 2 配置文件改变,Web框架是否重新加载Struts 2配置文件 -->
    <constant name="struts.configuration.xml.reload" value="true"/>
    <!-- 配置开发模式, Struts 2处于开发状态 -->
    <constant name="struts.devMode" value="true"/>

    <!-- 当用户请求的URL在容器中找不到对应的Action,采用默认Action处理请求 -->
     <package name="shenjie" extends="action-default">
         <default-action-ref name="defaultViewResultAction" />
         <action name="defaultViewResultAction" class="">
             <result name="error">/error.jsp</result>
         </action>
     </package>
    
    <package name="user" extends="struts-default">
        
        <interceptors>
            <interceptor name="userIntercetor" class="com.shenjie.action.interceptor.AuthorityInterceptor"/>
            <interceptor-stack name="userStack">
                <interceptor-ref name="defaultStack"/>
                <interceptor-ref name="userIntercetor"/>
            </interceptor-stack>
        </interceptors>
        <default-interceptor-ref name="userStack"/>
        
        <global-results>
            <!-- 下面定义的结果对所有的Action都有效 -->
            <result name="error">/error.jsp</result>
        </global-results>
        
        <action name="Login" class="com.shenjie.action.UserAction"method="Login">
            <result name="login">/login.jsp</result>
            <result name="error">/login.jsp</result>
            <result name="success">/welcome.jsp</result>        
        </action>
        
    </package>
</struts>



Database

ColumnDAO dao = new ColumnDAOImpl();
        Connection conn =null;
        try {
            conn = Database.getConnection();
            dao.setConnection(conn);
            Column Column=new Column();
            Column.setColumnId(new Long(2));
            Column.setColumnName("新年喜讯");
            Column.setColumnStatus(new Integer(1));
            dao.updateColumn(Column);
            Database.commit();
            dao.listAllColumns();
            
        } catch (Exception e) {
            Database.rollback();
            e.printStackTrace();
        }finally{
            Database.releaseConnection(conn);
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值