Validation Spring Boot 2.0-验证不起作用

Validation Spring Boot 2.0-验证不起作用,validation,spring-boot,Validation,Spring Boot,我创建了我想用Spring工具验证的表单。不幸的是,表单传递时出现了错误。我不知道是什么问题。我试着添加到pom弹簧靴启动器验证中,但它是不起作用的。你能告诉我哪里有错误吗 pom: 雇员: package com.xyz.dto; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; public class EmployeeDTO { private I

我创建了我想用Spring工具验证的表单。不幸的是,表单传递时出现了错误。我不知道是什么问题。我试着添加到pom弹簧靴启动器验证中,但它是不起作用的。你能告诉我哪里有错误吗

pom:

雇员:

package com.xyz.dto;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

    public class EmployeeDTO {

    private Integer id = null;

    @NotNull
    @Size(max = 100)
    private String name;

    @NotNull
    @Size(max = 150)
    private String street;

    @NotNull
    @Size(max = 150)
    private String city;

@NotNull
@Email
private String email;
//getters and setters

我也有过类似的问题。更新到SpringBoot2.0之后,验证就不起作用了。问题在于方法

@InitBinder(BasketCommandService.COMMAND_NAME)
protected final void initBinder(WebDataBinder binder) {
    binder.addValidators(validator);
}
那是无法代理的。 这是生成我的项目时控制台输出的一部分:

2018-07-09 14:26:15.593  INFO 18600 --- [           main] o.s.aop.framework.CglibAopProxy          : Final method [protected final void cz.<companyName>.core.web.shop.orderprocess.AbstractOrderProcessController.initBinder(org.springframework.web.bind.WebDataBinder)] cannot get proxied via CGLIB: Calls to this method will NOT be routed to the target instance and might lead to NPEs against uninitialized fields in the proxy instance.
2018-07-09 14:26:15.593信息18600---[main]o.s.aop.framework.CglibAopProxy:Final方法[protectedfinal void cz..core.web.shop.orderprocess.abstractorderprocescontroller.initBinder(org.springframework.web.bind.WebDataBinder)]无法通过CGLIB获得代理:对该方法的调用将不会路由到目标实例,并可能导致针对代理实例中未初始化字段的NPE。

解决方法是查看所有类似于上面的警告,并从受影响的方法中删除“final”一词。

您的
saveEmployee
方法正在处理GET请求,而前端代码可能正在发布表单。如果你的方法被调用了?您在浏览器开发工具中看到了什么?是的,方法被调用。发送参数。当我调试代码(Java)并在metod中发布breakpoin“if(result.hasErrors()”时,我得到“result:”org.springframework.validation.BeanPropertyBindingResult:0错误“”
@InitBinder(BasketCommandService.COMMAND_NAME)
protected final void initBinder(WebDataBinder binder) {
    binder.addValidators(validator);
}
2018-07-09 14:26:15.593  INFO 18600 --- [           main] o.s.aop.framework.CglibAopProxy          : Final method [protected final void cz.<companyName>.core.web.shop.orderprocess.AbstractOrderProcessController.initBinder(org.springframework.web.bind.WebDataBinder)] cannot get proxied via CGLIB: Calls to this method will NOT be routed to the target instance and might lead to NPEs against uninitialized fields in the proxy instance.