§<dynamic>标签
§二元标签
§一元标签
§<iterate>标签
§ 共同的属性 prepend,open,close
<dynamic>标签
§<dynamic>标签
§属性 prepend,open,close
二元条件标签
§<isEqual property=“age” compareValue=“20”>
比较属性值和静态值或另一个属性值是否相等
§<isNotEqual>
比较属性值和静态值或另一个属性值是否不相等。
§<isGreaterThan>
比较属性值是否大于静态值或另一个属性值。
§<isGreaterEqual>
比较属性值是否大于等于静态值或另一个属性值。
§<isLessThan>
比较属性值是否小于静态值或另一个属性值。
§<isLessEqual>
比较属性值是否小于等于静态值或另一个属性值。
一元条件标签
§<isPropertyAvailable>
检查是否存在该属性(存在parameter bean的属性)
§<isNotPropertyAvailable>
检查是否不存在该属性(不存在parameter bean的属性)
§<isNull>
检查属性是否为null
§<isNotNull>
检查属性是否不为null
§<isEmpty>
检查Collection.size()的值,属性的String或String.valueOf()值,是否为null或空(“”或size() < 1)
§<isNotEmpty>
检查Collection.size()的值,属性的String或String.valueOf()值,是否不为null或不为空(“”或size() > 0)
其他标签
§<isParameterPresent>
检查是否存在参数对象(不为null)
§<isNotParameterPresent>
检查是否不存在参数对象(参数对象为null)
§<iterate>
遍历类型为java.util.List的元素。
view plaincopy to clipboardprint?
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap>
<!-- 动态查询1-->
<select id="getOrders1" parameterClass="com.air.Account"
resultClass="com.air.Product">
SELECT
orders.id as id,
orders.product as product,
orders.customer as customer
FROM orders
<dynamic prepend=" WHERE ">
<isNull property="username">customer IS NOT NULL</isNull>
<isNotNull property="username">
orders.customer=#username#
</isNotNull>
</dynamic>
</select>
<!-- 动态查询2-->
<select id="getOrders2" parameterClass="com.air.Account"
resultClass="com.air.Product">
SELECT
o.id as id,
o.product as product,
o.customer as customer
FROM orders o
<isNotNull property="username">
INNER JOIN user_account a ON o.customer=a.username
</isNotNull>
<dynamic prepend="where ">
<isNotEmpty property="groupname" prepend="and " open="(" close=")">
a.groupname=#groupname#
</isNotEmpty>
</dynamic>
</select>
<!-- 动态查询3-->
<select id="getOrders3" parameterClass="com.air.Product"
resultClass="com.air.Product">
SELECT
orders.id as id,
orders.product as product,
orders.customer as customer
FROM orders
<dynamic prepend="WHERE ">
<isNotEmpty property="product" prepend="and" open="(" close=")" removeFirstPrepend="true">
product=#product#
</isNotEmpty>
<isNotEmpty property="customer" prepend="and" open="(" close=")">
customer=#customer#
</isNotEmpty>
</dynamic>
</select>
<!-- 动态查询4-->
<select id="getOrders4" parameterClass="com.air.Product"
resultClass="com.air.Product">
SELECT
*
FROM orders
<dynamic prepend="WHERE ">
<iterate property="keywords" open="(" close=")" conjunction="OR">
product=#keywords[]#
</iterate>
</dynamic>
<!-- <dynamic prepend="WHERE product IN ">-->
<!-- <iterate property="keywords" open="(" close=")" conjunction=","> -->
<!-- #keywords[]#-->
<!-- </iterate>-->
<!-- </dynamic>-->
</select>
</sqlMap>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap>
<!-- 动态查询1-->
<select id="getOrders1" parameterClass="com.air.Account"
resultClass="com.air.Product">
SELECT
orders.id as id,
orders.product as product,
orders.customer as customer
FROM orders
<dynamic prepend=" WHERE ">
<isNull property="username">customer IS NOT NULL</isNull>
<isNotNull property="username">
orders.customer=#username#
</isNotNull>
</dynamic>
</select>
<!-- 动态查询2-->
<select id="getOrders2" parameterClass="com.air.Account"
resultClass="com.air.Product">
SELECT
o.id as id,
o.product as product,
o.customer as customer
FROM orders o
<isNotNull property="username">
INNER JOIN user_account a ON o.customer=a.username
</isNotNull>
<dynamic prepend="where ">
<isNotEmpty property="groupname" prepend="and " open="(" close=")">
a.groupname=#groupname#
</isNotEmpty>
</dynamic>
</select>
<!-- 动态查询3-->
<select id="getOrders3" parameterClass="com.air.Product"
resultClass="com.air.Product">
SELECT
orders.id as id,
orders.product as product,
orders.customer as customer
FROM orders
<dynamic prepend="WHERE ">
<isNotEmpty property="product" prepend="and" open="(" close=")" removeFirstPrepend="true">
product=#product#
</isNotEmpty>
<isNotEmpty property="customer" prepend="and" open="(" close=")">
customer=#customer#
</isNotEmpty>
</dynamic>
</select>
<!-- 动态查询4-->
<select id="getOrders4" parameterClass="com.air.Product"
resultClass="com.air.Product">
SELECT
*
FROM orders
<dynamic prepend="WHERE ">
<iterate property="keywords" open="(" close=")" conjunction="OR">
product=#keywords[]#
</iterate>
</dynamic>
<!-- <dynamic prepend="WHERE product IN ">-->
<!-- <iterate property="keywords" open="(" close=")" conjunction=","> -->
<!-- #keywords[]#-->
<!-- </iterate>-->
<!-- </dynamic>-->
</select>
</sqlMap>