2007-04-19

spring mvc循序渐进(6)

关键字: spring

第十八步——添加一下测试数据让它自动装载业务对象

我还不想添加任何从数据库加载业务对象的代码。我们仅仅使用spring的bean运用环境编制几个对象。我将简单把握需要的数据全部放到springapp-servlet.xml里。我同时添加我将在后面创建的整个信息池配置('messages.properties')。

springapp/war/WEB-INF/springapp-servlet.xml

  1. xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.        xsi:schemaLocation="   
  5. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">  
  6.   
  7.   
  8.   
  9.     <bean id="springappController" class="web.SpringappController">  
  10.         <property name="productManager">  
  11.             <ref bean="prodMan"/>  
  12.         property>  
  13.     bean>  
  14.   
  15.     <bean id="prodMan" class="bus.ProductManager">  
  16.         <property name="products">  
  17.             <list>  
  18.                 <ref bean="product1"/>  
  19.                 <ref bean="product2"/>  
  20.                 <ref bean="product3"/>  
  21.             list>  
  22.         property>  
  23.     bean>  
  24.   
  25.     <bean id="product1" class="bus.Product">  
  26.         <property name="description"><value>Lampvalue>property>  
  27.         <property name="price"><value>5.75value>property>  
  28.     bean>  
  29.            
  30.     <bean id="product2" class="bus.Product">  
  31.         <property name="description"><value>Tablevalue>property>  
  32.         <property name="price"><value>75.25value>property>  
  33.     bean>  
  34.   
  35.     <bean id="product3" class="bus.Product">  
  36.         <property name="description"><value>Chairvalue>property>  
  37.         <property name="price"><value>22.79value>property>  
  38.     bean>  
  39.   
  40.     <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">  
  41.         <property name="basename"><value>messagesvalue>property>  
  42.     bean>  
  43.   
  44.   
  45.     <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">       
  46.         <property name="mappings">         
  47.             <props>              
  48.                 <prop key="/hello.htm">springappControllerprop>     
  49.             props>         
  50.         property>     
  51.     bean>  
  52.   
  53.     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
  54.         <property name="viewClass"><value>org.springframework.web.servlet.view.JstlViewvalue>property>  
  55.         <property name="prefix"><value>/WEB-INF/jsp/value>property>  
  56.         <property name="suffix"><value>.jspvalue>property>  
  57.     bean>  
  58.   
  59. beans>  

 

第十九步——添加消息池绑定同时添加一个clean target到build.xml

I create a 'messages.properties' file in the war/WEB-INF/classes directory. This properties bundle so far has three entries matching the keys specified in the tags that we added to the hello.jsp.

我在war/WEB-INF/classes目录下创建了一个“messages.properties'”文件。这个消息捆绑(properties bundle)目前已经有三个匹配hello.jsp的中定义的索引的 标签。

springapp/war/WEB-INF/classes/messages.properties

  1. title=SpringApp   
  2. heading=Hello :: SpringApp   
  3. greeting=Greetings, it is now   

运行ant,重启tomcat,浏览http://127.0.0.1:8080/springapp/hello.htm,就看到改动了

评论
aninfeel 2007-05-30
辞职了,没时间写了
gowhere 2007-05-11
楼主继续后面的哈,测试那里有点没看懂
发表评论

您还没有登录,请登录后发表评论

aninfeel
搜索本博客
博客分类
最近加入圈子
最新评论
评论排行榜