spring学习笔记(二十六)springboot_web开发

1.解决上节课程遇到的问题

添加员工页面
添加员工页面

在添加员工信息的时候之后,点击添加没有成功跳转到员工列表页,员工信息也没有添加成功

看标题像是请求了一个get方法,检查代码也没有检查出来问题,debug发现是添加信息之后的后续操作action没有添加,默认也是get方法

<form>
	<div class="form-group">
		<label>LastName</label>
		<input name="lastName" type="text" class="form-control" placeholder="zhangsan">
	</div>
	<div class="form-group">
		<label>Email</label>

修改成.....

<form th:action="@{/emp}"  method ="post">
	<div class="form-group">
		<label>LastName</label>
		<input name="lastName" type="text" class="form-control" placeholder="zhangsan">
	</div>
 

2.添加信息后报404错误,查看日志报错“Field error in object 'employee' on field 'birth': rejected value [2019-08-23]; codes [typeMismatch.employee.birth,typeMismatch.birth,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [employee.birth,birth]; arguments []; default message [birth]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'birth'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.util.Date] for value '2019-08-23'; nested exception is java.lang.IllegalArgumentException]]”

提交的数据格式不对:不支持2019-08-23这种格式,只支持2017/12/12这种格式

日期的格式化;SpringMVC将页面提交的值需要转换为指定的类型;

默认日期是按照/的方式;

在配置文件中配置数据格式方式

spring.mvc.date-format=yyyy-MM-dd

查看源码: 

WebMvcAutoConfiguration.java

@Bean
@ConditionalOnProperty(
    prefix = "spring.mvc",
    name = {"date-format"}
)
public Formatter<Date> dateFormatter() {
   return new DateFormatter(this.mvcProperties.getDateFormat());
}


WebMvcProperties.java
//默认格式 yyyy/MM/dd
public String getDateFormat() {
   return this.dateFormat;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值