CeDo
2021-05-13 e9857b2c71f52e3127992859447ec7f5f28de496
add:上传文件大小限制
2个文件已修改
1个文件已添加
47 ■■■■■ 已修改文件
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/constants/HttpStatus.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/dao/ComMngStructAreaDAO.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/zuul/src/main/java/com/panzhihua/zuul/handles/FileUploadExceptionAdvice.java 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/constants/HttpStatus.java
@@ -73,6 +73,11 @@
    public static final int CONFLICT = 409;
    /**
     * 请求主体的大小超过了服务器
     */
    public static final int REQUEST_TOO_LARGE = 413;
    /**
     * 不支持的数据,媒体类型
     */
    public static final int UNSUPPORTED_TYPE = 415;
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/dao/ComMngStructAreaDAO.java
@@ -43,7 +43,7 @@
            "AND community_id=#{comMngStructAreaVO.communityId} \n" +
            " </if> " +
            "<if test='comMngStructAreaVO.areaName != null and comMngStructAreaVO.areaName.trim() != &quot;&quot;'>" +
            "AND area_name = concat( '%',#{comMngStructAreaVO.areaName}, '%' )" +
            "AND area_name like concat( '%',#{comMngStructAreaVO.areaName}, '%' )" +
            " </if> " +
            "</script>")
    IPage<ComMngStructAreaVO> pageArea(Page page, @Param("comMngStructAreaVO") ComMngStructAreaVO comMngStructAreaVO);
springcloud_k8s_panzhihuazhihuishequ/zuul/src/main/java/com/panzhihua/zuul/handles/FileUploadExceptionAdvice.java
New file
@@ -0,0 +1,40 @@
package com.panzhihua.zuul.handles;
import com.panzhihua.common.constants.HttpStatus;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.utlis.ResultUtil;
import org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ControllerAdvice
public class FileUploadExceptionAdvice {
    @ExceptionHandler(MaxUploadSizeExceededException.class)
    public void handleMaxSizeException(
            MaxUploadSizeExceededException exc,
            HttpServletRequest request,
            HttpServletResponse response) {
        //请求超过大小限制
        response.setContentType("application/json;charset=utf-8");
        ResultUtil.responseJson(response, R.fail(HttpStatus.REQUEST_TOO_LARGE, "请求主体的大小超过限制"));
        return;
    }
    @ExceptionHandler(FileSizeLimitExceededException.class)
    public void handleFileSizeLimitException(
            FileSizeLimitExceededException exc,
            HttpServletRequest request,
            HttpServletResponse response) {
        //请求超过大小限制
        response.setContentType("application/json;charset=utf-8");
        ResultUtil.responseJson(response, R.fail(HttpStatus.REQUEST_TOO_LARGE, "文件大小超过限制"));
        return;
    }
}