zoukankan      html  css  js  c++  java
  • 记录一次mabatis 查询不到数据问题

         原来写的mapper方法:

       

    List<InterCityTeam> queryTeamsByParam(@Param("cityId") Integer cityId,
                                   @Param("supplierId") Integer supplierId,
                                   @Param("teamId")Integer teamId,
                                   @Param("teamIdList")List<Integer> teamIdList,
                                          @Param("cityIds") Set<Integer> cityIds,
                                          @Param("supplierIds") Set<Integer> supplierIds);

    对应的方法:

      <select id="queryTeamsByParam" resultMap="BaseResultMap"   >
        select
        <include refid="Base_Column_List" />
        from inter_city_team
        where  1=1
        <if test="cityId != null" >
          AND city_id = #{cityId,jdbcType=INTEGER}
        </if>
    
        <if test="supplierId != null" >
          and supplier_id = #{supplierId,jdbcType=INTEGER}
        </if>
    
        <if test="teamId != null" >
          and id = #{teamId,jdbcType=INTEGER}
        </if>
    
        <if test="teamIdList != null and teamIdList.size() > 0" >
          and id in
          <foreach collection="teamIdList" open="(" close=")" item="id" separator="," >
            #{id}
          </foreach>
        </if>
     <if test="cityIds != null and cityIds.size() > 0" >
    and city_id in
    <foreach collection="cityIds" open="(" close=")" item="cityId" separator="," >
    #{cityId}
    </foreach>
    </if>


    <if test="supplierIds != null and supplierIds.size() > 0" >
    and supplier_id in
    <foreach collection="supplierIds" open="(" close=")" item="supplierId" separator="," >
    #{supplierId}
    </foreach>
    </if>

    ORDER BY update_time DESC
    </select>

        然后发现当传入cityId时候死活出不来数据,最后没办法就一直调试。最后发现把cityId换个别名就可以了。猜测是不是和我在force里面定义的item也叫cityId 有关。

       

      <select id="queryTeamsByParam" resultMap="BaseResultMap"   >
        select
        <include refid="Base_Column_List" />
        from inter_city_team
        where  1=1
        <if test="cityIdParam != null" >
          AND city_id = #{cityIdParam,jdbcType=INTEGER}
        </if>
    
        <if test="supplierId != null" >
          and supplier_id = #{supplierId,jdbcType=INTEGER}
        </if>
    
        <if test="teamId != null" >
          and id = #{teamId,jdbcType=INTEGER}
        </if>
    
        <if test="teamIdList != null and teamIdList.size() > 0" >
          and id in
          <foreach collection="teamIdList" open="(" close=")" item="id" separator="," >
            #{id}
          </foreach>
        </if>
    
    
        <if test="cityIds != null and cityIds.size() > 0" >
          and city_id in
          <foreach collection="cityIds" open="(" close=")" item="cityId" separator="," >
            #{cityId}
          </foreach>
        </if>
    
    
        <if test="supplierIds != null and supplierIds.size() > 0" >
          and supplier_id in
          <foreach collection="supplierIds" open="(" close=")" item="supplierId" separator="," >
            #{supplierId}
          </foreach>
        </if>
    
        ORDER BY update_time DESC
      </select>
  • 相关阅读:
    thymeleaf是用于编写html模版的编程语言(工具语言)
    前端页面生成技术
    算法是用逻辑语言描述的问题求解步骤
    模板引擎
    递归与分形
    泛型的特征-为什么使用泛型(集合理论)
    算法沉思录-算法的描述(草稿)
    计算机语言发展史
    pHP生成唯一单号
    laravel实现批量添加数据
  • 原文地址:https://www.cnblogs.com/thinkingandworkinghard/p/13432730.html
Copyright © 2011-2022 走看看