spring boot 开发 提交form表单出错
?
?
提交表單時,字段有的沒有值,springboot 會報錯。
org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 4 errors
Field error in object 'stone' on field 'stone_purchdate': rejected value [2018-05-11T16:00:00.000+0000]; codes [typeMismatch.stone.stone_purchdate,typeMismatch.stone_purchdate,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [stone.stone_purchdate,stone_purchdate]; arguments []; default message [stone_purchdate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'stone_purchdate'; nested exception is java.lang.IllegalArgumentException: Could not parse date: Unparseable date: "2018-05-11T16:00:00.000+0000"]
Field error in object 'stone' on field 'stone_substoPramt': rejected value []; codes [typeMismatch.stone.stone_substoPramt,typeMismatch.stone_substoPramt,typeMismatch.double,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [stone.stone_substoPramt,stone_substoPramt]; arguments []; default message [stone_substoPramt]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'double' for property 'stone_substoPramt'; nested exception is java.lang.NumberFormatException: empty String]
Field error in object 'stone' on field 'stone_substoPrperct': rejected value []; codes [typeMismatch.stone.stone_substoPrperct,typeMismatch.stone_substoPrperct,typeMismatch.double,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [stone.stone_substoPrperct,stone_substoPrperct]; arguments []; default message [stone_substoPrperct]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'double' for property 'stone_substoPrperct'; nested exception is java.lang.NumberFormatException: empty String]
Field error in object 'stone' on field 'stone_substoWgt': rejected value []; codes [typeMismatch.stone.stone_substoWgt,typeMismatch.stone_substoWgt,typeMismatch.double,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [stone.stone_substoWgt,stone_substoWgt]; arguments []; default message [stone_substoWgt]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'double' for property 'stone_substoWgt'; nested exception is java.lang.NumberFormatException: empty String]
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:157) ~[spring-web-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:124) ~[spring-web-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161) [spring-web-5.0.6.RELEASE.jar:5.0.6.RELEASE]
?
?
解決方法:
參數里加上?BindingResult 即可
?
org.springframework.validation.BindingResult?
General interface that represents binding results. Extends the interface for error registration capabilities, allowing for a Validator to be applied, and adds binding-specific analysis and model building.
Serves as result holder for a DataBinder, obtained via the DataBinder.getBindingResult() method. BindingResult implementations can also be used directly, for example to invoke a Validator on it (e.g. as part of a unit test).
Since:?
?
轉載于:https://www.cnblogs.com/lick468/p/9131911.html
總結
以上是生活随笔為你收集整理的spring boot 开发 提交form表单出错的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: .NET Core Community
- 下一篇: 转 linux常用查看硬件设备信息命令