Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.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
我在控制器的寄存器函数中添加了@Valid注释,现在我得到了javax.validation.ValidationException错误_Java_Json_Validation_Spring Mvc - Fatal编程技术网

我在控制器的寄存器函数中添加了@Valid注释,现在我得到了javax.validation.ValidationException错误

我在控制器的寄存器函数中添加了@Valid注释,现在我得到了javax.validation.ValidationException错误,java,json,validation,spring-mvc,Java,Json,Validation,Spring Mvc,这是发送到控制器的内容: JSON: {"username":"testy9001@test.com","password":"test","firstName":"First","lastName":"Last","langKey":"en-US","enabled":false} @RequestMapping(value = "/register", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VA

这是发送到控制器的内容:

JSON: {"username":"testy9001@test.com","password":"test","firstName":"First","lastName":"Last","langKey":"en-US","enabled":false}
@RequestMapping(value = "/register", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<?> registerAccount(@Valid @RequestBody User userDTO) {
        User user = null;
        if (/* user authenticating */) {
            return ResponseEntity.badRequest()
                    .contentType(MediaType.TEXT_PLAIN)
                    .body(error);
        } else {
            user = userService.createUserInformation(userDTO.getUsername().toLowerCase(), encoder.encode(userDTO.getPassword()), userDTO.getFirstName(), userDTO.getLastName(), userDTO.getLangKey());

            mailService.sendEmail(user, env.getRequiredProperty("default.mail."+env.getRequiredProperty("spring.profiles.active")+".url"), MailType.ACTIVATION);
            return new ResponseEntity<>(user, HttpStatus.OK);
        }
    }
这是控制器:

JSON: {"username":"testy9001@test.com","password":"test","firstName":"First","lastName":"Last","langKey":"en-US","enabled":false}
@RequestMapping(value = "/register", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<?> registerAccount(@Valid @RequestBody User userDTO) {
        User user = null;
        if (/* user authenticating */) {
            return ResponseEntity.badRequest()
                    .contentType(MediaType.TEXT_PLAIN)
                    .body(error);
        } else {
            user = userService.createUserInformation(userDTO.getUsername().toLowerCase(), encoder.encode(userDTO.getPassword()), userDTO.getFirstName(), userDTO.getLastName(), userDTO.getLangKey());

            mailService.sendEmail(user, env.getRequiredProperty("default.mail."+env.getRequiredProperty("spring.profiles.active")+".url"), MailType.ACTIVATION);
            return new ResponseEntity<>(user, HttpStatus.OK);
        }
    }

我不确定这是什么原因造成的,我相信它是@Valid,但我已经删除了好几次,我仍然得到了这个错误。是否有其他人遇到过这样的问题?如果您能够纠正此问题,请提供用户类代码,并且,您是否可以添加第二个参数BindingResult到方法并打印出结果。getFieldError?通过这种方式,您可以检查它是否与@Valid注释有关。