MyBatis两种传参方式的区别

时间:2023-01-01 19:41:33

$与#的区别

 select * from T_PRINT_LAYOUT where  D_RECID = ${recId}

最后生成的SQL为:

select * from T_PRINT_LAYOUT where  D_RECID = 1

即:直接将参数值替换到了原来${recId}的位置,相当于硬拼SQL

 select * from T_PRINT_LAYOUT where  D_RECID = #{recid,jdbcType=DECIMAL}

最后生成的SQL为:

 select * from T_PRINT_LAYOUT where  D_RECID = ?

即:#{...}被识别为一个SQL参数