记录一个springboot+freemark的错误

本文记录了一次在SpringBoot项目中使用FreeMarker模板引擎时遇到的错误,具体表现为在遍历集合时出现异常。错误源于从Mybatis-Plus查询的Page对象直接返回,正确做法是取出Page内的数据后再传递给FreeMarker模板,以避免此类错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

javax.servlet.ServletException: Cannot expose bind macro helper 'springMacroRequestContext' because of an existing model object of the same name

还有

freemarker.core.NonSequenceOrCollectionException: The value you try to list is an extended_hash+string (com.baomidou.mybatisplus.plugins.Page wrapped into f.e.b.StringModel), thus you must specify two loop variables after the "as"; one for the key, and another for the value, like <#... as k, v>).

项目是springboot+freemark

今天报了这个错 ,先来解释下为什么报错
根据错误提示在[#list indexPage as _data]
遍历集合时候出错了, 再看后台怎么封装的

Page<IrStaticDiss> indexPage = iIrStaticDissService.searchIndexByVo(irStaticDissVo);
  model.addAttribute("indexPage", indexPage);

这里是直接将查出Page返回了 (Page是mybatis-plus自带的) , 所以应该再取值时改成下面这样就不会报错了

[#list indexPage.records as _data]

粗心的错…

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值