Mybatis XML 文件中 什么时候用$ 什么时候用#

什么时候用$ 什么时候用#

   <update id="updateProcessId">
        update  ${tableName}
          set processId = ${processId}
           where id = ${keyId}
    </update>

这段话输出的SQL是

update 表A
 set processId =1234
where id= 3456

当processId和id都是int类型时不会报错,当这两个其中一个是字符串类型字段的时候就会出错了。

   <update id="updateProcessId">
        update  ${tableName}
          set processId = #{processId}
           where id = #{keyId}
    </update>

当把这两个字段改为 # 的时候,会自动根据字段的类型决定两边会不会自动加上双信号。

原文地址:https://www.cnblogs.com/Bruce_H21/p/14680316.html