How to write mybatis fuzzy query like statement
May 19, 2021 pm 03:26 PMThe 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!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

iBatis vs. MyBatis: Which one is better for you?

Various ways to implement batch deletion operations in MyBatis

Detailed explanation of the Set tag function in MyBatis dynamic SQL tags

Comparative analysis of the functions and performance of JPA and MyBatis

Detailed explanation of how to use MyBatis batch delete statements

Detailed explanation of MyBatis first-level cache: How to improve data access efficiency?

Detailed explanation of MyBatis one-to-many query configuration: solving common related query problems

Analyze the caching mechanism of MyBatis: compare the characteristics and usage of first-level cache and second-level cache
