본문 바로가기
DataBase

mybatis 문법 foreach

by 아이티.파머 2021. 4. 2.
반응형

리스트객체로 보낼경우 parameterType="java.util.List" , collection = "list"로 받아서 처리 한다.

 

this.jobMapper.findAllByJobId(List.of(masterJobId)

<select id="findAllByJobId" parameterType="java.util.List" resultType="com.cjenm.report.library.domain.entity.JobEntity">
    SELECT
    `job_execution_id`,
    `master_job_id` as `job_id`,
    `job_name`,
    `total_size`,
    `processed_count`,
    `start_time`,
    `end_time`,
    `status`,
    `exit_status`,
    `message`,
    `request_details`,
    `requester`,
    `last_update`
    FROM `master_job_management`
    WHERE 1=1
    AND `master_job_id` in
    <foreach item="jobIds" collection="list" open="(" close=")" separator=",">
        #{jobIds}
    </foreach>

</select>

 

Map 객체 안에 Object로 보내는 경우 collection="masterJobIds" 와 같이 Parameter key 값을 적어 준다.

Map<String,Object> parameter = new HashMap<>();
parameter.put("jobEntity",jobEntity);
parameter.put("masterJobIds",List.of(jobId));
parameter.put("jobExecutionId", jobExecutionId);

<update id="updateStatus" parameterType="Map">
    UPDATE `master_job_management`
    SET
    `status` = #{jobEntity.status},
    `processed_count` = #{jobEntity.processedCount},
    `last_update` = #{jobEntity.lastUpdate}
    WHERE 1=1

    <if test="jobExecutionId != null and jobExecutionId != ''">
        AND job_execution_id = #{jobExecutionId}
    </if>
    AND `master_job_id` in
    <foreach item="jobIds" collection="masterJobIds" open="(" close=")" separator=",">
        #{jobIds}
    </foreach>
    AND status = 'RUNNING';
</update>

 

반응형

'DataBase' 카테고리의 다른 글

무료 ERD 추천  (0) 2021.11.22
Aerospike  (0) 2018.04.09
MSSQL LPAD  (0) 2011.03.25