zoukankan      html  css  js  c++  java
  • ibatis的iterate使用

    Iterate:这属性遍历整个集合,并为 List 集合中的元素重复元素体的内容。 
    Iterate 的属性: 
          prepend  - 可被覆盖的 SQL 语句组成部分,添加在语句的前面(可选) 
          property  - 类型为 java.util.List 的用于遍历的元素(必选) 
          open  -  整个遍历内容体开始的字符串,用于定义括号(可选) 
          close  -整个遍历内容体结束的字符串,用于定义括号(可选) 
          conjunction -  每次遍历内容之间的字符串,用于定义 AND 或 OR(可选) 
          遍历类型为 java.util.List的元素。 

    例子: 
    <iterate prepend=”AND” property=”userNameList” 
    open=”(” close=”)” conjunction=”OR”> 
    username=#userNameList[]# 
    </iterate>

    ibatis中如何配置in语句,需要迭代,不能直接用string的写法
    <select id="sql_test" parameterclass="myPramBean" resultclass="myResult">
    select *from tablewhere name in 
    <iterate property="ids" conjunction="," close=")" open="(" /> 
    #value[]# 
    </iterate>
    and code=#code#
    </select>
    myPramBean
    {
    private String code;
    private List ids;
    ...


    eg:
    <delete id="member.batchDelete" parameterClass="java.util.List">
          DELETE FROM member where id IN
          <iterate conjunction="," open="(" close=")" >
              #value[]# 
          </iterate>
    </delete>

    注意:使用<iterate>时,在List元素名后面包括方括号[]非常重要,方括号[]将
    对象标记为List,以防解析器简单地将List输出成String。

    posted on 2010-02-02 15:49 飞熊 阅读(20034) 评论(3)  编辑  收藏 所属分类: Ibatis

    评论

    # re: ibatis的iterate使用 2011-10-06 01:10 wiky

    ibatis中如何配置in语句,需要迭代,不能直接用string的写法
    <select id="sql_test" parameterclass="myPramBean" resultclass="myResult">
    select *from tablewhere name in 
    <iterate property="ids" conjunction="," close=")" open="(" /> 
    #value[]# 
    </iterate>
    and code=#code#
    </select>

    #value[]# 要改成#ids[]# 才行  回复  更多评论   

    # re: ibatis的iterate使用[未登录] 2013-08-22 13:36 呵呵

    第三种:in后面的数据确定,使用string传入 
    <select id="GetEmailList_Test2" parameterClass="TestIn" resultClass="EmailInfo_"> 
    select * 
    from MailInfo with (nolock) 
    where ID in 
    ($StrValue$) 
    </select>

  • 相关阅读:
    关注Imagine cup 2010Palantir智能公交系统
    Windows Media Player Application Sample Code Analysis (Mobile 6.5.3)
    Oracle客户端穿过防火墙连接服务器
    国内最大的IT门户天极网也采用了博客园的.TEXT程序
    基于深度优先的递归判断域用户是否是某个组的成员
    Oracle外部身份认证研究
    在Oracle中用存储过程发中文的HTML邮件
    cnblogs .text系统配置主要操作简介
    适合于初学者的一些小技巧
    我在cnblog .text基础上做的适应性修改
  • 原文地址:https://www.cnblogs.com/Struts-pring/p/5127500.html
Copyright © 2011-2022 走看看