u013234356
不常发疯的疯子
2015-06-03 00:09

springmvc中DAO中save方法与数据库

  • spring
  • 方法
  • dao
  • 数据库

save方法:
public void save(T o){

    getSession().save(o);

}

controller里的方法:
@RequestMapping(value = "/fileUpload2.do", method = RequestMethod.POST)

public String fileUpload2(Long id,Video video,ModelMap map,HttpServletRequest request)

throws IllegalStateException, IOException {

System.out.println("id是"+id);
// 设置上下方文

CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(

request.getSession().getServletContext());
System.out.println("2");
// 检查form是否有enctype="multipart/form-data"

if (multipartResolver.isMultipart(request)) {

MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;

System.out.println("3");
Iterator iter = multiRequest.getFileNames();

while (iter.hasNext()) {

// 由CommonsMultipartFile继承而来,拥有上面的方法.

MultipartFile file = multiRequest.getFile(iter.next());

if (file != null) {

String videoname = "Upload" + file.getOriginalFilename();
video.setvideoname(videoname);
String path = "E:/" + videoname;

video.setPath(path);
File localFile = new File(path);

file.transferTo(localFile);
System.out.println("4");
}

}

}
Long Tid=id;
map.addAttribute("id", id);
map.addAttribute("Tid", Tid);
video.setTid(Tid);
System.out.println("视频路径是1"+video.getPath());
System.out.println("视频Tid是1"+video.getTid());
videoService.save(video);
System.out.println("视频路径是2"+video.getPath());
System.out.println("视频Tid是2"+video.getTid());
return "main/homework";

}

控制台打印信息是正确的,但是数据库中没有插入相应信息。有木有大神指点?挺急的,在线等。

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答