本文整理匯總了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";
}