比如我们有一个字段在数据库是datetime类型的,但是我们又需传给前端“yyyy-MM-dd”这样的格式,这时我们不需要再代码里面去手动用simpledateformat或者DateTimeFormatter去转,这样很转很麻烦的。
我们可以使用fasonjson的@JSONField注解,来format成任意我们想要的格式。
复制代码
1
2
3
4
5
6
7
8
9
10
11package com.alibaba.fastjson.annotation; import com.alibaba.fastjson.parser.Feature; import com.alibaba.fastjson.serializer.SerializerFeature; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) public @interface JSONField {
复制代码
1
2
3@JSONField(name="test_date",format = "yyyy-MM-dd") private Date testDate`;
最后
以上就是要减肥机器猫最近收集整理的关于fasonjson的@JSONField注解 format日期格式的全部内容,更多相关fasonjson的@JSONField注解内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复