public class UserController {
// 文件上传
@RequestMapping("/test1")
@ResponseBody
public void test01(String username, MultipartFile fileName) throws IOException {
System.out.println("用户名:"+username);
String originalFilename = fileName.getOriginalFilename();
//传到本地
fileName.transferTo(new File("D:\\test"+originalFilename));
System.out.println("上传成功");
}
// 多文件上传
@RequestMapping("/test2")
@ResponseBody
public void test02(String username, MultipartFile[] fileName){
System.out.println("用户名"+username);
for(MultipartFile file : fileName){
String originalFilename = file.getOriginalFilename();
System.out.println(originalFilename);
}
}
// SpringMvc拦截器
@RequestMapping("/test3")
// @ResponseBody
public ModelAndView test03(){
System.out.println("该方法执行...");
//返回数据模型和视图
ModelAndView mav = new ModelAndView();
mav.addObject("user","赵琦溢");
mav.setViewName("/success.jsp");
//返回
return mav;
} |
|