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: