当前位置:网站首页>@JsonFormat和@DateTimeFormat的区别和使用
@JsonFormat和@DateTimeFormat的区别和使用
2022-07-26 10:46:00 【Eric-x】
@DatetimeFormat是将String转换成Date,一般前台给后台传值时用
import org.springframework.format.annotation.DateTimeFormat;
/** * 前台传后台时, 字符串自动封装成日期 */
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date birth;
@JsonFormat(pattern=”yyyy-MM-dd”) 将Date转换成String 一般后台传值给前台时
import com.fasterxml.jackson.annotation.JsonFormat;
/** * 后台返给前台时, 日期自动格式化 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date birth;
注意
@JsonFormat不仅可以完成后台到前台参数传递的类型转换,还可以实现前台到后台类型转换。
当content-type为application/json时,优先使用@JsonFormat的pattern进行类型转换。而不会使用@DateTimeFormat进行类型转换。
@JsonFormat注解的作用就是完成json字符串到java对象的转换工作,与参数传递的方向无关。
然后:@DateTimeFormat和@JsonFormat分别属于Spring和Jackson
参考链接:https://www.cnblogs.com/wq-9/articles/12000799.html
边栏推荐
猜你喜欢

Flutter编译报错 version of NDK matched the requested version 21.0.6113669. Versions available locally: 2

使用Selenium抓取zabbix性能监控图

文案秘籍七步曲至----文献团队协作管理
![Error[Pe147]: declaration is incompatible with '错误问题](/img/4f/57145d78f4dc1fe84d2f271dd9d82f.png)
Error[Pe147]: declaration is incompatible with '错误问题

mysql20210906
![Error[pe147]: declaration is incompatible with 'error problem](/img/4f/57145d78f4dc1fe84d2f271dd9d82f.png)
Error[pe147]: declaration is incompatible with 'error problem

RT thread learning notes (VII) -- open the elmfat file system based on SPI flash (middle)

Issue 5: the second essential skill for College Students

el-table实现可编辑表格

Add touch screen driver for stemwin 5.22 on Shenzhou IV development board
随机推荐
PLC与伺服电机连接
LIst和Dictionary实例应用(※)
Issue 5: the second essential skill for College Students
Anaconda is used on vscode (the environment has been configured)
px2rem-loader将px转化为rem,适配移动端vant-UI等框架
【小程序】onReachBottom 事件为什么不能触发 ?(一秒搞定)
putty的使用教程
[leetcode daily question 2021/4/23]368. Maximum divisible subset
(转载)ArcGIS Engine中各种点的创建方法
Analysis of the transaction problem of chained method call
SQL Server 之Sql语句创建数据库
20210807#1 C语言程序结构
工厂模式详解
MFC图片控件
2021-08-12函数递归_和鹏哥学习C语言
Common classes (understand)
反射机制简述
鹏哥C语言第六节课
Issue 7: how do you choose between curling up and lying flat
[machine learning notes] [face recognition] deeplearning ai course4 4th week programming