前台jason 和后台@Requestbody不匹配

本文介绍如何将Spring MVC中的@ModelAttribute替换为@RequestBody,并确保Jackson 2.x库位于类路径上。此外,通过使用@JsonIgnoreProperties注解来忽略JSON中未知属性的方法也进行了详细说明。

You need to replace @ModelAttribute with @RequestBody and of course have the Jackson 2.x library on the classpath.

You will also need to add @JsonIgnoreProperties(ignoreUnknown = true) to TestResource

@JsonIgnoreProperties(ignoreUnknown = true)
public class TestResource {
   //all the rest of your code
}

because the Link you are posting contains properties that the Link object does not contain.

As was very correctly mentioned by OP, the @JsonIgnoreProperties annotation needs to be imported from com.fasterxml.jackson.annotation not from org.codehaus.jackson.annotate since the latter is from Jackson 1.x

转载于:https://my.oschina.net/superise/blog/682698

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值