2022-01-04

mybatis异常提示For input string:{1=null}
报错情况:

<where>
    <if test='#{judge} != null  and #{judge}==1'>
     create_time>='2021-01-09 00:00:00' and create_time &lt;='2021-01-30 23:59:59'</if>    
     <if test='#{judge}!= null  and #{judge}==2'>
     create_time>='2021-02-09 00:00:00' and create_time &lt;='2021-02-30 23:59:59'</if>
    </where>

解决办法:

<where>
    <if test='judge != null  and judge==1'>
    create_time>='2021-01-09 00:00:00' and create_time &lt;='2021-01-30 23:59:59'
    </if>   
      <if test='judge!= null  and judge==2'>
      create_time>='2021-02-09 00:00:00' and create_time &lt;='2021-02-30 23:59:59'
      </if>
      </where>

原因:
Mybatis中的 #KaTeX parse error: Expected 'EOF', got '#' at position 8: 的区别和作用 #̲相当于对数据 加上 双引号,则是事什么就显示什么

例如:id = #{id},如果传入的值是99,那么解析成sql时的值为 id =“99”
例如:id = ${id},如果传入的值是99,那么解析成sql时的值为d = 99

本质上的区别:
将传入的数据都当成一个字符串,会对自动传入的数据加一个双引号。#
方式能够很大程度防止sql注入#
方式一般用于传入数据库对象,例如传入表名传入的数据直接显示生成在sql中。
排序时使用order by 动态参数使用$

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容