ibatis动态标签sql
程序员文章站
2022-05-13 11:12:19
...
<select id="selectAccount" resultMap="AccountResult" parameterClass="Account"> select * from ACCOUNT <dynamic prepend="where"> <isNotNull property="id" prepend="and" open="(" close=")"> id = #id# </isNotNull> <isNotEmpty property="name" prepend="and"> name like '%$name$%' </isNotEmpty> </dynamic> </select>当id和name不为空是生成的SQL语句是:
select * from ACCOUNT where (id=id的值) and name like '%name的值%'
<isNotNull>和<isNotEmpty>子句没有时不会添加前缀where
<isNotNull>和<isNotEmpty>的prepend属性当并列子句存在是才会添加,因为有默
认属性:removeFirstPrepend="true"
open和close属性会并动态语句包括起来