java – 从HttpServletRequest转换为WebRequest
发布时间:2020-12-14 23:35:50 所属栏目:Java 来源:网络整理
导读:我使用 Spring Initializer,嵌入式Tomcat,Thymeleaf模板引擎和包作为可执行JAR文件生成了一个Spring Boot Web应用程序. 使用的技术: Spring Boot 2.0.0.M6,Java 8,maven 我在这个课程中有一个这个方法 private MapString,Object getErrorAttributes(HttpSer
我使用
Spring Initializer,嵌入式Tomcat,Thymeleaf模板引擎和包作为可执行JAR文件生成了一个Spring Boot Web应用程序.
使用的技术: Spring Boot 2.0.0.M6,Java 8,maven 我在这个课程中有一个这个方法 private Map<String,Object> getErrorAttributes(HttpServletRequest request,boolean includeStackTrace) { RequestAttributes requestAttributes = new ServletRequestAttributes(request); return this.errorAttributes.getErrorAttributes(request,includeStackTrace) } 但是我不知道如何从javax.servlet.http强制转换HttpServletRequest org.springframework.web.context.request.WebRequest The method getErrorAttributes(WebRequest,boolean) in the type ErrorAttributes is not applicable for the arguments (HttpServletRequest,boolean) 解决方法
您不需要将HttpServletRequest转换为WebRequest.您需要的是在控制器方法中使用WebRequest.
@GetMapping("/endpoint") public .. endpont(HttpServletRequest request,WebRequest webRequest) { getErrorAttributes(request,webRequest,true); } 并更改为您的getErrorAttributes方法 private Map<String,WebRequest webRequest,boolean includeStackTrace) { RequestAttributes requestAttributes = new ServletRequestAttributes(request); return this.errorAttributes.getErrorAttributes(webRequest,includeStackTrace) } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |