[1] 看来我有麻烦了。如果删除.haserrors(),则无法将产品添加到db,我可以这样做,但无法验证,反之亦然
产品控制器.java
public String saveProd(ModelMap model, @ModelAttribute(value = "product") @Validated Product product, BindingResult result, @RequestParam MultipartFile image) throws Exception {
ProductValidator prodVali = new ProductValidator();
prodVali.validate(product, result);
if (image.getName() != null) {
[1]
if (result.hasErrors()) {
model.addAttribute("listProduct", productService.getListProduct());
return "product/add-prod";
} else {
System.out.println("Saving file" + image.getOriginalFilename());
product.setImage(image.getBytes());
productService.insertProduct(product);
model.addAttribute("listProduct", productService.getListProduct());
}
}
return "redirect:/admin/product/";
}
添加产品.jsp
<input id="image-input" type="file" name="image" />
产品.java
@Lob
private byte[] image;
//contructor
//geter/seter
暂无答案!
目前还没有任何答案,快来回答吧!