报错:
java.lang.NumberFormatException: For input string:
报错原因:
mybatis是用OGNL表达式来解析的,在OGNL的表达式中,'1'会被解析成字符,java是强类型的,char 和 一个string 会导致不等,所以if标签中的sql不会被解析,需要将'1'改为"1",或者加 .toString() 来转换。
解决办法:
把(注意 ' 和 " 的区别)
<if test="type == '1' and type != null ">
改为
<if test='type == "1" and type!= null '>
或改为
<if test="type == '1'.toString() and type != null ">
即可。