mybatis中使用like匹配查询的错误
提示:
Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='bookName', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null .
解决方法:
mysql中的语句一般写成:
1 select * from books where bookName like "%Java%"
错误写法:
1 select * from ssmbuild.books where bookName like "%#{bookName}%"
应该由于mybatis的解析参数,从而出现了问题。
正确写法:
1 select * from ssmbuild.books where bookName like "%"#{bookName}"%"

浙公网安备 33010602011771号