提交有文件和其它文本内容的表单
<form action="items/addItems" method="post" enctype="multipart/form-data">
<pre>
产品名称:<input type="text" name="name" />
产品价格:<input type="text" name="price" />
产品图片:<input type="file" name="file" />
产品详情:<input type="text" name="detail" />
产品日期:<<input type="text" name="createtime">
<input type="submit" name="sub" value="提交" />
</pre>
</form>
@RequestMapping(“/addItems”)
public String addItems(@RequestParam(“file”) MultipartFile file, Items items, HttpServletRequest request)
{
System.out.println(items);
System.out.println(file.getOriginalFilename());
//String basePath = request.getScheme()+“://”+request.getServerName()+“:”+request.getServerPort()+request.getContextPath()+“/”;
String basePath=request.getSession().getServletContext().getRealPath(“/upload/”);
System.out.println(basePath);
try {
file.transferTo(new File(basePath+file.getOriginalFilename()));//保存
} catch (IOException e) {
e.printStackTrace();
}
}