1)如果前端传的是json,后端接受时要用@RequestBody注解,json对象要与实体类对应
1 public boolean updateKnowledge(@RequestBody Knowledge knowledge){ 2 return knowledgeService.updateKnowledge(knowledge); 3 }
如果json没有与实体类对应的话,可以有另外一种方法,利用JSONObject对象取值,可以直接转换成你需要的类型,这里仅展示string类型
1 public int deleteKnowledge(@RequestBody JSONObject obj){ 2 return knowledgeService.deleteKnowledge(obj.getString("id")); 3 }
2)如果前端传的是form-data,后端接受时要用@RequestParam注解,表单的key也要与实体类的字段对应
public void downloadFile( @RequestParam("groupName") String groupName,@RequestParam("url") String url, HttpServletResponse response) throws IOException { 2 MyFile myFile = new MyFile(); 3 myFile.setGroupName(groupName); 4 myFile.setUrl(url); 5 myFileService.downloadFile(myFile,response); 6 }