vue-axios-post方式傳遞物件至後臺
阿新 • • 發佈:2018-11-29
1.物件引數型別JSON化: data:JSON.parse(JSON.stringify(object)),
2.頭部資訊headers: "Content-Type": "application/json; charset=UTF-8"
3.service中請求方式寫為POST
4.後臺controller中獲得引數方式:@RequestBody String Object
5.String轉換為json:JSONObject accident=JSONObject.fromObject(newsObject);
public int save(@RequestBody String newsObject) { JSONObject accident=JSONObject.fromObject(newsObject); JSONObject accident2=JSONObject.fromObject(accident.get("newsObject"));//需要import net.sf.json.JSONObject========需要新增依賴json-lib ...... }
(注:JSONObject將外部為{}的String型別轉換為JSONObject;JSONArray是將外部為[]的String型別轉換為JSONArray)