30岁叛逆期 2023-02-08 10:16 采纳率: 0%
浏览 34

mybatis查询报错,高难度

mybatis查询使用Map作为test查询条件报错
项目上查询时偶现
<select id="queryRecord" resultType="Map">
    select * from ${tableName}
    <where>
      <if test="keysRecord!=null ">
         <foreach collection="keysRecord.entrySet()" separator="AND" index="k" item="entry">
             <if test="entry.value != null and entry.value != ''" >
                ${entry.key} = #{entry.value}
             </if>
          </foreach>
      </if>
    </where>    
  </select>


运行结果及详细报错内容

Caused by: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'entry.value != null and entry.value != '''. Cause: org.apache.ibatis.ognl.OgnlException: value [java.lang.IllegalAccessException: Class org.apache.ibatis.ognl.OgnlRuntime can not access a member of class java.util.HashMap$Entry with modifiers "public final"]
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)

我的解答思路和尝试过的方法,不写自己思路的,回答率下降 60%

猜测就是Map中entry.value值拿不到,拿不到里面报了权限不允许访问错误。想不明白为何会拿不到权限,是mybatis的这个test表达式使用反射导致的问题吗

  • 写回答

2条回答 默认 最新

  • 踢足球的阿坤 2023-02-08 10:37
    关注

    这个问题是由于foreach不支持entry.value != null和entry.value != ''这种条件判断方式引起的,可以修改test条件:

    ${entry.key} = #{entry.value}

    评论

报告相同问题?

问题事件

  • 创建了问题 2月8日

悬赏问题

  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持