Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 弹簧显示原始值验证错误_Java_Spring_Validation - Fatal编程技术网

Java 弹簧显示原始值验证错误

Java 弹簧显示原始值验证错误,java,spring,validation,Java,Spring,Validation,我将此表单发布到spring,我试图使其在发布更新值之前显示数据库中的原始值,同时如果存在验证错误而不是发布值,则在字段上留下错误消息。然而,我所做的一切似乎都不管用 我的post操作看起来像: @RequestMapping(method=RequestMethod.POST) public String updateValues(@ModelAttribute("values") @Valid ValueList, Errors errors, RedircetAttributes redi

我将此表单发布到spring,我试图使其在发布更新值之前显示数据库中的原始值,同时如果存在验证错误而不是发布值,则在字段上留下错误消息。然而,我所做的一切似乎都不管用

我的post操作看起来像:

@RequestMapping(method=RequestMethod.POST)
public String updateValues(@ModelAttribute("values") @Valid ValueList, Errors errors, RedircetAttributes redirectAttributes){

     if (errors.hasErrors()){
        return VALUES_VIEW;
     }
     //Do update stuff
     return VALUES_REDIRECT;
}

将模型中的值覆盖为数据库中的值。在您的情况下,类似于:

ValueList dbValueList = someService.getValueList();
valueListInModel.setSomeProperty(dbValueList.getSomeProperty());

我已经试过了,如果在球场上没有错误,它就会起作用。但是,如果值未通过验证,spring将继续使用发布的值。