mybatis中#{}与${}的区别

#{}类似于PreparedStatement的用法,它相当于?(即占位符),之后传入参数来替换

${}类似于Statement的用法,传入参数来进行字符串拼接

eg:

<select id="queryUserByTableName" resultType="com.zpc.mybatis.pojo.User">
    select * from #{tableName}
</select>

这种情况下会报错,假设tableName为'a',则会变成select * from 'a',应使用${tableName}

原文地址:https://www.cnblogs.com/yanze/p/10172559.html