5.29日bug记录

  • 报错提示
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates//site/notice.html]")
Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "commentNotice.unread!=0?commentNotice.unread:''" (template: "/site/notice" - line 85, col 40)
	at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393)
	at org.attoparser.MarkupParser.parse(MarkupParser.java:257)
	at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230)
	... 52 common frames omitted

问题是模板读取不到unread数据,排查发现是给模板返回数据是逻辑发生错误

        //查询评论类通知
        Message message = messageService.findLatestNotice(user.getId(), TOPIC_COMMENT);
        Map<String, Object> messageVo = new HashMap<>();
        if (message != null) {
            //构造一个voMap
            //丰富这个messageVo对象
            messageVo.put("message", message);
            //处理content字段,因为之前在数据路中的content字段存放的是json对象
            String content = HtmlUtils.htmlUnescape(message.getContent());
            //将这个字符串转化为正常对象
            HashMap<String, Object> data = JSONObject.parseObject(content, HashMap.class);
            messageVo.put("user", userService.findUserById((Integer) data.get("userId")));
            messageVo.put("entityType", data.get("entityType"));
            messageVo.put("entityId", data.get("entityId"));
            messageVo.put("postId", data.get("postId"));
            int count = messageService.findNoticeCount(user.getId(), TOPIC_COMMENT);
            messageVo.put("count", count);

            int unread = messageService.findNoticeUnreadCount(user.getId(), TOPIC_COMMENT);
            messageVo.put("unread", unread);
        }
        model.addAttribute("commentNotice", messageVo);
  • 问题分析
    应该将messageVo这个Map和向模板返回数据这些逻辑放在if逻辑中构造,因为只有系统有消息的时候我们才需要给模板返回数据,这个错误逻辑,无论是message是否为空都会向模板返回messageVo,但是当message为空的是否向模板返沪的messageVo是一个空map,所以模板会报错找到指定数据
  • 处理结果
if (message != null) {
            //构造一个voMap
            Map<String, Object> messageVo = new HashMap<>();
            //丰富这个messageVo对象
            messageVo.put("message", message);
            //处理content字段,因为之前在数据路中的content字段存放的是json对象
            String content = HtmlUtils.htmlUnescape(message.getContent());
            //将这个字符串转化为正常对象
            HashMap<String, Object> data = JSONObject.parseObject(content, HashMap.class);
            messageVo.put("user", userService.findUserById((Integer) data.get("userId")));
            messageVo.put("entityType", data.get("entityType"));
            messageVo.put("entityId", data.get("entityId"));
            messageVo.put("postId", data.get("postId"));
            int count = messageService.findNoticeCount(user.getId(), TOPIC_COMMENT);
            messageVo.put("count", count);

            int unread = messageService.findNoticeUnreadCount(user.getId(), TOPIC_COMMENT);
            messageVo.put("unread", unread);
            model.addAttribute("commentNotice", messageVo);
        }
  • 解决成功!!!
旋转手势是hammer.js库中的一个功能,它允许用户通过触摸屏幕来旋转一个元素。然而,有时候在使用hammer.js的过程中可能会遇到旋转功能的bug。 旋转bug可能有不同的表现形式,如旋转过程中元素位置的跳动、旋转角度的不稳定或者旋转速度异常等等。这些问题与hammer.js库本身的设计或者配置有关,所以我们可以通过检查代码和配置项来解决旋转bug。 首先,可以确保hammer.js库的版本是最新的,因为更新版本通常会修复一些旧版本中的bug。然后,我们可以检查hammer.js的配置项,例如可触摸元素的选择器、旋转的阈值、旋转的方向等等。根据旋转bug的具体表现,可能需要调整这些配置项来获得更好的用户体验。 此外,我们还可以检查其他可能影响旋转功能的因素。例如,元素的CSS样式是否正确设置了旋转的中心点、是否存在其他与旋转相冲突的事件监听器等等。通过排查这些因素,我们可以找到并解决造成旋转bug的根本原因。 如果以上方法无法解决旋转bug,还可以考虑使用其他库或者自行实现旋转功能。有一些其他的JavaScript库或者插件也提供了类似的旋转功能,可以避免hammer.js的bug。另外,如果具备前端开发的能力,可以尝试自行实现旋转功能,这样可以更好地掌控代码和调试bug。 总之,解决hammer.js旋转bug的方法包括检查代码和配置项、更新库版本、检查其他可能影响旋转的因素,并可以考虑使用其他库或自行实现旋转功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值