The writing method is: 1. Use "${...}", the syntax is "like '${...}'"; 2. Use "#{...}", the syntax is " like '#{...}'"; 3. Use the CONCAT function to connect the parameter form, the syntax is "like CONCAT('%',#{...},'%')".
The operating environment of this tutorial: windows7 system, java10 version, Dell G3 computer.
There are several ways to use like to perform fuzzy queries in mybatis:
(1) Use ${...}
Note: Since $ is directly injected as a parameter, resulting in this writing method, jdbcType cannot be specified in the curly brackets, otherwise an error will be reported
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'
Disadvantages: It may cause SQL injection. Try to avoid using ${...}
(2) Use #{...}
Note: Because when #{...} is parsed into a sql statement, single quotation marks ' ' will be automatically added outside the variable, so here % needs to use double quotation marks " ", and single quotation marks ' ' cannot be used, otherwise No results will be found.
(3) Use the CONCAT() function to connect the parameter form
Related free learning recommendations: java basic tutorial
The above is the detailed content of How to write mybatis fuzzy query like statement. For more information, please follow other related articles on the PHP Chinese website!