提交表单时,字段有的没有值,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表单出错的更多相关文章

  1. 使用ajax提交form表单,包括ajax文件上传 转http://www.cnblogs.com/zhuxiaojie/p/4783939.html

    使用ajax提交form表单,包括ajax文件上传 前言 使用ajax请求数据,很多人都会,比如说: $.post(path,{data:data},function(data){ ... },&qu ...

  2. 按下回车默认提交form表单问题

    最近开发中碰到一个问题,项目中有几个列表展示页面,允许用户通过查询条件模糊查询数据.用户录入关键字后点击回车会调用查询方法根据关键字查询,原先功能没有问题,但是最近发现在查询输入框中按下回车会直接刷新 ...

  3. ajax提交form表单

    1. ajax提交form表单和不同的form表单的提交主要区别在于,ajax提交表单是异步提交的,而普通的是同步提交的表单. 2. from视图部分 <form id="loginF ...

  4. Jquery通过Ajax方式来提交Form表单

    今天刚好看到Jquery的ajax提交数据到服务器的方法,原文是: 保存数据到服务器,成功时显示信息. jQuery 代码: $.ajax({ type: "POST", url: ...

  5. ajax提交form表单资料详细汇总

    一.ajax提交form表单和不同的form表单的提交主要区别在于,ajax提交表单是异步提交的,而普通的是同步提交的表单.通过在后台与服务器进行少量数据交换,ajax 可以使网页实现异步更新.这意味 ...

  6. 导出excel用ajax不行,提交form表单可以

    导出excel用ajax不行,提交form表单可以. 一直用ajax找原因,网页不出现下载提示框 写了 response.setContentType("application/binary ...

  7. C# 模拟提交 Form表单的数据

    用 HttpWebRequest Post方法模拟提交Form表单数据时,需要设置 ContentType 为 "application/x-www-form-urlencoded" ...

  8. 提交form表单不刷新页面案列

    提交form表单不刷新页面其实很简单的,这里拿上传图片来举列,大家有什么其它的方法也欢迎留言告知与我 <form action="" method="post&qu ...

  9. jquery实现ajax提交form表单的方法总结

    本篇文章主要是对jquery实现ajax提交form表单的方法进行了总结介绍,需要的朋友可以过来参考下,希望对大家有所帮助 方法一:  function AddHandlingFeeToRefund( ...

随机推荐

  1. bug管理工具为开发者工作带来哪些改变?

    BUG管理工具的主要功能是对软件开发测试过程中出现的BUG进行跟踪管理,提高开发者的工作效率与工作质量. 在实际工作中,如果没有bug管理工具的帮助,就可能会出现如下一系列的影响: 1.软件测试人员将 ...

  2. linux常用命令:rcp 命令

    rcp代表"remote file copy"(远程文件拷贝). 1.命令格式: rcp [参数] [源文件] [目标文件] 2.命令功能: 功能:  rcp命令用于在计算机之间拷 ...

  3. emoj表情过滤

    用法:  isEmojiCharacter(input_value)   //  提交时候校验.true:emoj表情   undefined:无   if(isEmojiCharacter(val) ...

  4. Java内存管理(一):深入Java内存区域

    本文转自:http://www.cnblogs.com/gw811/archive/2012/10/18/2730117.html#undefined 推荐查看原文,原文格式更好一些. 本文引用自:深 ...

  5. Linux基础命令---mkfs

    mkfs 在磁盘分区上创建ext2.ext3.ext4.ms-dos.vfat文件系统,默认情况下会创建ext2.mkfs用于在设备上构建Linux文件系统,通常是硬盘分区.文件要么是设备名称(例如/ ...

  6. "1130-host ... is not allowed to connect to this MySql server"登录失败

    原因: 该用户没有远程连接权限. 解决:授权! mysql>GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'password' ...

  7. [省选模拟]array

    这题真是太神了! 考试的时候冲着四十分写了个$O(\frac{N^3logN}{32})$的制杖算法. 然后就狠狠的T掉了.如果没有充分的理解单调性和应用单调性就只有10分的傻逼分拿了. 首先考虑枚举 ...

  8. GreenOpenPaint的实现(五)矩形框

    想显示一副图片相对来说比较容易.但是想在SDI中显示一个可以拖拽的矩形框,并且在滚动和缩放下都不变形,是很困难的. MFC应该说在这个方面提供了强大的支持,但是也有一些是由于历史的原因需要去除的地方, ...

  9. AS不能在手机上现在调试软件

    这两天遇到的一个问题,(android studio2.0以上的版本),在在线调试应用的时候,将手机上的此程序卸载了,然后准备重新再AS中将这个程序推送到手机上,可是这时候发现不能推送,Log显示什么 ...

  10. Python3基础 setattr 设置对象的属性值,如果属性不存在就创建

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...