我是靠谱客的博主 要减肥机器猫,最近开发中收集的这篇文章主要介绍fasonjson的@JSONField注解 format日期格式,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

比如我们有一个字段在数据库是datetime类型的,但是我们又需传给前端“yyyy-MM-dd”这样的格式,这时我们不需要再代码里面去手动用simpledateformat或者DateTimeFormatter去转,这样很转很麻烦的。
我们可以使用fasonjson的@JSONField注解,来format成任意我们想要的格式。

package 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 {
@JSONField(name="test_date",format = "yyyy-MM-dd")
private Date testDate`;

最后

以上就是要减肥机器猫为你收集整理的fasonjson的@JSONField注解 format日期格式的全部内容,希望文章能够帮你解决fasonjson的@JSONField注解 format日期格式所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部