mybatis的foreach写用法
2015-11-09 18:41
423 查看
一、mybatis查询
二、mybatis插入
以上方法Mybatis会帮我们进行sql注入拦截,Mybatis如果采用#{xxx}的形式设置参数,Mybatis会进行sql注入的过滤。如果采用的是${xxx},Mybatis不会进行sql注入过滤,而是直接将参入的内容输出为sql语句。
public abstract List<Model> findByIds(@Param("ids")List<Integer> ids);
select * from table <where> id in <foreach collection="ids" item="item" index="index" open="(" separator="," close=")">#{item}</foreach> </where>
二、mybatis插入
public abstract void saves(@Param("tables")List<Model> tables);
insert into table(name,addtime) values <foreach collection="tables" item="item" index="index" separator=","> (#{item.name},#{item.addtime}) </foreach>
以上方法Mybatis会帮我们进行sql注入拦截,Mybatis如果采用#{xxx}的形式设置参数,Mybatis会进行sql注入的过滤。如果采用的是${xxx},Mybatis不会进行sql注入过滤,而是直接将参入的内容输出为sql语句。
相关文章推荐
- 不定义JQuery插件,不要说会JQuery
- ACM——输入输出外挂
- hdu3065 病毒侵袭持续中(AC自动机)
- listView滚动高度
- PET重建技术 MLEM迭代法(C++)(一) 原理及成像
- 在 ios 与 android 同时支持js功能,即web与app的交互功能的实现
- 进阶书籍
- CocoaPods的安装和使用 —— HERO博客
- Chrome 控制台不完全指南
- CF 500C New Year Book Reading
- mysql容灾及自动化切换
- hdu4381Grid【微复杂的背包】
- 笔记_Maya绑定基础_修改骨骼的方向
- C++类的静态成员详细讲解
- iOS 更改textField里placeholder的字体和颜色
- 使用celery之怎么让celery跑起来(转)
- Android 之 text relocations的简单解决方法
- 洛必达法则求极限的本质
- Elasticsearch-PHP 搜索操作
- grep命令及正则表达式的使用和介绍