import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
@Controller
@RequestMapping("/multipart")
public class Multipart {
@ResponseBody()
@RequestMapping(value="upload2", produces="text/html;charset=utf-8")
public String upload2(HttpServletRequest request, MultipartFile config) throws IllegalStateException, IOException {
if (config != null) {
String path = request.getServletContext().getRealPath("upload/" + config.getOriginalFilename());
System.out.println(path);
// 上传
config.transferTo(new File(path));
return "2:成功上传文件";
}
return "2:上传文件失败";
}
}