一,mybatis 动态sql
1) mybatis 的动态sql可以对查询条件进行预编译,生成比较灵活的sql语句
二,常用标签
1)if :判断传入参数
o_ip,
2)where :
select * from sys_inf_usero_id = #{oId} and o_ip = #{oIp}
3)set :
update sys_inf_useru_name =#{uName}, u_pwd =#{uPwd}, where u_id = #{uId}
4)trim :
5)foreach :
#{item}
三,foreach 使用
1)批量添加(传入list,list里包含对象)
1.准备数据:
命名不规范,只为示例;
ArrayList
2.接口
int addTestLists(ArrayList
3.sql
insert into sys_test (name,pwd,dianhua,dizhi) values (#{item.name},#{item.pwd},#{item.dianhua},#{item.dizhi})
2)批量删除
1.准备数据:
Listlist = new ArrayList (); list.add(4); list.add(5); list.add(6); list.add(7); list.add(8); int i=testMapper.deleteTest(list);
2.接口:
int deleteTest(Listlist);
3.sql :
delete from sys_test where id in #{item}
3)foreach遍历map
1)数据准备
Map
2)接口
int deleteTests(@Param(value="maps")Map
3)sql
delete from sys_test where id in #{item}