gpt4 book ai didi

java - EL1008E : Property or Field 'timestamp' cannot be found on object of type 'java.util.HashMap' - maybe not public?

转载 作者:IT老高 更新时间:2023-10-28 13:50:39 28 4
gpt4 key购买 nike

当我使用 Spring Boot 的全局异常处理程序时,我得到了这个:

org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'timestamp' cannot be found on object of type 'java.util.HashMap' - maybe not public?

这是我的代码,我在我的项目中导入了 Spring Security 和 Thymeleaf。

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
<meta charset="UTF-8" />
<title>统一异常处理</title>
</head>
<body>
<h1> 系统异常 </h1>
<div th:text="${url ?: '未捕捉到URL'}"></div>
<div th:text="${exception == null ? '暂无异常信息' : exception.message}"></div>
</body>
</html
@GetMapping("/test")
public String test() throws Exception {
throw new Exception("发生错误");
}
@ControllerAdvice
public class GlobalExceptionHandler {

private static final String DEFAULT_ERROR_VIEW = "/error";
private static final Logger LOGGER = LoggerFactory.getLogger(GlobalExceptionHandler.class);

@ExceptionHandler(value = Exception.class)
public ModelAndView defaultErrorHandler(HttpServletRequest request, Exception e) {
LOGGER.error("系统异常", e);
ModelAndView mav = new ModelAndView();
mav.addObject("exception", e);
mav.addObject("url", request.getRequestURI());
mav.setViewName(DEFAULT_ERROR_VIEW);
return mav;
}
}

最佳答案

你的 View 名称应该是“error”而不是“/error”, View 解析器会在模板文件夹中找到名为error.html的模板,如果 View 解析器找不到它会使用默认的,在模型中需要哪个时间戳。

关于java - EL1008E : Property or Field 'timestamp' cannot be found on object of type 'java.util.HashMap' - maybe not public?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43751128/

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