Optional int parameter 'folderId' is not present but cannot be translated into a null value due to b

85 篇文章 0 订阅

错误信息:

严重: Servlet.service() for servlet [controller] in context with path [/gxbms] threw exception [Request processing failed; nested exception is org.springframework.web.bind.annotation.support.HandlerMethodInvocationException: Failed to invoke handler method [public void cn.cnic.cstnet.SCP.controller.FileController.uploadProjectFile(int,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws javax.servlet.ServletException,java.io.IOException]; nested exception is java.lang.IllegalStateException: Optional int parameter 'folderId' is not present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type.] with root cause

java.lang.IllegalStateException: Optional int parameter 'folderId' is not present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type.
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.checkValue(HandlerMethodInvoker.java:742)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveRequestParam(HandlerMethodInvoker.java:511)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:348)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)


解决方法:

public void uploadProjectFile(int  folderId, HttpServletRequest request, HttpServletResponse response){

    .................

}

int  修改成  Integer

即可。

下面是对代码进行注释的解释: ``` /** * 上传文件 * @param file 要上传的文件 * @param condition 文件上传的条件,包括分片数、MD5标识等 * @param projectFolderId 项目文件夹的ID * @param projectId 项目的ID * @return 上传成功后的Document对象 * @throws BimdcException 上传文件失败时抛出的异常,包含错误信息及HTTP状态码 */ public Document uploadDocument(MultipartFile file, FileUploadCondition condition, String projectFolderId, String projectId) { // 初始化Document对象为null Document document = null; try { // 如果condition中的fileId为空,则将其设置为null if (StringUtils.isEmpty(condition.getFileId())) { condition.setFileId(null); } // 创建一个新的日期文件夹,并返回文件夹ID String folderId = createNewDateFolder(projectFolderId, projectId); // 调用documentService.breakpointUpload方法上传文件,并将返回的Document对象赋值给document document = documentService.breakpointUpload(file, condition.getChunkNumber(), condition.getTotalChunks(), condition.getMd5Identifier(), condition.getFileId(), folderId, null); } catch (Exception e) { // 如果上传文件失败,则记录错误日志并抛出异常 log.error("上传文件失败,fileName=[{}],错误信息:", file.getOriginalFilename(), e); throw new BimdcException(HttpStatus.BAD_REQUEST.value(), "上传文件失败,请稍后重试!"); } // 如果document对象为null或其文件ID为空,则记录错误日志并抛出异常 if (document == null || StringUtils.isEmpty(document.getFileId())) { log.error("上传文件失败,fileName=[{}]", file.getOriginalFilename()); throw new BimdcException(HttpStatus.BAD_REQUEST.value(), "上传文件失败,请稍后重试!"); } // 返回上传成功的Document对象 return document; } ```
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值