济南手机网站定制费用,注册公司代理费用标准,找i满洲做卖房广告不收费的网站,内网网站建设主流语言超简单#xff0c;顺带记录一下 1.入参实体类上使用注释#xff1a;JsonFormat(pattern “yyyy-MM-dd”) 导致舍弃了 时分秒的部分。 2.数据库字段对应的类型是 date。date就是日期#xff0c;日期就不带时分秒。 3.返参实体类使用了JsonFormat(pattern “yyyy-MM-dd”) 导… 超简单顺带记录一下 1.入参实体类上使用注释JsonFormat(pattern “yyyy-MM-dd”) 导致舍弃了 时分秒的部分。 2.数据库字段对应的类型是 date。date就是日期日期就不带时分秒。 3.返参实体类使用了JsonFormat(pattern “yyyy-MM-dd”) 导致舍弃了时分秒部分。
扩展 关于注解JsonFormat
General-purpose annotation used for configuring details of how values of properties are to be serialized. Unlike most other Jackson annotations, annotation does not have specific universal interpretation: instead, effect depends on datatype of property being annotated (or more specifically, deserializer and serializer being used). p Common uses include choosing between alternate representations -- for example, whether {link java.util.Date} is to be serialized as number (Java timestamp) or String (such as ISO-8601 compatible time value) -- as well as configuring exact details with {link pattern} property. p As of Jackson 2.6, known special handling includes: ul li{link java.util.Date}: Shape can be {link ShapeSTRING} or {link ShapeNUMBER}; pattern may contain {link java.text.SimpleDateFormat}-compatible pattern definition. li liCan be used on Classes (types) as well, for modified default behavior, possibly overridden by per-property annotation li li{link java.lang.Enum}s: Shapes {link ShapeSTRING} and {link ShapeNUMBER} can be used to change between numeric (index) and textual (name or codetoString()code); but it is also possible to use {link ShapeOBJECT} to serialize (but not deserialize) {link java.lang.Enum}s as JSON Objects (as if they were POJOs). NOTE: serialization as JSON Object only works with class annotation; will not work as per-property annotation. li li{link java.util.Collection}s can be serialized as (and deserialized from) JSON Objects, if {link ShapeOBJECT} is used. NOTE: can ONLY be used as class annotation; will not work as per-property annotation. li li{link java.lang.Number} subclasses can be serialized as full objects if {link ShapeOBJECT} is used. Otherwise the default behavior of serializing to a scalar number value will be preferred. NOTE: can ONLY be used as class annotation; will not work as per-property annotation. li ul机器翻译通用注释用于配置如何序列化属性值的详细信息。与大多数其他 Jackson 注释不同注释没有特定的通用解释相反效果取决于被注释的属性的数据类型或者更具体地说使用的反序列化器和序列化器。p 常见用途包括在替代表示形式之间进行选择——例如{link java.util.Date} 是序列化为数字Java 时间戳还是字符串例如 ISO-8601 兼容的时间值——以及使用 {link pattern} 属性配置确切的详细信息。p 从 Jackson 2.6 开始已知的特殊处理包括 ul li{link java.util.Date}形状可以是 {link ShapeSTRING} 或 {link ShapeNUMBER};pattern 可能包含 {link java.text.SimpleDateFormat} 兼容的模式定义。li li也可以用于类类型用于修改默认行为可能被每个属性的注释 li li{link java.lang.Enum} 覆盖形状 {link ShapeSTRING} 和 {link ShapeNUMBER} 可用于在数字索引和文本name 或 codetoString之间切换code;但也可以使用 {link ShapeOBJECT} 将 {link java.lang.Enum} 序列化但不能反序列化为 JSON 对象就像它们是 POJO 一样。注意序列化为 JSON Object 仅适用于类注释;将不用作每个属性的注释。li li如果使用 {link ShapeOBJECT}则 {link java.util.Collection} 可以序列化为 JSON 对象并从中反序列化。注意只能用作类注释;将不用作每个属性的注释。li li如果使用 {link ShapeOBJECT}则可以将 {link java.lang.Number} 子类序列化为完整对象。否则将首选序列化为标量数值的默认行为。注意只能用作类注释;将不用作每个属性的注释。li ul补充几个 JsonFormat 的使用方式。
//实体类
Data
Accessors(chain true)
public class TestJsonFormat {JsonFormat(shape JsonFormat.Shape.NUMBER_INT)private Integer sendDate;JsonFormat(shape JsonFormat.Shape.STRING)private String str;JsonFormat(shape JsonFormat.Shape.NUMBER)private Date dateNum;JsonFormat(pattern yyyy-MM-dd)private Date getDate;
}
//接口定义GetMapping(/testJsonFormat)public AjaxResult testJsonFormat(RequestBody TestJsonFormat format) {format.setDateNum(new Date());return AjaxResult.success(format);}
//接口调用入参
{sendDate: 12.3,str: 333,receiveDate:2023-10-21
}
//打印结果
TestJsonFormat(sendDate12, str333, dateNumnull, receiveDateSat Oct 21 00:00:00 CST 2023)
//返回参数
{msg: 操作成功,code: 200,data: {sendDate: 12,str: 333,dateNum: 1734569603473,receiveDate: 2023-10-21}
}
可以看到
1、JsonFormat(shape JsonFormat.Shape.NUMBER_INT)将接收数据转换成了整形
2、JsonFormat(shape JsonFormat.Shape.STRING)将接收数据转换成了字符串类型
3、JsonFormat(shape JsonFormat.Shape.NUMBER)将返回的数据转换成了数字类型时间戳
4、JsonFormat(pattern yyyy-MM-dd)将字符串类型的时间转换成了对象又以指定格式返回字符串