一个小bug,不过可以调一下mybatis的逻辑,首先加日志打印一下mybatis的日志
- log4j2.xml,日志输出有点儿多
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="OFF">
<appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</appenders>
<loggers>
<logger name="log4j.logger.noModule" level="fatal" additivity="false">
<appender-ref ref="Console"/>
</logger>
<logger name="log4j.logger.org.mybatis.jpetstore" level="trace" additivity="false">
<appender-ref ref="Console"/>
</logger>
<logger name="log4j.logger.com.opensymphony.xwork2" level="debug" additivity="false">
<appender-ref ref="Console"/>
</logger>
<logger name="log4j.logger.com.ibatis" level="trace" additivity="false">
<appender-ref ref="Console"/>
</logger>
<logger name="log4j.logger.com.ibatis.common.jdbc.SimpleDataSource" level="debug" additivity="false">
<appender-ref ref="Console"/>
</logger>
<logger name="log4j.logger.com.ibatis.common.jdbc.ScriptRunner" level="debug" additivity="false">
<appender-ref ref="Console"/>
</logger>
<logger name="log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate" level="debug" additivity="false">
<appender-ref ref="Console"/>
</logger>
<logger name="log4j.logger.org.mybatis" level="debug" additivity="false">
<appender-ref ref="Console"/>
</logger>
<logger name="log4j.logger.java.sql" level="debug" additivity="false">
<appender-ref ref="Console"/>
</logger>
<logger name="log4j.logger.java.sql.Connection" level="debug" additivity="false">
<appender-ref ref="Console"/>
</logger>
<logger name="log4j.logger.java.sql.Statement" level="debug" additivity="false">
<appender-ref ref="Console"/>
</logger>
<logger name="log4j.logger.java.sql.PreparedStatement" level="debug" additivity="false">
<appender-ref ref="Console"/>
</logger>
<logger name="log4j.logger.java.sql.ResultSet" level="debug" additivity="false">
<appender-ref ref="Console"/>
</logger>
<root level="trace">
<appender-ref ref="Console"/>
</root>
</loggers>
</configuration>
- 调试
IfSqlNode
里面会计算test表达式的值OgnlOps
的equal方法会真正计算,如果0 != ''
这个表达式,会进入compareWithConversion
方法,
case 8:
double dv1 = doubleValue(v1);
double dv2 = doubleValue(v2);
return dv1 == dv2 ? 0 : (dv1 < dv2 ? -1 : 1);
最终把空字符串和0都转为double,然后 0 != ''
就是false,直觉上应该是true,因此引发bug
- 结论
尽量不要出现不同类型直接的比较
来源:oschina
链接:https://my.oschina.net/wuxiaofei/blog/4317074