mybatis if test 判断字符串的坑

今天调试一个非常简单的test判断字符串查询语句,怎么调试都是不好用,后来百度才发现,是我写的test标签写错了,我写成:

 <if test="record.current != null and record.current=='1'" >    注意:1旁边是单引号

 

正确写法:

 <if test="record.current != null and record.current=='1'.toString()" >

 

或者:

<if test = 'record.current != null and record.current==“1”'> 注意:1 旁边是双引号

 

因为mybatis会把'1'解析为字符,java是强类型语言,所以不能这样写,需要双引号

 
posted @ 2018-12-14 14:12  HalleyZ  阅读(4942)  评论(0编辑  收藏  举报