springmvc配置

1.spring_velocity集成配置 

<!-- 解析velocity,配置视图解析器 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="suffix" value=".html" />
<property name="prefix" value="" />
</bean>

 

<!-- Spring+Velocity集成配置 -->
<bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="/WEB-INF/views/" />
<property name="velocityProperties">
<props>
<prop key="input.encoding">utf-8</prop>
<prop key="output.encoding">utf-8</prop>
</props>
</property>
</bean>
可以在页面上使用velocity模板语言

 

//resourceLoaderPath指定页面存放的文件夹,会自动到这个文件夹下找文件
//根据springmvc controller返回的result----->会找到web-inf/views下的results.html文件

 

2.springmvc的普通配置
<!-- 配置视图解析器-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResolverViewResolver">
<property name="prefix" value="/WEB/INF/views/" />
<property name="suffix" value=".jsp" />
</bean>

 

//根据springmvc controller返回的result----->会找到web-inf/views/result.jsp文件

 

3.springmvc 框架传参数
在Action方法参数中加上@RequestParam("id"),就可以在方法中获取传入的id值

 

Action方法执行完成后到达显示页面时传参
在Action方法参数中加入参数 Modelmap modelmap对象,方法中modelmap.put("","")就会把对象放入请求域中,
在页面上可以用EL表达式获取

 


4.在springmvc控制层获取属性文件的的配置信息
在spring-mvc.xml文件中 导入属性文件 
<util:properties id="applicationReader" location="classpath:application.properties" />

 

在controller中

private String hrburl;

 

@Value("#{applicationReader[hrbUrl]}")
public void setHrburl(String hrburl) {
this.hrburl = hrburl;
}
把属性文件中的键值对(hrbur对应的值)注入到javaBean的属性中

 

web.xml中的配置:

核心控制器:

<servlet>
<servlet-name>hcm</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>hcm</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章