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

mybatis中对于使用like来进行模糊查询的几种方式:spring

(1)使用${...}sql

注意:因为$是参数直接注入的,致使这种写法,大括号里面不能注明jdbcType,否则会报错apache

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'mybatis

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

(2)使用#{...}函数

注意:由于#{...}解析成sql语句时候,会在变量外侧自动加单引号'  ',因此这里 % 须要使用双引号"  ",不能使用单引号 '  ',否则会查不到任何结果。blog

(3)使用CONCAT()函数链接参数形式get

相关文章
相关标签/搜索