SQL语句MyBatis传参什么时候用#,什么时候用$

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Knight_Key/article/details/84343853

代码截图如下:

 <select id="get_" parameterType="map" resultMap="user">
        select * FROM `user` where user_status != 0
        and name = #{name} order by ${sort}
 </select>

 当所用SQL语句中涉及到查询某个字段的值为什么时,正常用到类似#{name}扎样的格式,所呈现出的内容:

and name = "yang",是自带引号的;

当所用SQL语句涉及到传一个固定值的参数构成SQL语句的语法主体。这时候需要注意,不应该存在" ",如下:

order by id

猜你喜欢

转载自blog.csdn.net/Knight_Key/article/details/84343853