Springjdbc like fuzzy query, Spring namedparameterjdbctemplate like query

Source: Internet
Author: User

springjdbc like fuzzy query, Spring namedparameterjdbctemplate like query ,

Springjdbc named parameter like Fuzzy query, namedparameterjdbctemplate like fuzzy query

>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>

? Copyright Sweet Potato Yiu July 20, 2017

http://www.cnblogs.com/fanshuyao/

When Springjdbc uses a named template class (Namedparameterjdbctemplate) for a like fuzzy query, how do I set it?

Method One: Set in the SQL statement (%)

Java code
  1. SELECT * from Jo_user WHERE 1=1 and username like '% ': username '% '
  2. : There must be a space on both sides of username
  3. If: Username no space on both sides of the query is not data, as follows:
  4. SELECT * from Jo_user WHERE 1=1 and username like '% ': username'% '
  5. Left Blur Query
  6. SELECT * from Jo_user WHERE 1=1 and username like '% ': username
  7. Fuzzy query on the right
  8. SELECT * from Jo_user WHERE 1=1 and username like:username '% '

Method Two: Set (%) in the value of the parameter, the query SQL statement is just a named parameter

such as "%" + Username + "%"

SQL is as follows:

Java code
    1. SELECT * from Jo_user WHERE 1=1 and username Like:username

Both of the above methods have been tested and can be used with confidence.

After testing, the following is not possible (add a double vertical line).

Java code
    1. SELECT * from article WHERE title like '% ' | |: TITLE | | '% '

>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>

? Copyright Sweet Potato Yiu July 20, 2017

http://www.cnblogs.com/fanshuyao/

Springjdbc like fuzzy query, Spring namedparameterjdbctemplate like query

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.