This article will introduce to you the difference between # and $ in sql. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
#{} is used here. When using #:
1. Used to pass in parameters. SQL will add " ", parsed as a string, such as here role_id = "roleid";
2, #{} can largely prevent sql injection;
Extension:
1. Use the incoming data to directly display in the generated sql, such as the above statement, use roleid= to directly display the incoming data in the generated sql, such as the above statement, use roleid={roleId, jdbcType=INTEGER}, then the value of sql is roleId = roleId when parsing, and an error will be reported during execution;
2, ${} method cannot prevent sql injection;
3, $ is generally used Input the database object, such as the database table name;
4. Try to use #{} when you can use #{};
Note:
## When using order by dynamic parameters when sorting #mybaties, you need to pay attention to using ${} instead of #{};Related recommendations: "mysql tutorial"
The above is the detailed content of What is the difference between # and $ in sql. For more information, please follow other related articles on the PHP Chinese website!