目录
1.什么是动态sql:
1.2为什么使用动态sql:
1.3mybatis中动态sql标签有哪些?
2.if标签--单条件判断
3.choose标签 多条件分支判断
4.where标签
1.什么是动态sql:
根据参数的值,判断sql的条件。
name!=null address
select * from 表名 where name=#{name} and address=#{address}
name==null
select * from 表名
1.2为什么使用动态sql:
1.3mybatis中动态sql标签有哪些?
2.if标签--单条件判断
//如果name不为null则按照name查询 如果为null则查询所有 public List
select * from account where 1=1
and name=#{name}
and money=#{money}
3.choose标签 多条件分支判断
select * from account where 1=1
and name=#{name}
and money=#{money}
and isdeleted=0
4.where标签
我们观察到上面的sql都加了 where 1=1 ,如果不使用where 1=1 那么你的动态sql可能会出错。 我们能不能不加where 1=1呢! 可以 那么我们就可以使用where标签,作用:可以自动为你添加where关键字,并且可以帮你去除第一个and |or
select * from account
and name=#{name}
and money=#{money}
相关文章
发表评论