使用<span style="font-family: Arial, Helvetica, sans-serif;">@ModelAttribute 和</span><span style="font-family: Arial, Helvetica, sans-serif;">@RequestParam来同时接受对象,和文件内容</span>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<span style="font-family: Arial, Helvetica, sans-serif;"> @RequestMapping(value = "uploadLocalFile")</span>
public void uploadLocalFile(Model model,@ModelAttribute CsConfigFile configFile,@RequestParam("file") MultipartFile file,@CookieValue("username") String username) throws IOException
{
// model.addAttribute(csService.localFile(username,csConfigFile));
// System.out.println(configFile);configFile里有filePath字段
// System.out.println(new String(file.getBytes()));
configFile.setFileContent(new String(file.getBytes()));
model.addAttribute(csService.localFile(username,configFile));
}
<form method="post" action="xxx/uploadLocalFile" enctype="multipart/form-data">
filePath: <input type="text" name="filePath"/>
fileContent <input type="file" name="file"/>
<input type="submit"/>
</form>