Spring Mvc 3 hasErrors总是假的 [英] Spring Mvc 3 hasErrors is always false
本文介绍了Spring Mvc 3 hasErrors总是假的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下课程,
public class MarketPlace {
@NotEmpty(message="This Template Name is required")
@Size(max=50)
private String templateName;
public String getTemplateName() {
return templateName;
}
}
使用以下发布方法,
@RequestMapping(value = "/PublishApplication.htm", method = RequestMethod.POST)
public String PublishForm(@Valid MarketPlace m, BindingResult result, Map model) {
if (result.hasErrors()) {
return "PublishApplication";
}
return "PublishApplication";
}
但是hasErrors总是假的?为什么?
我需要进一步配置吗?
But hasErrors is always false? why? Is I need any further configuration?
推荐答案
你必须在你的spring-servlet中设置注释On添加:< mvc:annotation-driven />
You have to set annotations "On" in your spring-servlet by adding this: <mvc:annotation-driven/>
不要忘记也包含命名空间MVC。它看起来像这样:
Don't forget to include also the namespace "mvc". It'll look something like this:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
添加xlmns:mvc:
add xlmns:mvc:
xmlns:mvc="http://www.springframework.org/schema/mvc
添加到xsi:schemaLocation:
add to xsi:schemaLocation:
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
这篇关于Spring Mvc 3 hasErrors总是假的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文