@JsonProperty()和@JsonIgnore()(@Jsonproperty() and @ jsonignore())

记错了注解了,那不到别名的字段:

说来也怪,我的字段名是

   @JsonProperty("OSUnicode")
   private String OSUnicode;

按理说,不加这个注解,泛型也能拿到这个属性的,自动给转换成了osuniCode。所以还是得加,不加就是null

  @JsonProperty() 用以声明dto的字段别名,比方前端传来的是 属性是 prop :1 ,但是我想这个dto创建时将这个prop映射成 name ,就要在着如果属性头上写

前端穿的 属性 prop

@JsonProperty("prop")
private String name;

这样name拿到的就是prop绑定的数据。

  @JsonIgnore()

    1.作用在字段上,可以这个字段给前端传输时去掉,get,set都拿不到数据。

    2.作用在方法上,注解get上,就会发现前端不会显示的数据,注解在set上,后端就拿不到前端传过来的的数据。

————————

Wrong annotation. The alias field cannot be found:

Oddly enough, my field name is

   @JsonProperty("OSUnicode")
   private String OSUnicode;

It is reasonable to say that without this annotation, the generic type can get this attribute and automatically convert it into osunicode. So you still have to add it. If you don’t add it, it’s null

< strong > @ jsonproperty() < / strong > it is used to declare the field alias of dto. For example, the property from the front end is prop: 1, but I want to map this prop to name when creating this dto, so I need to write if on the property header

Front end wear property prop

@JsonProperty("prop")
private String name;

In this way, name gets the data bound by prop.

  @JsonIgnore()

    1. It acts on a field, which can be removed when it is transmitted to the front end. Neither get nor set can get data

    2. When it is applied to the method and annotation get, you will find the data that the front end will not display. When the annotation is applied to set, the back end will not get the data transmitted from the front end