Mybatis的#和$有什么区别

最直接的概括就是#相当于加上了双引号,$则相当于直接显示数据

1、#对传入的参数视为字符串,就是它会预编译,select * from user where name= #{test} ,就是相当于select * from user where name=“name”,而select * from user where name =${name} ,则就是少了个引号

2、#的优势在于它能很大程度的防止sql注入,而$则不行

3、Mybatis排序时使用order by动态参数时需要注意,用$而不是#

原文地址:https://www.cnblogs.com/elian91/p/11114481.html