王者之座 2016-08-09 08:51 采纳率: 61.9%
浏览 1377

mybatis符号$换#出现问题

之前公司用$,看我没事做就叫我换#号试一下 结果发现一些问题

原来代码中的codition 是一段字符串 如

  where  t_applyUnit.BAU_CHECKSTATUS = '2'

在xml文件中直接在sql语句后面加上${codition}使用 但是我改成#以后出现问题 似乎自动加了个\似得

 ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' where  t_applyUnit.BAU_CHECKSTATUS = \'2\''' at line 53
; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' where  t_applyUnit.BAU_CHECKSTATUS = \'2\''' at line 53

结果发现好像是输出的语句中前后多了双引号

  • 写回答

1条回答 默认 最新

  • 看山 Java领域优质创作者 2017-02-28 06:12
    关注

    在mybatis中,
    $就将语句直接方在变量出,比如where age=${age},age是12,那解析出来就是where age=12
    #是认为变量是字符变量,所以会在前后添加单引号,比如where username=#{username},username是abc,解析出来就是where username='abc'

    评论

报告相同问题?

悬赏问题

  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示