首页 > 技术文章 > SpringMvc的xml里关于<if>里传递多个参数(包含List、Integer、String)

supiaopiao 2020-02-18 14:08 原文

dao层:

List<ProjectCompanyOrg> findProCompanyListByOrgIds(@Param("orgIdList") List<Integer> orgIdList, @Param("orgName") String orgName, @Param("projectId") Integer projectId);
 

xml层:

<select id="findProCompanyOrgListByOrgIds" resultType="com.highgoal.group.project.domain.entity.ProjectCompanyOrg">
    select a.id as aid,a.org_id , b.*
    from project_company_org_unti a
    join project_company_org b on a.project_company_org_id = b.project_company_org_id
    <where>
      a.del = 0 and b.del = 0
      <if test="orgIdList.size()!=0">
        and a.org_id in
        <foreach collection="orgIdList" index="index" item="item" open="(" separator="," close=")">
          #{item}
        </foreach>
      </if>
      <if test="orgName != null and orgName != ''">
        and b.org_name like concat('%',concat(#{orgName},'%'))
      </if>
      <if test="projectId != null">
        and b.project_id = #{projectId,jdbcType=INTEGER}
      </if>
    </where>
  </select>

 

 

查询时间区间,用between...and语法

实体类:

private String startTime;

private String endTime;

 

 

xml:

<if test="startTime != null and endTime != null">
    and date_format(create_time,'%Y-%m') between #{startTime,jdbcType=TIMESTAMP} and #{endTime,jdbcType=TIMESTAMP}
</if>

 

推荐阅读