开发Spring MVC应用程序(4-3)

l         springapp-xml中需要定义DAO使用的DataSourceProductManagerDao接口的引用

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
 "http://www.springframework.org/dtd/spring-beans.dtd">
 
<!--
  - Application context definition for "springapp" DispatcherServlet.
  -->
 
<beans>
 
    <!--  Controller for the initial "Hello" page -->
    <bean id="springappController" class="web.SpringappController">
        <property name="productManager">
            <ref bean="prodMan"/>
        </property>
    </bean>
 
    <!--  Validator and Form Controller for the "Price Increase" page -->
    <bean id="priceIncreaseValidator" class="bus.PriceIncreaseValidator"/>
    <bean id="priceIncreaseForm" class="web.PriceIncreaseFormController">
        <property name="sessionForm"><value>true</value></property>
        <property name="commandName"><value>priceIncrease</value></property>
        <property name="commandClass"><value>bus.PriceIncrease</value></property>
        <property name="validator"><ref bean="priceIncreaseValidator"/></property>
        <property name="formView"><value>priceincrease</value></property>
        <property name="successView"><value>hello.htm</value></property>
        <property name="productManager">
            <ref bean="prodMan"/>
        </property>
    </bean>
 
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property>
      <property name="url">
        <value>jdbc:mysql://localhost/test</value>
      </property>
      <property name="username"><value>test</value></property>
      <property name="password"><value>test</value></property>
    </bean>
 
    <bean id="prodManDao" class="db.ProductManagerDaoJdbc">
        <property name="dataSource">
            <ref bean="dataSource"/>
        </property>
    </bean>
 
    <bean id="prodMan" class="bus.ProductManager">
        <property name="productManagerDao">
            <ref bean="prodManDao"/>
        </property>
<!--
        <property name="products">
            <list>
                <ref bean="product1"/>
                <ref bean="product2"/>
                <ref bean="product3"/>
            </list>
        </property>
-->
    </bean>
<!--
    <bean id="product1" class="bus.Product">
        <property name="description"><value>Lamp</value></property>
        <property name="price"><value>5.75</value></property>
    </bean>
 
    <bean id="product2" class="bus.Product">
        <property name="description"><value>Table</value></property>
        <property name="price"><value>75.25</value></property>
    </bean>
 
    <bean id="product3" class="bus.Product">
        <property name="description"><value>Chair</value></property>
        <property name="price"><value>22.79</value></property>
    </bean>
-->
    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename"><value>messages</value></property>
    </bean>
 
    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="/hello.htm">springappController</prop>
                <prop key="/priceincrease.htm">priceIncreaseForm</prop>
            </props>
        </property>
    </bean>
 
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass">
           <value>org.springframework.web.servlet.view.JstlView</value>
        </property>
        <property name="prefix"><value>/WEB-INF/jsp/</value></property>
        <property name="suffix"><value>.jsp</value></property>
    </bean>
</beans>

l         重新部署程序,运行程序,做增长价格的操作,数据库中数据会相应变化

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值