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 即可
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:
- 2.0
- Author:
- Juergen Hoeller
- See Also:
- DataBinder
- Errors
- Validator
- BeanPropertyBindingResult
- DirectFieldBindingResult
- MapBindingResult

spring boot 开发 提交form表单出错的更多相关文章
- 使用ajax提交form表单,包括ajax文件上传 转http://www.cnblogs.com/zhuxiaojie/p/4783939.html
使用ajax提交form表单,包括ajax文件上传 前言 使用ajax请求数据,很多人都会,比如说: $.post(path,{data:data},function(data){ ... },&qu ...
- 按下回车默认提交form表单问题
最近开发中碰到一个问题,项目中有几个列表展示页面,允许用户通过查询条件模糊查询数据.用户录入关键字后点击回车会调用查询方法根据关键字查询,原先功能没有问题,但是最近发现在查询输入框中按下回车会直接刷新 ...
- ajax提交form表单
1. ajax提交form表单和不同的form表单的提交主要区别在于,ajax提交表单是异步提交的,而普通的是同步提交的表单. 2. from视图部分 <form id="loginF ...
- Jquery通过Ajax方式来提交Form表单
今天刚好看到Jquery的ajax提交数据到服务器的方法,原文是: 保存数据到服务器,成功时显示信息. jQuery 代码: $.ajax({ type: "POST", url: ...
- ajax提交form表单资料详细汇总
一.ajax提交form表单和不同的form表单的提交主要区别在于,ajax提交表单是异步提交的,而普通的是同步提交的表单.通过在后台与服务器进行少量数据交换,ajax 可以使网页实现异步更新.这意味 ...
- 导出excel用ajax不行,提交form表单可以
导出excel用ajax不行,提交form表单可以. 一直用ajax找原因,网页不出现下载提示框 写了 response.setContentType("application/binary ...
- C# 模拟提交 Form表单的数据
用 HttpWebRequest Post方法模拟提交Form表单数据时,需要设置 ContentType 为 "application/x-www-form-urlencoded" ...
- 提交form表单不刷新页面案列
提交form表单不刷新页面其实很简单的,这里拿上传图片来举列,大家有什么其它的方法也欢迎留言告知与我 <form action="" method="post&qu ...
- jquery实现ajax提交form表单的方法总结
本篇文章主要是对jquery实现ajax提交form表单的方法进行了总结介绍,需要的朋友可以过来参考下,希望对大家有所帮助 方法一: function AddHandlingFeeToRefund( ...
随机推荐
- css中外边距
1.内部元素设置margin等,父元素高度不能适应 .classA { height: 200px; background-color: cornflowerblue; overflow: hidde ...
- iOS UI基础-5.0 QQ框架(Storyboard)
1.拉入TabBarController和4个Navigation 2.TabBarController关联Navigation 3.设置消息,拉入一个Button,设置背影 4.联系人,拉入一个Se ...
- python 安装 Scrapy 模块
环境的安装总是让人多愁善感,爱恨交叉... 本人安装环境:win7 64 + python2.7 先来几个网站 https://doc.scrapy.org/en/latest/intro/insta ...
- SQL Server查询中特殊字符的处理方法
SQL Server查询中,经常会遇到一些特殊字符,比如单引号“'”等,这些字符的处理方法,是SQL Server用户都应该需要知道的. 我们都知道SQL Server查询过程中,单引号“'”是特殊字 ...
- ArrayList(JDK1.9)
一.ArrayList概念. 1.数据结构.它是一个数组,可以动态增长的数组. 2.继承实现关系图.继承抽象List,实现List.随机方法.克隆.序列化. 3. 二.内部类. final class ...
- VC++文件操作之最全篇
一.剖析VC中的文件操作 各种关于文件的操作在程序设计中是十分常见,如果能对其各种操作都了如指掌,就可以根据实际情况找到最佳的解决方案,从而在较短的时间内编写出高效的代码,因而熟练的掌握文件操作是十分 ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON HistoToThresh1
zw版[转发·台湾nvp系列Delphi例程]HALCON HistoToThresh1 procedure TForm1.Button1Click(Sender: TObject);var imag ...
- linux常用命令:ln 命令
ln是linux中又一个非常重要命令,它的功能是为某一个文件在另外一个位置建立一个同步的链接.当我们需要在不同的目录,用到相同的文件时,我们不需要在每一个需要的目录下都放一个必须相同的文件,我们只要在 ...
- 20165207 Exp3 免杀原理与实践
Exp3 免杀原理与实践 1.实验内容 1.1.使用msf 1.1.1. 确定基准线 首先看kali的ip 直接msfvenom的结果,不加其他的东西: 使用VirusTotal得到的检测这个程序得到 ...
- java多线程----ReentrantReadWriteLock
package com.test; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks ...
