Java SpringMVC3hasErrors总是错误的
我有以下课程Java SpringMVC3hasErrors总是错误的,java,jsp,spring-mvc,Java,Jsp,Spring Mvc,我有以下课程 public class MarketPlace { @NotEmpty(message="This Template Name is required") @Size(max=50) private String templateName; public String getTemplateName() { return templateName; } } 使用以下post方法 @RequestMapping(valu
public class MarketPlace {
@NotEmpty(message="This Template Name is required")
@Size(max=50)
private String templateName;
public String getTemplateName() {
return templateName;
}
}
使用以下post方法
@RequestMapping(value = "/PublishApplication.htm", method = RequestMethod.POST)
public String PublishForm(@Valid MarketPlace m, BindingResult result, Map model) {
if (result.hasErrors()) {
return "PublishApplication";
}
return "PublishApplication";
}
但是错误总是错误的?为什么?
我需要进一步的配置吗?仅将此添加到spring XML中,以启用对控制器的注释支持:
<mvc:annotation-driven/>
在这之后,它应该会工作。您必须通过添加以下内容在SpringServlet中“打开”注释:
别忘了还包括名称空间“mvc”。它看起来像这样:
<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">
添加到xsi:schemaLocation:
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
您发送的数据是否会导致MarketPlace对象中的绑定错误?如果不是,hasErrors()将始终正确地为false。是的,我正在为marketplace发送数据,并且它们已正确绑定。只有验证没有触发将mvc:annotation驱动到xml配置文件的开头。我也有一个类似的错误。这不管用。我的问题是:我也犯过类似的错误。这不管用。我的问题是:
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">