其他分享
首页 > 其他分享> > @JsonFormat和@DateTimeFormat的作用

@JsonFormat和@DateTimeFormat的作用

作者:互联网

原文链接:https://blog.csdn.net/wddbq/article/details/79632534

https://blog.csdn.net/wddbq/article/details/79632534

 

 

 

 大部分开发者都知道,在SpringMvc中@JsonFormat用于将后台返回前台的Date变量转换为字符串类型;而@DateTimeFormat用于将前台传到后台字符串变量转换为Date类型。

    今天针对这两个注解亲自测试了一下。@JsonFormat不仅可以完成后台到前台参数传递的类型转换,还可以实现前台到后台类型转换。当content-type为application/json时,优先使用@JsonFormat的pattern进行类型转换。而不会使用@DateTimeFormat进行类型转换。

    个人理解,@JsonFormat注解的作用就是完成json字符串到java对象的转换工作,与参数传递的方向无关。springmvc中如何使用这两个注解的,需要深入研究(有深入了解的,欢迎留言交流)。
 

标签:类型转换,JsonFormat,后台,前台,DateTimeFormat,注解,作用
来源: https://blog.csdn.net/wangpailiulanqi8/article/details/100652713