spring @RequestBody 注入报错 not marked as ignorable

报错原因:当请求的参数包含类中不存在的字段。

解决:@JsonIgnoreProperties(ignoreUnknown = true)写在类上,它会忽略不存在的字段。

注意:

  • @JsonIgnoreProperties(ignoreUnknown = true),将这个注解写在类上之后,就会忽略类中不存在的字段,可以满足当前的需要。这个注解还可以指定要忽略的字段。
  • @JsonIgnore注解用来忽略某些字段,可以用在Field或者Getter方法上,用在Setter方法时,和Filed效果一样。这个注解只能用在POJO存在的字段要忽略的情况。

猜你喜欢

转载自blog.csdn.net/xixingzhe2/article/details/85266684