控制输入前端时间格式及其它常见需求

在dao层加上相应的注解,就可以控制输入前端的数据样式

页面输出格式常用注解----@JsonIgnore,@JsonFormat,@JsonFormat

1.注解名称:@JsonIgnore 作用:在实体类向前台返回数据时用来忽略不想传递给前台的属性或接口。 Eg:User实体中会有字段password字段,

当返回用户信息给前台的时候,当然是不希望将password值也一并返回。所以,这个时候可以在password属性上加上注解JsonIgnore或者,

@JsonIgnore
private String password;
private Integer age;

2.注解名称:@JsonFormat

前台使用固定时间格式时可以在属性名上添加@JsonFormat注解()

@JsonFormat(pattern="yyyy-MM-dd hh:mm:ss a", locale="zh", timezone="GMT+8")
private Date birthday;

3.注解名称:@JsonFormat   不返回null字段数据

在相关对象的类上添加 @JsonInclude 注解,设定值为 NON_NULL
@JsonInclude(Include.NON_NULL)
private String desc;

posted @ 2020-04-11 14:56  lsaac  阅读(438)  评论(0编辑  收藏  举报