简介
本文用示例说明SpringBoot的@Validated的用法。
代码结构
依赖
必须引入此依赖,否则校验会无效。而且@Validated是SpringBoot增强的依赖,所以必须引入上边这个依赖。
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> </dependency>
它里边依赖了hibernate validator,就是下边这个。
<dependency> <groupId>org.hibernate.validator</groupId> <artifactId>hibernate-validator</artifactId> </dependency>
用法1:不分组
代码
Controller
package com.knife.example.business.user.without_group.controller; import com.knife.example.business.user.without_group.bo.UserBO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.validation.BindingResult; import org.springframework.validation.ObjectError; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.List; @Api(tags = "不分组") @RestController @RequestMapping("validatedWithoutGroup") public class ValidatedWithoutGroupController { @ApiOperation("正常用法") @PostMapping("normal") public UserBO normal(@Validated @RequestBody UserBO userBO) { return userBO; } @ApiOperation("获得BindingResult") @PostMapping("bindingResult") public UserBO bindingResult(@Validated UserBO userBO, BindingResult bindingResult) { if (bindingResult.hasErrors()){ List<ObjectError> list = bindingResult.getAllErrors(); for (ObjectError objectError : list) { System.out.println(objectError.getDefaultMessage()); } //System.out.println(bindingResult.getFieldError().getDefaultMessage()); } return userBO; } }
BO
UserBO
package com.knife.example.business.user.without_group.bo; import lombok.Data; import javax.validation.Valid; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import java.util.List; @Data public class UserBO { @NotBlank(message = "名字不能为空") private String name; private Integer age; @NotBlank(message = "密码不能为空") private String password; @NotEmpty(message = "分数不能为空") private List<Integer> scoreArray; @Valid @NotNull(message = "账户不能为空") private AccountBO accountBO; @Valid @NotNull(message = "账户列表不能为空") private List<AccountBO> accountBOList; }
AccountBO
package com.knife.example.business.user.without_group.bo; import lombok.Data; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; @Data public class AccountBO { @NotNull(message = "账户ID不能为空") private Long id; @NotBlank(message = "电话号码不能为空") private String phoneNumber; private String[] emails; }
测试
测试1:缺少字段
可以发现:和最外侧使用@Valid是一样的:所有位置的校验都是有效的,包括:顶层实体类、普通字段、数组字段、包装类字段、包装类列表字段。
后端结果:
2023-10-16 16:33:42.454 ERROR 25004 --- [nio-8080-exec-4] c.k.e.c.advice.GlobalExceptionAdvice : 参数校验异常 org.springframework.web.bind.MethodArgumentNotValidException: Validation failed for argument [0] in public com.knife.example.business.user.without_group.bo.UserBO com.knife.example.business.user.without_group.controller.ValidatedWithoutGroupController.normal(com.knife.example.business.user.without_group.bo.UserBO) with 5 errors: [Field error in object 'userBO' on field 'scoreArray': rejected value [[]]; codes [NotEmpty.userBO.scoreArray,NotEmpty.scoreArray,NotEmpty.java.util.List,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [userBO.scoreArray,scoreArray]; arguments []; default message [scoreArray]]; default message [分数不能为空]] [Field error in object 'userBO' on field 'name': rejected value []; codes [NotBlank.userBO.name,NotBlank.name,NotBlank.java.lang.String,NotBlank]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [userBO.name,name]; arguments []; default message [name]]; default message [名字不能为空]] [Field error in object 'userBO' on field 'accountBO.phoneNumber': rejected value []; codes [NotBlank.userBO.accountBO.phoneNumber,NotBlank.accountBO.phoneNumber,NotBlank.phoneNumber,NotBlank.java.lang.String,NotBlank]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [userBO.accountBO.phoneNumber,accountBO.phoneNumber]; arguments []; default message [accountBO.phoneNumber]]; default message [电话号码不能为空]] [Field error in object 'userBO' on field 'password': rejected value []; codes [NotBlank.userBO.password,NotBlank.password,NotBlank.java.lang.String,NotBlank]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [userBO.password,password]; arguments []; default message [password]]; default message [密码不能为空]] [Field error in object 'userBO' on field 'accountBOList[0].id': rejected value [null]; codes [NotNull.userBO.accountBOList[0].id,NotNull.userBO.accountBOList.id,NotNull.accountBOList[0].id,NotNull.accountBOList.id,NotNull.id,NotNull.java.lang.Long,NotNull]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [userBO.accountBOList[0].id,accountBOList[0].id]; arguments []; default message [accountBOList[0].id]]; default message [账户ID不能为空]] at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:141) ~[spring-webmvc-5.3.13.jar:5.3.13] at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121) ~[spring-web-5.3.13.jar:5.3.13] at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:179) ~[spring-web-5.3.13.jar:5.3.13] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:146) ~[spring-web-5.3.13.jar:5.3.13] //... 省略 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) [spring-webmvc-5.3.13.jar:5.3.13] at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) [spring-webmvc-5.3.13.jar:5.3.13] at javax.servlet.http.HttpServlet.service(HttpServlet.java:681) [tomcat-embed-core-9.0.55.jar:4.0.FR] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) [spring-webmvc-5.3.13.jar:5.3.13]
请求体:
{ "accountBO": { "emails": [], "id": 2, "phoneNumber": "" }, "accountBOList": [ { "emails": [], "id": null, "phoneNumber": "12345" } ], "age": 0, "name": "", "password": "", "scoreArray": [] }
测试2:不缺少字段
可以看到,接口没有报错。
请求体:
{ "accountBO": { "emails": ["123@qq.com"], "id": 2, "phoneNumber": "123" }, "accountBOList": [ { "emails": ["11@qq.com"], "id": 3, "phoneNumber": "12345" } ], "age": 0, "name": "Tony", "password": "abbb", "scoreArray": [95,98] }
测试3: 获得BindingResult
可以发现,正常返回。结果和最外层使用@Valid是一样的。
后端结果:
分数不能为空 账户ID不能为空 电话号码不能为空 名字不能为空 密码不能为空
用法2:分组
Controller
package com.knife.example.business.user.with_group.controller; import com.knife.example.business.user.with_group.bo.UserBO; import com.knife.example.business.user.with_group.group.IGroupA; import com.knife.example.business.user.with_group.group.IGroupAll; import com.knife.example.business.user.with_group.group.IGroupB; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @Api(tags = "分组") @RestController @RequestMapping("validatedWithGroup") public class ValidatedWithGroupController { @ApiOperation("使用组:GroupA") @PostMapping("groupA") public UserBO groupA(@Validated({IGroupA.class}) @RequestBody UserBO userBO) { return userBO; } @ApiOperation("使用组:GroupB") @PostMapping("groupB") public UserBO groupB(@Validated({IGroupB.class}) @RequestBody UserBO userBO) { return userBO; } @ApiOperation("使用组:GroupA和GroupB") @PostMapping("groupAAndGroupB") public UserBO groupAAndGroupB(@Validated({IGroupA.class, IGroupB.class}) @RequestBody UserBO userBO) { return userBO; } @ApiOperation("使用组:GroupAll") @PostMapping("groupAll") public UserBO groupAll(@Validated({IGroupAll.class}) @RequestBody UserBO userBO) { return userBO; } }
BO
UserBO
package com.knife.example.business.user.with_group.bo; import com.knife.example.business.user.with_group.group.IGroupA; import com.knife.example.business.user.with_group.group.IGroupB; import lombok.Data; import javax.validation.Valid; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import java.util.List; @Data public class UserBO { @NotBlank(message = "名字不能为空") private String name; @NotNull(message = "年龄不能为空", groups = {IGroupA.class}) private Integer age; @NotEmpty(message = "密码不能为空", groups = {IGroupB.class}) private String password; @NotEmpty(message = "分数不能为空", groups = {IGroupA.class, IGroupB.class}) private List<Integer> scoreArray; @Valid @NotNull(message = "账户不能为空") private AccountBO accountBO; @Valid @NotEmpty(message = "账户列表不能为空") private List<AccountBO> accountBOList; }
AccountBO
package com.knife.example.business.user.with_group.bo; import com.knife.example.business.user.with_group.group.IGroupA; import com.knife.example.business.user.with_group.group.IGroupB; import lombok.Data; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; @Data public class AccountBO { @NotNull(message = "账户ID不能为空", groups = {IGroupA.class} ) private Long id; @NotBlank(message = "电话号码不能为空", groups = {IGroupB.class}) private String phoneNumber; private String[] emails; }
Group
IGroupA接口
package com.knife.example.business.user.with_group.group; public interface IGroupA { }
IGroupB接口
package com.knife.example.business.user.with_group.group; public interface IGroupB { }
IGroupAll接口
package com.knife.example.business.user.with_group.group; import javax.validation.GroupSequence; import javax.validation.groups.Default; @GroupSequence({Default.class, IGroupA.class, IGroupB.class}) public interface IGroupAll { }
测试
下载源码
此隐藏内容仅限VIP查看升级VIP
测试1:缺参数请求GroupA
可以发现:GroupA的校验生效了(列表形式的包装类字段也生效了)。
后端结果:
2023-10-16 16:53:28.434 ERROR 21312 --- [nio-8080-exec-4] c.k.e.c.advice.GlobalExceptionAdvice : 参数校验异常 org.springframework.web.bind.MethodArgumentNotValidException: Validation failed for argument [0] in public com.knife.example.business.user.with_group.bo.UserBO com.knife.example.business.user.with_group.controller.ValidatedWithGroupController.groupA(com.knife.example.business.user.with_group.bo.UserBO) with 2 errors: [Field error in object 'userBO' on field 'accountBOList[0].id': rejected value [null]; codes [NotNull.userBO.accountBOList[0].id,NotNull.userBO.accountBOList.id,NotNull.accountBOList[0].id,NotNull.accountBOList.id,NotNull.id,NotNull.java.lang.Long,NotNull]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [userBO.accountBOList[0].id,accountBOList[0].id]; arguments []; default message [accountBOList[0].id]]; default message [账户ID不能为空]] [Field error in object 'userBO' on field 'scoreArray': rejected value [[]]; codes [NotEmpty.userBO.scoreArray,NotEmpty.scoreArray,NotEmpty.java.util.List,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [userBO.scoreArray,scoreArray]; arguments []; default message [scoreArray]]; default message [分数不能为空]] at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:141) ~[spring-webmvc-5.3.13.jar:5.3.13] at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121) ~[spring-web-5.3.13.jar:5.3.13] at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:179) ~[spring-web-5.3.13.jar:5.3.13] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:146) ~[spring-web-5.3.13.jar:5.3.13] // ...省略 org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) ~[spring-webmvc-5.3.13.jar:5.3.13] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) [spring-webmvc-5.3.13.jar:5.3.13] at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) [spring-webmvc-5.3.13.jar:5.3.13] at javax.servlet.http.HttpServlet.service(HttpServlet.java:681) [tomcat-embed-core-9.0.55.jar:4.0.FR] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) [spring-webmvc-5.3.13.jar:5.3.13]
请求体:
{ "accountBO": { "emails": [], "id": 2, "phoneNumber": "" }, "accountBOList": [ { "emails": [], "id": null, "phoneNumber": "12345" } ], "age": 0, "name": "", "password": "", "scoreArray": [] }
测试2:缺参数请求groupB
可以发现:GroupB的校验生效了(列表形式的包装类字段也生效了)。
后端结果:
2023-10-16 16:56:01.352 ERROR 21312 --- [nio-8080-exec-6] c.k.e.c.advice.GlobalExceptionAdvice : 参数校验异常 org.springframework.web.bind.MethodArgumentNotValidException: Validation failed for argument [0] in public com.knife.example.business.user.with_group.bo.UserBO com.knife.example.business.user.with_group.controller.ValidatedWithGroupController.groupB(com.knife.example.business.user.with_group.bo.UserBO) with 3 errors: [Field error in object 'userBO' on field 'scoreArray': rejected value [[]]; codes [NotEmpty.userBO.scoreArray,NotEmpty.scoreArray,NotEmpty.java.util.List,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [userBO.scoreArray,scoreArray]; arguments []; default message [scoreArray]]; default message [分数不能为空]] [Field error in object 'userBO' on field 'password': rejected value []; codes [NotEmpty.userBO.password,NotEmpty.password,NotEmpty.java.lang.String,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [userBO.password,password]; arguments []; default message [password]]; default message [密码不能为空]] [Field error in object 'userBO' on field 'accountBO.phoneNumber': rejected value []; codes [NotBlank.userBO.accountBO.phoneNumber,NotBlank.accountBO.phoneNumber,NotBlank.phoneNumber,NotBlank.java.lang.String,NotBlank]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [userBO.accountBO.phoneNumber,accountBO.phoneNumber]; arguments []; default message [accountBO.phoneNumber]]; default message [电话号码不能为空]] at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:141) ~[spring-webmvc-5.3.13.jar:5.3.13] at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121) ~[spring-web-5.3.13.jar:5.3.13] // ...省略 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) [spring-webmvc-5.3.13.jar:5.3.13] at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) [spring-webmvc-5.3.13.jar:5.3.13] at javax.servlet.http.HttpServlet.service(HttpServlet.java:681) [tomcat-embed-core-9.0.55.jar:4.0.FR] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) [spring-webmvc-5.3.13.jar:5.3.13]
测试3:缺参数请求GroupA和GroupB
可以发现:GroupA和GroupB的校验生效了(列表形式的包装类字段也生效了)。
后端结果:
2023-10-16 16:58:16.515 ERROR 21312 --- [nio-8080-exec-8] c.k.e.c.advice.GlobalExceptionAdvice : 参数校验异常 org.springframework.web.bind.MethodArgumentNotValidException: Validation failed for argument [0] in public com.knife.example.business.user.with_group.bo.UserBO com.knife.example.business.user.with_group.controller.ValidatedWithGroupController.groupAAndGroupB(com.knife.example.business.user.with_group.bo.UserBO) with 4 errors: [Field error in object 'userBO' on field 'scoreArray': rejected value [[]]; codes [NotEmpty.userBO.scoreArray,NotEmpty.scoreArray,NotEmpty.java.util.List,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [userBO.scoreArray,scoreArray]; arguments []; default message [scoreArray]]; default message [分数不能为空]] [Field error in object 'userBO' on field 'accountBO.phoneNumber': rejected value []; codes [NotBlank.userBO.accountBO.phoneNumber,NotBlank.accountBO.phoneNumber,NotBlank.phoneNumber,NotBlank.java.lang.String,NotBlank]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [userBO.accountBO.phoneNumber,accountBO.phoneNumber]; arguments []; default message [accountBO.phoneNumber]]; default message [电话号码不能为空]] [Field error in object 'userBO' on field 'password': rejected value []; codes [NotEmpty.userBO.password,NotEmpty.password,NotEmpty.java.lang.String,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [userBO.password,password]; arguments []; default message [password]]; default message [密码不能为空]] [Field error in object 'userBO' on field 'accountBOList[0].id': rejected value [null]; codes [NotNull.userBO.accountBOList[0].id,NotNull.userBO.accountBOList.id,NotNull.accountBOList[0].id,NotNull.accountBOList.id,NotNull.id,NotNull.java.lang.Long,NotNull]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [userBO.accountBOList[0].id,accountBOList[0].id]; arguments []; default message [accountBOList[0].id]]; default message [账户ID不能为空]] at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:141) ~[spring-webmvc-5.3.13.jar:5.3.13] at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121) ~[spring-web-5.3.13.jar:5.3.13] // ...省略 org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.13.jar:5.3.13] org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) [spring-webmvc-5.3.13.jar:5.3.13] at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) [spring-webmvc-5.3.13.jar:5.3.13] at javax.servlet.http.HttpServlet.service(HttpServlet.java:681) [tomcat-embed-core-9.0.55.jar:4.0.FR] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) [spring-webmvc-5.3.13.jar:5.3.13]
请求体:
{ "accountBO": { "emails": [], "id": 2, "phoneNumber": "" }, "accountBOList": [ { "emails": [], "id": null, "phoneNumber": "12345" } ], "age": 0, "name": "", "password": "", "scoreArray": [] }
测试4:缺参数请求GroupAll
可以看到:走的是除了IGroupA和IGroupB注解的字段的逻辑。
后端结果:
2023-10-16 17:01:23.177 ERROR 21312 --- [io-8080-exec-10] c.k.e.c.advice.GlobalExceptionAdvice : 参数校验异常 org.springframework.web.bind.MethodArgumentNotValidException: Validation failed for argument [0] in public com.knife.example.business.user.with_group.bo.UserBO com.knife.example.business.user.with_group.controller.ValidatedWithGroupController.groupAll(com.knife.example.business.user.with_group.bo.UserBO): [Field error in object 'userBO' on field 'name': rejected value []; codes [NotBlank.userBO.name,NotBlank.name,NotBlank.java.lang.String,NotBlank]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [userBO.name,name]; arguments []; default message [name]]; default message [名字不能为空]] at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:141) ~[spring-webmvc-5.3.13.jar:5.3.13] at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121) ~[spring-web-5.3.13.jar:5.3.13] // ... 省略 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) [spring-webmvc-5.3.13.jar:5.3.13] at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) [spring-webmvc-5.3.13.jar:5.3.13] at javax.servlet.http.HttpServlet.service(HttpServlet.java:681) [tomcat-embed-core-9.0.55.jar:4.0.FR] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) [spring-webmvc-5.3.13.jar:5.3.13]
将错误提示出来
本文将参数非法这种异常统一提示到了前端,用了全局异常处理(捕获MethodArgumentNotValidException异常)。如果不用异常处理,后端打印信息会很多:
2023-10-15 19:45:17.549 WARN 1920 --- [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.bind.MethodArgumentNotValidException: Validation failed for argument [0] in public com.example.demo.business.valid.entity.User com.example.demo.business.valid.controller.ValidController.normal(com.example.demo.business.valid.entity.User) with 5 errors: [Field error in object 'user' on field 'account.phoneNumber': rejected value []; codes [NotBlank.user.account.phoneNumber,NotBlank.account.phoneNumber,NotBlank.phoneNumber,NotBlank.java.lang.String,NotBlank]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [user.account.phoneNumber,account.phoneNumber]; arguments []; default message [account.phoneNumber]]; default message [电话号码不能为空]] [Field error in object 'user' on field 'name': rejected value []; codes [NotBlank.user.name,NotBlank.name,NotBlank.java.lang.String,NotBlank]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [user.name,name]; arguments []; default message [name]]; default message [名字不能为空]] [Field error in object 'user' on field 'password': rejected value []; codes [NotBlank.user.password,NotBlank.password,NotBlank.java.lang.String,NotBlank]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [user.password,password]; arguments []; default message [password]]; default message [密码不能为空]] [Field error in object 'user' on field 'scoreArray': rejected value [[]]; codes [NotEmpty.user.scoreArray,NotEmpty.scoreArray,NotEmpty.java.util.List,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [user.scoreArray,scoreArray]; arguments []; default message [scoreArray]]; default message [分数不能为空]] [Field error in object 'user' on field 'accountList[0].id': rejected value [null]; codes [NotNull.user.accountList[0].id,NotNull.user.accountList.id,NotNull.accountList[0].id,NotNull.accountList.id,NotNull.id,NotNull.java.lang.Long,NotNull]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [user.accountList[0].id,accountList[0].id]; arguments []; default message [accountList[0].id]]; default message [账户ID不能为空]] ]
下载源码
此隐藏内容仅限VIP查看升级VIP
请先
!