SpringMVC(2)传递JSON、 从url中获取参数、上传文件、cookie 、session
一。//传递JSON
@RequestMapping("/r7")//@RequestBody请求
public String r7(@RequestBody UserInto user){
return "接收:"+user.toString();
}
也可以:
二. //从url中获取参数
@RequestMapping("/article/{t}/{articId}")
//重命名
public String r8(@PathVariable Integer articId,@PathVariable("t") String type){
return "接收ID:"+articId+" type:"+type;
}
三.//上传文件
@RequestMapping("r9")
//重命名
public String r9(@RequestParam("file11") MultipartFile file) throws IOException {
System.out.println(file.getOriginalFilename());
//文件上传
file.transferTo(new File("D:\\新建文件夹 (2)\\as\\"+file.getOriginalFilename()));
return "文件接收成功";
}
cookie:学生证 session:学生证里面存储的信息