本文整理汇总了Java中org.springframework.validation.BindingResult.getSuppressedFields方法的典型用法代码示例。如果您正苦于以下问题:Java BindingResult.getSuppressedFields方法的具体用法?Java BindingResult.getSuppressedFields怎么用?Java BindingResult.getSuppressedFields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.validation.BindingResult
的用法示例。
在下文中一共展示了BindingResult.getSuppressedFields方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processAddNewProductForm
import org.springframework.validation.BindingResult; //导入方法依赖的package包/类
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String processAddNewProductForm(@ModelAttribute("newProduct") @Valid Product newProduct, BindingResult result, @ModelAttribute("productImage") ProductImage image, HttpServletRequest request) throws IOException {
if(result.hasErrors()) {
return "addProduct";
}
String[] suppressedFields = result.getSuppressedFields();
if (suppressedFields.length > 0) {
throw new RuntimeException("Próba wiązania niedozwolonych pól: " + StringUtils.arrayToCommaDelimitedString(suppressedFields));
}
ProductThumbnail productThumbnail = new ProductThumbnail(newProduct);
ProductPicture productPicture = new ProductPicture(newProduct);
MultipartFile productImage = image.getProductImage();
if (productImage!=null && !productImage.isEmpty()) {
try {
InputStream is = image.getProductImage().getInputStream();
BufferedImage img = Thumbnails.of(is)
.crop(Positions.CENTER)
.size(400, 300)
.asBufferedImage();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, "jpg", baos);
byte[] imageBytess = Base64.getEncoder().encode(baos.toByteArray());
productThumbnail.setBase64Image(new String(imageBytess));
byte[] encoded = Base64.getEncoder().encode(image.getProductImage().getBytes());
productPicture.setBase64Image(new String(encoded));
} catch(Exception e) {
throw new RuntimeException("Niepowodzenie podczas próby zapisu obrazka produktu", e);
}
}
productService.create(newProduct);
productThumbnailService.create(productThumbnail);
productPictureService.create(productPicture);
return "redirect:/products";
}