@ExceptionHandler(MaxUploadSizeExceededException.class) public void handleException(MaxUploadSizeExceededException ex, HttpServletResponse response) throws Exception { StringBuilder error = new StringBuilder(); if (ex instanceof MaxUploadSizeExceededException) { MaxUploadSizeExceededException ms = (MaxUploadSizeExceededException) ex; SizeLimitExceededException cause = (SizeLimitExceededException) ms.getCause(); long maxUploadSize = ms.getMaxUploadSize(); String actualSize = String.valueOf(cause.getActualSize()); double parseDouble = Double.parseDouble(actualSize) / 1024 / 1024; BigDecimal b = new BigDecimal(parseDouble); double d = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); error.append("最大上传文件为:" + maxUploadSize / 1024 / 1024).append("M;"); error.append("实际文件大小为:").append(d).append("M"); System.out.println(error.toString()); } error.append("上传文件出错"); System.out.println(error.toString()); }
XML配置
微信公众号:
JAVA程序猿成长之路
分享资源,记录程序猿成长点滴。专注于Java,Spring,SpringBoot,SpringCloud,分布式,微服务。
来源:https://www.cnblogs.com/niugang0920/p/12187359.html