在新的Spring6中,官方删除了之前上传文件使用的CommonsMultipartResolver类,导致之前的上传文件方法行不通了。
我们可以在Spring6官网中看到官方的声明:

大致意思就是:
CommonsMultipartResolver从 Spring Framework 6.0 及其新的 Servlet 5.0+ 基线开始,基于 Apache Commons FileUpload 的过时版本不再可用。
在网上查找后发现出现这个问题的人并不多,只好自己摸索了一下,去bingGPT和ChatGPT搜索了一下,一番操作发现上传成功了。
先给出我的环境:
org.springframework spring-webmvc6.0.11 jakarta.servlet jakarta.servlet-api6.0.0 provided org.thymeleaf thymeleaf-spring63.1.1.RELEASE 
使用的Spring6的环境。
下面给出我的解决方法:
首先在你的web.xml文件配置前端处理器-DispatcherServlet的标签中:
DispatcherServlet org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:SpringMVC.xml 1 
加上下面的配置:
10485760 10485760 0 
接着在Spring的配置文件中,把
org.springframework.web.multipart.commons.CommonsMultipartyResolver
替换成
org.springframework.web.multipart.support.StandardServletMultipartResolver
同时要注意,这个bean的id一定要是multipartResolver,千万不要写错。
最后在你的Controller类的方法中,MultipartFile类型的形参前面加上@RequestParam注解,注意别忘了它的value属性
 @RequestMapping("/testUpload")
    public String testUpload(@RequestParam("picture") MultipartFile picture,
HttpSession session) throws IOException {
        ServletContext servletContext = session.getServletContext();
        if (picture.isEmpty()) {
            return "上传失败,请选择文件";
        }
        String picturePath = servletContext.getRealPath("picture");
        String fileName = picture.getOriginalFilename();
        File dest = new File(picturePath);
        if (!dest.exists()) {
            dest.mkdirs();
        }
        String finalPath = picturePath + File.separator + fileName;
        System.out.println(finalPath);
        picture.transferTo(new File(finalPath));
        return "success";
    } 
加入注解后,获取到上传文件的真实路径和文件名,拼接后传给transferTo方法即可。
在页面中点击上传:

服务器提示成功:

至此结束。
只是分享了我的解决方法,希望能帮到一些碰到同样问题的人。