MultipartFile file 如果没有文件上传该怎么解决

Controller中方法

public String excelInsertTeachers(MultipartFile file,HttpServletRequest request, HttpSession session, HttpServletResponse response)
            throws IllegalStateException, IOException {
}

这个方法可能走多次,但是存在有不上传文件的操作,那走这个方法就会有异常了,怎么解决呢?

public String excelInsertTeachers(HttpServletRequest request, HttpSession session, HttpServletResponse response)
            throws IllegalStateException, IOException {
        MultipartFile file = null;
        boolean isMultipart = ServletFileUpload.isMultipartContent(request);
        if (isMultipart) {
            MultipartHttpServletRequest multipartRequest = WebUtils.getNativeRequest(request,
                    MultipartHttpServletRequest.class);
            file = multipartRequest.getFile("multipartFile");
        }

拿到方法中去 去判断当前是否存在文件提交;如果有那就去做读取文件的操作.

我问过一个前辈,他的意思好像是可以通过设置参数来指定当前存在不存在的。。。。。但是我找不到啊。。挠头.jpg

如果有朋友知道其他方法的话也可以告诉我其他的方法,谢谢    挠头.gif。

猜你喜欢

转载自www.cnblogs.com/dxk1019/p/9120800.html
今日推荐