iBATIS动态查询的实现浅析

来源:互联网 发布:人体解剖软件 编辑:程序博客网 时间:2024/06/05 11:57

 http://developer.51cto.com/art/200907/136553.htm

http://developer.51cto.com/art/200907/138596.htm

 

iBATIS动态查询是如何实现的呢?我们将会在本篇文章内向你介绍iBATIS动态查询的情况

 

iBATIS动态查询的实现主要是在iBATIS中使用安全的拼接语句,动态查询

iBATIS比JDBC的优势之一,安全高效

iBATIS动态查询实例:(说明文字在注释中)

  1. ﹤ select  id ="selectAllProducts"  parameterClass ="Product"  resultMap ="ProductResult" ﹥   
  2.  select id,note from Product  
  3.      ﹤ dynamic  prepend ="WHERE" ﹥   
  4.      ﹤!--  isNotNull判断参数是否存在,Integer类型  --﹥   
  5.           ﹤ isNotNull  property ="id" ﹥   
  6.               ﹤!--  isGreaterThan判断参数是否大于compareValue,isGreaterEquals是大于等于  --﹥   
  7.               ﹤ isGreaterThan  prepend =" and "  property ="id"  compareValue ="0" ﹥   
  8.              id = #id#  
  9.               ﹤/ isGreaterThan ﹥   
  10.           ﹤/ isNotNull ﹥   
  11.           ﹤!--  isNotEmpty判断字串不为空,isEmpty可以判断字串为空  --﹥   
  12.           ﹤ isNotEmpty  prepend =" and "  property ="note" ﹥   
  13.           ﹤!--  模糊查询不能用#,#在是用prepareStatement的?插入参数,$是文本替换  --﹥   
  14.          note like '%$note$%' 
  15.           ﹤/ isNotEmpty ﹥   
  16.       ﹤/ dynamic ﹥   
  17. ﹤/ select ﹥ 

iBATIS动态查询解释:

用Map传参数

  1. ﹤ select  id ="selectAllProducts"  parameterClass ="java.util.HashMap"  resultMap ="ProductResult" ﹥   
  2.   select id,note from Product  
  3.       ﹤ dynamic  prepend ="WHERE" ﹥   
  4.       ﹤!--  isPropertyAvailable判断属性是否有效  --﹥   
  5.          ﹤ isPropertyAvailable  property ="id" ﹥   
  6.            ﹤ isNotNull  property ="id" ﹥   
  7.                ﹤!--  isLessThan判断参数是否小于compareValue,isLessEquals是小于等于  --﹥   
  8.                ﹤ isLessThan  prepend =" and "  property ="id"  compareValue ="10" ﹥   
  9.               id = #id#  
  10.                ﹤/ isLessThan ﹥   
  11.            ﹤/ isNotNull ﹥   
  12.          ﹤/ isPropertyAvailable ﹥   
  13.        ﹤/ dynamic ﹥   
  14.  ﹤/ select ﹥ 

iBATIS动态查询几个常用属性

﹤ isPropertyAvailable ﹥  属性是存在

﹤ isNotPropertyAvailable ﹥  属性不存在

﹤ isNull ﹥  属性值是null

﹤ isEmpty ﹥  判断Collection.size ﹤ 1 或String.length()﹤1

﹤isEqual ﹥  等于

﹤ isNotEqual ﹥  不等于

﹤ isGreaterThan ﹥  大于

﹤ isGreaterEqual ﹥  大于等于

﹤ isLessThan ﹥  小于

﹤ isLessEqual ﹥  小于等于

iBATIS动态查询的相关信息就向你介绍到这里,希望对你了解iBATIS动态查询有所帮助。

原创粉丝点击