zoukankan      html  css  js  c++  java
  • ibatis中iterate

    查询条件dto

    public class queryCondition
    {
    private String[] stuIds;
    private String name;
    }

    查询sqlMap

    <select id="selectStu" parameterClass="cn.xy.queryCondition" resultClass="cn.xy.Student">
     select id,name from student
     <dynamic prepend="where">
      <isNotNull property="stuIds" prepend="and">
       <iterate property="stuIds" open="id in (" close=")" conjunction=",">
        #stuIds[]#
       </iterate>
      </isNotNull>
      <isNotNull property="name" prepend="and">
       name like '%$name$%'
      </isNotNull>
     </dynamic>
    </select>
    

    在查询条件中有一个数组stuIds,在动态标签中进行遍历,看每一个student的id是否在该数组中。

    发出的语句 select id,name from student where id in ( ? , ?) ...

    二.查询条件dto

    public class queryCondition
    {
    private List lst;
    private String name;
    }

    查询sqlMap

    <select id="selectStu" parameterClass="cn.xy.queryCondition" resultClass="cn.xy.Student">
     select id,name from student
     <dynamic prepend="where">
      <isNotNull property="lst" prepend="and">
       <iterate property="lst" open=" (" close=")" conjunction="or">
        id = #lst[].id#
       </iterate>
      </isNotNull>
      <isNotNull property="name" prepend="and">
       name like '%$name$%'
      </isNotNull>
     </dynamic>
    </select>
    

    发出的语句 select id,name from student where (id = ? or id = ?)

  • 相关阅读:
    Nginx+Keepalived实现简单的服务高可用
    搭建私有镜像仓库
    GlusterFS
    GlusterFS分布式存储系统
    GlusterFS分布式存储
    ladp日志配置
    go mod位置和自定义包引入问题
    .netcore 使用redis
    一篇技术博文引发的stylelint项目实践
    React Hooks使用避坑指南
  • 原文地址:https://www.cnblogs.com/taoziBlogs/p/14912977.html
Copyright © 2011-2022 走看看