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}"%" 

posted @ 2021-10-26 23:01  现在开始JAVA  阅读(309)  评论(0)    收藏  举报