• 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>

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

  • 相关阅读:
    inotify+rsync做实时同步
    JAVA序列化和反序列化
    初识iBatis
    《Spring in action》之高级装配
    《Spring in action》之装配Bean
    原根
    数论知识
    线性(欧拉)筛
    Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) E DNA Evolution
    Fibonacci
  • 原文地址:https://www.cnblogs.com/zuge/p/5886039.html
Copyright © 2020-2023  润新知