在ibatis 拼接sql语句,动态查询
2008-01-25 11:29
555 查看
在ibatis中使用安全的拼接语句,动态查询
ibatis比JDBC的优势之一,安全高效
说明文字在注释中
<select id="selectAllProducts" parameterClass="Product" resultMap="ProductResult">
select id,note from Product
<dynamic prepend="WHERE">
<!-- isNotNull判断参数是否存在,Integer类型 -->
<isNotNull property="id">
<!-- isGreaterThan判断参数是否大于compareValue,isGreaterEquals是大于等于 -->
<isGreaterThan prepend=" and " property="id" compareValue="0">
id = #id#
</isGreaterThan>
</isNotNull>
<!-- isNotEmpty判断字串不为空,isEmpty可以判断字串为空 -->
<isNotEmpty prepend=" and " property="note">
<!-- 模糊查询不能用#,#在是用prepareStatement的?插入参数,$是文本替换 -->
note like '%$note$%'
</isNotEmpty>
</dynamic>
</select>
用Map传参数
<select id="selectAllProducts" parameterClass="java.util.HashMap" resultMap="ProductResult">
select id,note from Product
<dynamic prepend="WHERE">
<!-- isPropertyAvailable判断属性是否有效 -->
<isPropertyAvailable property="id">
<isNotNull property="id">
<!-- isLessThan判断参数是否小于compareValue,isLessEquals是小于等于 -->
<isLessThan prepend=" and " property="id" compareValue="10">
id = #id#
</isLessThan>
</isNotNull>
</isPropertyAvailable>
</dynamic>
</select>
------------------------------------------------------------------几个常用属性
<isPropertyAvailable> 属性是存在
<isNotPropertyAvailable> 属性不存在
<isNull> 属性值是null
<isEmpty> 判断Collection.size<1或String.length()<1
<isEqual> 等于
<isNotEqual> 不等于
<isGreaterThan> 大于
<isGreaterEqual> 大于等于
<isLessThan> 小于
<isLessEqual> 小于等于
ibatis比JDBC的优势之一,安全高效
说明文字在注释中
<select id="selectAllProducts" parameterClass="Product" resultMap="ProductResult">
select id,note from Product
<dynamic prepend="WHERE">
<!-- isNotNull判断参数是否存在,Integer类型 -->
<isNotNull property="id">
<!-- isGreaterThan判断参数是否大于compareValue,isGreaterEquals是大于等于 -->
<isGreaterThan prepend=" and " property="id" compareValue="0">
id = #id#
</isGreaterThan>
</isNotNull>
<!-- isNotEmpty判断字串不为空,isEmpty可以判断字串为空 -->
<isNotEmpty prepend=" and " property="note">
<!-- 模糊查询不能用#,#在是用prepareStatement的?插入参数,$是文本替换 -->
note like '%$note$%'
</isNotEmpty>
</dynamic>
</select>
用Map传参数
<select id="selectAllProducts" parameterClass="java.util.HashMap" resultMap="ProductResult">
select id,note from Product
<dynamic prepend="WHERE">
<!-- isPropertyAvailable判断属性是否有效 -->
<isPropertyAvailable property="id">
<isNotNull property="id">
<!-- isLessThan判断参数是否小于compareValue,isLessEquals是小于等于 -->
<isLessThan prepend=" and " property="id" compareValue="10">
id = #id#
</isLessThan>
</isNotNull>
</isPropertyAvailable>
</dynamic>
</select>
------------------------------------------------------------------几个常用属性
<isPropertyAvailable> 属性是存在
<isNotPropertyAvailable> 属性不存在
<isNull> 属性值是null
<isEmpty> 判断Collection.size<1或String.length()<1
<isEqual> 等于
<isNotEqual> 不等于
<isGreaterThan> 大于
<isGreaterEqual> 大于等于
<isLessThan> 小于
<isLessEqual> 小于等于
相关文章推荐
- 在ibatis框架中 拼接sql语句,动态查询 .
- 使用反射让linq实现动态查询, 类似拼接sql语句的where 条件
- 动态sql语句拼接查询条件
- hibernate根据条件动态组装sql/hql语句(仿ibatis动态查询语句功
- 根据条件查询动态拼接sql语句
- ibatis Dynamic总结(ibatis使用安全的拼接语句,动态查询)
- ibatis中使用安全的拼接语句,动态查询,大于、小于、等于
- Hibernate_根据条件动态组装sql/hql语句(仿ibatis动态查询语句功能)
- 使用log4net记录ibatis.net的SQL动态查询语句
- 使用反射让linq实现动态查询, 类似拼接sql语句的where 条件
- hibernate根据条件动态组装sql/hql语句(仿ibatis动态查询语句功能)
- sql不用拼接语句实现动态查询条件
- 多条件查询--使用dapper命令参数动态拼接出最安全的sql语句
- hibernate根据条件动态组装sql/hql语句(仿ibatis动态查询语句功能)
- 【转】ibatis.net中的单个参数查询、多个参数查询和实体类查询以及动态SQL语句生成查询
- hibernate根据条件动态组装sql/hql语句(仿ibatis动态查询语句功能)
- hibernate根据条件动态组装sql/hql语句(仿ibatis动态查询语句功能)
- IBATIS 的动态SQL语句拼接
- 根据参数指定的列名和值查询员工信息(使用动态sql语句)
- ibatis获取运行时的动态SQL语句及其参数