zoukankan      html  css  js  c++  java
  • Mybaits 之根据集合查询和逗号分隔的子查询

     这是我们的mapper要根据传入一个集合进行查询:

    List<ExtKeywordCategory> findListByIds(List<ExtKeywordFkCategory> extKeywordFkCategoryList);

    对应的xml

     <select id="findListByIds" resultType="com.ebrun.newcms.modules.extend.model.ExtKeywordCategory" parameterType="java.util.List">
        select 
        <include refid="Base_Column_List" />
        from ext_keywordCategory a
        <where>
        id in 
        <foreach item="item" index="index" collection="list" open="(" separator="," close=")">  
          #{item.categoryid}  
         </foreach>
        </where>
      </select>

    关于foreach的属性


    第二种

    前台传入的格式为字符串的,例如89,100那么我们可以这么处理

    mapper:

    List<ExtKeywordCategory> getListByIds(@Param("categoryids") String categoryids);

    xml:

    <select id="getListByIds" resultType="com.ebrun.newcms.modules.extend.model.ExtKeywordCategory">
       select 
        <include refid="Base_Column_List" />
        from ext_keywordCategory 
        <where>
        id in (${categoryids})
        </where>
      </select>

     需要注意的是#和$的区别

  • 相关阅读:
    ListCtrl中垂直滚动条自动滚动
    auth组件
    母版的继承
    mysql数据备份和恢复
    部署MHA
    安装mysql
    yum源优化
    存储过程
    redis哨兵、集群
    redis主从同步
  • 原文地址:https://www.cnblogs.com/zuge/p/5886039.html
Copyright © 2011-2022 走看看