在ibatis 拼接sql语句
889次浏览
编辑于2015年09月23日 23:39:56
Ibatis允许程序员自己编写SQL语句来实现DAO层的操作,让dao层的操作更加灵敏而方便,ibatis中还提供动态拼接sql方式,这样开发者可以减少很多sql的编写。如下代码:<select id="selectAllProducts" parameterClass="Product" resultMap="ProductResult">
select id,note from Product
<dynamic prepend="WHERE">
<isNotNull property="id">
<isGreaterThan prepend=" and " property="id" compareValue="0">
id = #id#
isGreaterThan>
isNotNull>
<isNotEmpty prepend=" and " property="note">
note like '%$note$%'
isNotEmpty>
dynamic>
select>
select id,note from Product
<dynamic prepend="WHERE">
<isNotNull property="id">
<isGreaterThan prepend=" and " property="id" compareValue="0">
id = #id#
isGreaterThan>
isNotNull>
<isNotEmpty prepend=" and " property="note">
note like '%$note$%'
isNotEmpty>
dynamic>
select>
推荐阅读