EL1008E: Property or field ‘lastMessage‘ cannot be found on object of type ‘java.util.HashMap‘

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'lastMessage' cannot be found on object of type 'java.util.HashMap' - maybe not public or not valid?
	at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:217)
	at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:104)
	at org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:51)
	at org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:406)
	at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:92)
	at org.springframework.expression.spel.ast.OpNE.getValueInternal(OpNE.java:43)
	at org.springframework.expression.spel.ast.OpNE.getValueInternal(OpNE.java:33)
	at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:112)
	at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:330)
	at org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:263)
	... 102 common frames omitted
	.TemplateProcessingException: Exception evaluating SpringEL expression: "commentMessage.lastMessage != null" (template: "site/notice" - line 80, col 71)

出现错误的地方:

  @RequestMapping(path = "/notice/list",method = RequestMethod.GET)
    public String getSystemMessage(Model model){
//        获取当前登录用户
        User localUser = sessionReplace.getUser();
        /**
         * 处理评论通知
         */
        Message lastMessage = messageService.findLastMessage(localUser.getId(), TOPIC_COMMENT);
        System.out.println("lastMessage是:"+lastMessage);
        Map<String,Object> messageVo = new HashMap<>();
        if (lastMessage != null){
            messageVo.put("lastMessage",lastMessage);
//          因为content为json格式的字符串,而且中间还有特殊字符,我们需要对其进行处理
            String htmlUnescape = HtmlUtils.htmlUnescape(lastMessage.getContent());
            Map<String,Object> content = JSONObject.parseObject(htmlUnescape,HashMap.class);
            messageVo.put("user",userService.findUserById((Integer) content.get("userId")));
            messageVo.put("entityType",content.get("entityType"));
            messageVo.put("entityId",content.get("entityId"));
            messageVo.put("postId",content.get("postId"));
//          获取评论通知的未读消息
            int unReadCount = messageService.findUnReadCount(localUser.getId(), TOPIC_COMMENT);
            messageVo.put("unReadCount",unReadCount);
//          获取评论通知的所有消息
            messageVo.put("messageTotal",messageService.findMessageTotal(localUser.getId(), TOPIC_COMMENT));

        }
        model.addAttribute("commentMessage",messageVo);

获取的消息可能会为空,因为想得不够严谨,所以会出现这种错误,将if判断语句对messageVo没有限制作用,就算为空,也会被放入model中传入前端界面,所以需要将messageVo和model.addAttribute(“commentMessage”,messageVo);一起放进if语句中。

菜鸡记BUG,大佬请无视!