mybatis中like模糊查询的几种写法及注意点

第一种:使用${...}

mybatis中like模糊查询的几种写法及注意点
注意:由于$是参数直接注入的,导致这种写法,大括号里面不能注明jdbcType,不然会报错。
mybatis中like模糊查询的几种写法及注意点

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'VARCHAR' in 'class com.utry.ucsc.dao.bean.KnowledgeLibraryBean'

弊端:可能会引起sql的注入,平时尽量避免使用${...}

第二种:使用#{...}

mybatis中like模糊查询的几种写法及注意点
注意:因为#{...}解析成sql语句时候,会在变量外侧自动加单引号' ',所以这里 % 需要使用双引号" ",不能使用单引号 ' ',不然会查不到任何结果。

第三种:使用CONCAT()函数连接参数形式

mybatis中like模糊查询的几种写法及注意点