使用thymeleaf对数据库取出的数据进行渲染时所踩的”坑“

报错:

Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "activity['activityId']" (template: "workbench/activity/test2" - line 12, col 17)
	at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
	at org.attoparser.MarkupParser.parse(MarkupParser.java:257) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
	at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
	... 48 common frames omitted
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "activity['activityId']" (template: "workbench/activity/test2" - line 12, col 17)

org.springframework.expression.spel.SpelEvaluationException: EL1027E: Indexing into type 'com.zarek.crm.pojo.domain.Activity' is not supported


Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: “activity[‘activityId’]” (template: “workbench/activity/test2” - line 12, col 17)
org.springframework.expression.spel.SpelEvaluationException: EL1027E: Indexing into type ‘com.zarek.crm.pojo.domain.Activity’ is not supported

问题产生的原因:

由于我的实体类和mapper映射文件是使用mybatis generator生成的,
导致原本我数据库中的表的属性是 activityId (I 是大写的) 的,结果实体类成了 activityid(i 是小写的)
mapper文件中,mybatis generator自动给我产生了一个BaseResultMap对应,我没有注意。

  <resultMap id="BaseResultMap" type="com.zarek.crm.pojo.domain.Activity" >
    <id column="activityId" property="activityid" jdbcType="CHAR" />
    <result column="owner" property="owner" jdbcType="CHAR" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="startDate" property="startdate" jdbcType="CHAR" />
    <result column="endDate" property="enddate" jdbcType="CHAR" />
    <result column="cost" property="cost" jdbcType="VARCHAR" />
    <result column="description" property="description" jdbcType="VARCHAR" />
    <result column="createTime" property="createtime" jdbcType="CHAR" />
    <result column="createBy" property="createby" jdbcType="VARCHAR" />
    <result column="editTime" property="edittime" jdbcType="CHAR" />
    <result column="editBy" property="editby" jdbcType="VARCHAR" />
  </resultMap>

因此在进行thymeleaf前端绑定数据的时候,想当然的将其写成了

            <td th:text="${activity['activityId']}"></td>

解决办法

实际上应该写成实体类中定义的属性名

            <td th:text="${activity['activityid']}"></td>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值