无法使用MyEclipse IDE在spring mvc中存储和检索图像和文件到数据库中

时间:2014-07-17 13:36:03

标签: spring-mvc

我正在使用Spring mvc与MyEclipse IDE进行实时项目而不集成maven,我的问题是如何将图像和文件存储和检索到数据库中。

1 个答案:

答案 0 :(得分:0)

用于将图像文件存储在数据库中的控制器代码:

@RequestMapping(value = "/saveproduct")    
public ModelAndView add(@ModelAttribute("command") CommonBean cbean,
          BindingResult result, HttpServletRequest request) throws Exception {
    CommonsMultipartFile file = cbean.getImage();       
    System.out.println("file content is " + file);
    cbean.setFile(file.getBytes());
    ProductModel model = new ProductModel();
    try {
        BeanUtils.copyProperties(model, cbean);
        eworldservice.addproduct(model);
    } catch(Exception ex) {
        ex.printStackTrace();
    }
    return new ModelAndView("home");
}