Spring 3.0中配置properties文件变得更简单,支持通配符形式
如果在多个项目中配置多个该元素,则需要加入以下参数
Spring MVC 3.0中,使用velocity绑定表单时,进行html转义使用以下方法绑定
或者
spring MVC 3.0中,action方法参数上如果绑定了一个表单可以使用如下方式:
其中的@ModelAttribute和BindingResult 中间不能有其它参数,否则会出现如下错误:
[code]
Errors/BindingResult argument declared without preceding model attribute. Check your handler method signature!
[/code]
参考:[url]http://howsun.blog.sohu.com/119023106.html[/url]
配置velocity的resourceLoader,如果希望除了默认的file类型的loader还希望通过从classpath中的jar或zip包中读取资源文件,则再配置一个自定义的resourceLoader。假如我们想要使用我们的classpath中的abc.jar中的xyz.velocity包中的custom-macro.vm的宏文件,则使用以下配置即可:
spring mvc 3.0中的@ExceptionHandler注解只能处理当前controller抛出的异常。如果,这个功能似乎有点弱,应该支持全局异常。
返回json结果,只要使用
@ResponseBody在方法上即可
<context:property-placeholder location="classpath:abc.properties" />
如果在多个项目中配置多个该元素,则需要加入以下参数
<context:property-placeholder location="classpath:abc.properties" ignore-unresolvable="true" />
Spring MVC 3.0中,使用velocity绑定表单时,进行html转义使用以下方法绑定
#springBindEscaped("command.email", true)
或者
<#-- until this point, default HTML escaping is used -->
<#assign htmlEscape = true in spring>
<#-- next field will use HTML escaping -->
<@spring.formInput "command.name" />
<#assign htmlEscape = false in spring>
<#-- all future fields will be bound with HTML escaping off -->
spring MVC 3.0中,action方法参数上如果绑定了一个表单可以使用如下方式:
public String doCreate(@Valid @ModelAttribute("appForm") CreateAppForm appForm,
BindingResult result, ...) {
...
}
其中的@ModelAttribute和BindingResult 中间不能有其它参数,否则会出现如下错误:
[code]
Errors/BindingResult argument declared without preceding model attribute. Check your handler method signature!
[/code]
参考:[url]http://howsun.blog.sohu.com/119023106.html[/url]
配置velocity的resourceLoader,如果希望除了默认的file类型的loader还希望通过从classpath中的jar或zip包中读取资源文件,则再配置一个自定义的resourceLoader。假如我们想要使用我们的classpath中的abc.jar中的xyz.velocity包中的custom-macro.vm的宏文件,则使用以下配置即可:
<bean id="velocityConfig"
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>
<!--
除默认的FileResourceLoader外再增加自定义的resourceLoader,从classpath中读取(jar,zip)
-->
<prop key="customMacro.resource.loader.class">
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
</prop>
<prop key="customMacro.resource.loader.path">customMacro</prop>
<prop key="velocimacro.library">xyz/velocity/custom-macro.vm</prop>
</props>
</property>
</bean>
spring mvc 3.0中的@ExceptionHandler注解只能处理当前controller抛出的异常。如果,这个功能似乎有点弱,应该支持全局异常。
返回json结果,只要使用
@ResponseBody在方法上即可