gpt4 book ai didi

java - 从 HttpServletRequest 转换为 WebRequest

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:31:36 26 4
gpt4 key购买 nike

我使用 Spring Initializer、嵌入式 Tomcat、Thymeleaf 模板引擎生成了一个 Spring Boot Web 应用程序,并将其打包为可执行 JAR 文件。

使用的技术:

Spring Boot 2.0.0.M6、Java 8、行家

我在类(class)的 1 中有这个方法

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。您需要在 Controller 方法中使用 WebRequest

@GetMapping("/endpoint")
public .. endpont(HttpServletRequest request, WebRequest webRequest) {
getErrorAttributes(request, webRequest, true);
}

然后更改为您的 getErrorAttributes 方法

private Map<String, Object> getErrorAttributes(HttpServletRequest request, WebRequest webRequest,
boolean includeStackTrace) {

RequestAttributes requestAttributes = new ServletRequestAttributes(request);
return this.errorAttributes.getErrorAttributes(webRequest, includeStackTrace)

}

关于java - 从 HttpServletRequest 转换为 WebRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47455730/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com