- 0
- 0
- 约1.78千字
- 约 4页
- 2026-02-13 发布于北京
- 举报
1.动态SQL
根据条件的不同,SQL语句也会随之动态地改变。
MyBatis中,了一组用于实现动态SQL。
1.1if
用于进行条件判断,test属性用于指定判断条件。为了拼
接条件,在SQL语句后强行添加1=1的恒成立条件。
selectid=selresultType=userselect*fromtuser
_
where1=1iftest=username!=nullandusername!=
andusername=#{username}/ififtest=password!=
nullandpassword!=andpassword=#{password}/if/
select
1.2where
用于管理where子句。有如下功能:
a)如果没有条件,不会生成where关键字;
b)如果有条件,会自动添加where关键字;
c)如果第一个条件中有and,去除之。
selectid=selresultType=user
select*fromt_user
where
iftest=username!=nullandusername!=
andusername=#{username}
/if
1.动态SQL
根据条件的不同,SQL语句也会随之动态的改变.MyBatis
中,了一组用于实现动态SQL.
1.1if
用于进行条件判断,test属性用于指定判断条件.为了拼接
条件,在SQL语句后强行添加1=1的恒成立条件.
selectid=selresultType=user
select*fromt_userwhere1=1
iftest=username!=nullandusername!=
andusername=#{username}
/if
iftest=password!=nullandpassword!=
andpassword=#{password}
/if
/select
1.2where
用于管理where子句.有如下功能:
a)如果没有条件,不会生成where关键字
b)如果有条件,会自动添加where关键字
c)如果第一个条件中有and,去除之
selectid=selresultType=user
select*fromt_user
where
iftest=username!=nullandusername!=
andusername=#{username}
/if
如果测试=“不为空且不等于”=
且=#{password}
/如果
/条件
/查询
iftest=password!=nullandpassword!=
andpassword=#{password}
/if
/where
/select
原创力文档

文档评论(0)