The difference between $ and # in MybatisThe difference between $ and # in Mybatis

The difference between $ and # in Mybatis

 1 # is to treat the incoming value as a string, eg: select id, name, age from student where id =#{id}, when the current end passes the id value of 1 to the background, it is equivalent to select id,name,age from student where id ='1'.

 2 $ is to directly display the incoming data to generate a sql statement, eg: select id, name, age from student where id = ${id}, when the front end puts the id value of 1, when it is passed into the background, it is equivalent to select id,name,age from student where id = 1.

 3 Using # can largely prevent sql injection.

 4 But if you use it in order by, you need to use $.

 5 In most cases, # is still used frequently, but $. 

 1 # is to treat the incoming value as a string, eg: select id, name, age from student where id =#{id}, when the current end passes the id value of 1 to the background, it is equivalent to select id,name,age from student where id ='1'.

 2 $ is to directly display the incoming data to generate a sql statement, eg: select id, name, age from student where id = ${id}, when the front end puts the id value of 1, when it is passed into the background, it is equivalent to select id,name,age from student where id = 1.

 3 Using # can largely prevent sql injection.

 4 But if you use it in order by, you need to use $.

 5 In most cases, # is still used frequently, but $. 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325134314&siteId=291194637