前端请求为content-type:application/json;后台如何接收

版权声明:不卑不亢,不骄不躁---好男人就是我,我就是曾哥. https://blog.csdn.net/weixin_42884584/article/details/82346197

①可以用@RequestBody,接收json数据

@RequestBody(required = false)String str

②如果是比较复杂的json数据,可以使用JSON处理

先引入jar包:

<dependency>
  <groupId>com.alibaba</groupId>
  <artifactId>fastjson</artifactId>
  <version>1.2.3</version>
</dependency>

controller代码中写

public CommonResult updateDictionary(@RequestBody(required = false) String obj) {
        //解析json数据
        JSONObject json = JSON.parseObject(obj);
        String description=json.getString("description");
        Object dictionaryItemList1=json.get("dictionaryItemList");
        ...
}

猜你喜欢

转载自blog.csdn.net/weixin_42884584/article/details/82346197
今日推荐