Mybatis中的in查询和foreach标签  Mybatis中的foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合。 (3)

  //分页数据组装
  Container<Map<String,Object>> container = new Container<Map<String,Object>>();
  List<Map<String,Object>> auditModelList = cmApplicationRepo.findAuditList(params);
  for(Map<String,Object> audit:auditModelList){ 
    //设置是否关注过
    Long auditId = Long.parseLong(audit.get("auditId").toString());
    Long auditPersonId = Long.parseLong(params.get("auditPersonId").toString());
    Map<String, Object> followMap = new HashMap<String,Object>();
    followMap.put("sourceType", DictConstants.FOLLOW_SOURCE_TYPE.FOLLOW_APPLICATION);
    followMap.put("sourceId", auditId);
    followMap.put("userId", auditPersonId);
    List<BizFollowModel> followList = bizFollowService.find(followMap);
    if(followList!= null && followList.size()>0){
      audit.put("isFollow", "true");
    }else{
      audit.put("isFollow", "false");
    }
  }
  container.setList(auditModelList);
  container.setTotalNum(cmApplicationRepo.countAuditListNumber(params));
  return container;
}

DAO

@Override
public List<Map<String,Object>> findAuditList(Map<String, Object> map) {
  return findList("getAuditList", map);
}

xml

<!-- 查询申请列表-->
<select resultType="java.util.Map" parameterType="map">
  select
    a.ID AS id,
    a.STATE AS stateCode, b.DICT_VALUE AS stateValue,
    a.ITEM AS itemCode, c.DICT_VALUE AS itemValue,
    a.TYPE AS typeCode, d.DICT_VALUE AS typeValue,
    a.APP_PERSON_ID AS appPersonId,
    a.CREATE_TIME AS createTime

  from cm_application a 
  LEFT JOIN cm_dict_type b on a.STATE = b.DICT_CODE AND b.TYPE = \'Application_State\'
  LEFT JOIN cm_dict_type c on a.ITEM = c.DICT_CODE 
  LEFT JOIN cm_dict_type d on a.TYPE = d.DICT_CODE

  where 1=1
  <if test="item != null" >
    and a.ITEM = #{item,jdbcType=VARCHAR}
    </if>
    <if test="type != null" > 
      and a.TYPE IN 
      <foreach item="typeArray" index="index" collection="type" open="(" separator="," close=")">
        #{typeArray}
      </foreach>
    </if>
    <if test="appPersonId != null" >
      and a.APP_PERSON_ID = #{appPersonId,jdbcType=BIGINT}
    </if>
    <if test="state != null" >
      and a.STATE IN 
      <foreach item="stateArray" index="index" collection="state" open="(" separator="," close=")">
        #{stateArray}
      </foreach>
    </if>
    <!-- 分页查询时,要选择createTime在starCreateTime和endCreatetTime之间的记录 -->
    <if test="startCreateTime != null" >
      and a.CREATE_TIME &gt;= #{startCreateTime,jdbcType=TIMESTAMP}
    </if>
    <if test="endCreateTime != null" >
      and a.CREATE_TIME &lt;= #{endCreateTime,jdbcType=TIMESTAMP}
    </if>
  order by a.ID
  <include refid="Paging" />
</select>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwzsdp.html