xml 模糊查询 ${} 和 #{} 的区别及用法
·
/**
* 假设模糊查询
* @param name
* @return
*/
List<User> testMohu(@Param("name") String name);
${} 相当于直接拼接在已写好的sql中
<select id="selectPage" resultType="User">
select * from t_user where username like "%"${value}"%" // 传参会自动拼接引号
<select>
#{} 相当于用一个占位符在sql中拼接语句
<select id="selectPage" resultType="User">
select * from t_user where username like "%"#{name}"%" // 传参会自动拼接引号
<select>
注:${}会产生SQL注入,#{}不会产生SQL注入问题 所以能用#{}就避免使用${}
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)