首页 > 其他分享 >【精品】Springboot 接收发送日期类型的数据

【精品】Springboot 接收发送日期类型的数据

时间:2023-10-03 15:01:06浏览次数:41  
标签:typeMismatch 12 java Springboot 发送 beginTime time 精品 type

问题

在这里插入图片描述

无法请求到后台,后台报错:[Failed to convert property value of type 'java.lang.String' to required type 'java.time.LocalDateTime' for property

2023-10-02T09:26:16.069+08:00  WARN 14296 --- [p-nio-80-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.bind.MethodArgumentNotValidException: Validation failed for argument [0] in public com.tiku.common.bean.ResultBean com.tiku.controller.manger.BookController.list(com.tiku.domain.query.BookQuery) with 2 errors: [Field error in object 'bookQuery' on field 'beginTime': rejected value [2000-12-12 12:12:12]; codes [typeMismatch.bookQuery.beginTime,typeMismatch.beginTime,typeMismatch.java.time.LocalDateTime,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [bookQuery.beginTime,beginTime]; arguments []; default message [beginTime]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.time.LocalDateTime' for property 'beginTime'; Failed to convert from type [java.lang.String] to type [java.time.LocalDateTime] for value [2000-12-12 12:12:12]]] [Field error in object 'bookQuery' on field 'endTime': rejected value [2020-12-12 12:12:12]; codes [typeMismatch.bookQuery.endTime,typeMismatch.endTime,typeMismatch.java.time.LocalDateTime,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [bookQuery.endTime,endTime]; arguments []; default message [endTime]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.time.LocalDateTime' for property 'endTime'; Failed to convert from type [java.lang.String] to type [java.time.LocalDateTime] for value [2020-12-12 12:12:12]]] ]

方式一

在application.yml中添加:

spring:
  mvc:
    format:
      date-time: yyyy-MM-dd HH:mm:ss
  #时间格式:返回格式化日期
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: GMT+8

方式二

在类的属性上添加注解:

//返回时间类型
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
// 接收时间类型
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private LocalDateTime beginTime;

标签:typeMismatch,12,java,Springboot,发送,beginTime,time,精品,type
From: https://blog.51cto.com/lianghecai/7693276

相关文章

  • SpringBoot 配置多数据源 dynamic-datasource(多库)
    1.Maven包com.baomidoudynamic-datasource-spring-boot-starter3.1.12.配置文件###MySQLdruid多数据源配置(纯粹多库)####去除durid配置spring.autoconfigure.exclude=com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure#指定默认数据源(必须配置)spring.d......
  • JDWP调试SpringBoot程序
    JDWP调试SpringBoot程序<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-loader</artifactId></dependency>java-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5050-jar&......
  • Springboot+Echarts+Element(二)
    今天主要是记录一些问题,主要是在使用vue通过axios发送请求的时候,起初我认为需要把vue和springboot整合到一块但是在听完课之后发现并不需要,因为vue的目的是实现前后端分离的开发,因此两个项目可以同时运行,调整vue项目就是改前端代码,调整springboot就是改后端代码,前端只负责发送请......
  • 如何在Linux关闭前向其他系统用户发送自定义消息
    在先前的文章中,我们解释了 Linux 中shutdown、poweroff、halt、reboot 命令的不同之处,并揭示了在用不同的选项执行这些命令时它们实际做了什么。本篇将会向你展示如何在系统关机时向所有的系统用户发送一条自定义的消息。建议阅读:tuptime-显示Linux系统的历史和统计运行......
  • 关于在springboot中开发mybatis来实现前后端分离
    一、分层架构Controller:负责处理用户的请求和响应get请求与post请求的区别:get请求需要的在http协议上输入参数,而post请求不需要在http协议上输入参数,要在请求体中寻找参数。 在一次请求与响应过程中,首先浏览器发起一次请求到服务器,服务器中会有一个前端控制器处理请求,处理......
  • springboot整合sentinel,sleuth
     1. 整合sentinel流控当需要对一个接口进行流量监控时可以使用springboot整合sentinel  (1)在common模块中导入依赖spring-cloud-starter-alibaba-sentinel;  (2)下载sentinel控制台并启动;  (3)配置sentinel控制台地址信息spring.cloud.sentinel.transport.dashboa......
  • springboot第40集:架构师写的代码,那叫一个优雅
    事务的隔离性上,从低到高可能产生的读现象分别是:脏读、不可重复读、幻读。脏读指读到了未提交的数据。不可重复读指一次事务内的多次相同查询,读取到了不同的结果。幻读师不可重复读的特殊场景。一次事务内的多次范围查询得到了不同的结果。通过在写的时候加锁,可以解决脏读。通过在......
  • springboot第40集:架构师写的代码,那叫一个优雅
    事务的隔离性上,从低到高可能产生的读现象分别是:脏读、不可重复读、幻读。脏读指读到了未提交的数据。不可重复读指一次事务内的多次相同查询,读取到了不同的结果。幻读师不可重复读的特殊场景。一次事务内的多次范围查询得到了不同的结果。通过在写的时候加锁,可以解决脏读。通过在读......
  • [SpringBoot 1] 自动装配和Run方法
    SpringBoot1阶段:1SpringBoot自动装配build.gradle中放依赖核心依赖,有很多启动器(spring-boot-start-xxx)@SpringBootApplication@SpringBootConfiguration@Configuration@Component@EnableAutoConfiguration@AutoConfiguration......
  • 邮件发送,附件太大怎么办 → 那就用分卷压缩吧
    开心一刻昨晚,老婆辅导女儿写作业有一道形容妈妈的题,女儿写下了:我妈妈像一个暴躁的老虎老婆拿起题册轻轻敲了下女儿,生气到:有这么形容你妈的吗女儿:你看你现在老婆:我有那么暴躁吗,你就不能说我妈妈像一个公主,温柔大方漂亮?女儿:题目让我造句,没让我造谣!......