Home > Java > Java Tutorial > body text

How to write mybatis fuzzy query like statement

醉折花枝作酒筹
Release: 2023-01-06 11:14:15
Original
11347 people have browsed it

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('%',#{...},'%')".

How to write mybatis fuzzy query like statement

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!