1、文件上传时,报“415 unsupported type”。
解决:使用@ModelAttribute
而不是@RequestBody
。
测试:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<title>Hello World!</title>
<meta charset="utf-8">
</head>
<body>
<form method="POST" enctype="multipart/form-data" action="http://127.0.0.1:8888/upload">
<p>文件1:<input type="text" name="id" /></p>
<p>文件2:<input type="text" name="name" /></p>
<p>文件3:<input type="file" name="file" /></p>
<p><input type="submit" value="上传" /></p>
</form>
</body>
</html>
代码语言:javascript复制 @RequestMapping(value = "/upload", method = RequestMethod.POST)
public String upload(@ModelAttribute FileUpload fileUpload) {
return "ok";
}