Home Java javaTutorial How to write mybatis fuzzy query like statement

How to write mybatis fuzzy query like statement

May 19, 2021 pm 03:26 PM
like mybatis fuzzy query

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!

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 admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

iBatis vs. MyBatis: Which one is better for you? iBatis vs. MyBatis: Which one is better for you? Feb 19, 2024 pm 04:38 PM

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

Various ways to implement batch deletion operations in MyBatis Various ways to implement batch deletion operations in MyBatis Feb 19, 2024 pm 07:31 PM

Various ways to implement batch deletion operations in MyBatis

Detailed explanation of the Set tag function in MyBatis dynamic SQL tags Detailed explanation of the Set tag function in MyBatis dynamic SQL tags Feb 26, 2024 pm 07:48 PM

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

Comparative analysis of the functions and performance of JPA and MyBatis Comparative analysis of the functions and performance of JPA and MyBatis Feb 19, 2024 pm 05:43 PM

Comparative analysis of the functions and performance of JPA and MyBatis

Detailed explanation of how to use MyBatis batch delete statements Detailed explanation of how to use MyBatis batch delete statements Feb 20, 2024 am 08:31 AM

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 first-level cache: How to improve data access efficiency? Feb 23, 2024 pm 08:13 PM

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 Detailed explanation of MyBatis one-to-many query configuration: solving common related query problems Feb 22, 2024 pm 02:18 PM

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 Analyze the caching mechanism of MyBatis: compare the characteristics and usage of first-level cache and second-level cache Feb 25, 2024 pm 12:30 PM

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

See all articles