What is the difference between Mybatis # {}and $,

Source: Internet
Author: User

What is the difference between Mybatis # {}and $,

Dynamic SQL is one of the powerful features of Mybatis and an important reason for its superiority over other ORM frameworks. Before pre-compiling SQL statements, Mybatis dynamically parses the SQL statements and parses them into a BoundSql object. It also processes dynamic SQL statements. In the dynamic SQL parsing phase, # {}and $ {} have different performance:

Select * from user where name =#{ name}

# {} Is resolved as a parameter tag during dynamic parsing. The parsed statement is:

Select * from user where name =?

When we use $:

Select * from user where name =$ {name}

During dynamic parsing, $ {} fills the input parameter into our statement as a String, and then becomes the following statement:

Select * from user where name = "dato"

The SQL statement before pre-compilation does not contain variables, and it is completely constant data. It is equivalent to an SQL statement without variables.

In summary, the replacement phase of the $ {} variable is in the dynamic SQL parsing phase, while the replacement of the # {} variable is in the DBMS.

This is the main difference between # {} and $ {}. In addition, there are the following differences:

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.