ibatis dynamic (bulk) update

ibatis dynamic (bulk) update

CreateTime--May 3, 2018 17:04:49

Author:Marydon

1.4.2.3 Batch modification

  Support single dynamic update, batch dynamic update

<update id="updateCONSULT_SCHEDULEDynamic" parameterClass="map">
    UPDATE CONSULT_SCHEDULE
    <dynamic prepend="set">
        <isNotEmpty prepend="," property="ORG_CODE">
            ORG_CODE = #ORG_CODE#
        </isNotEmpty>
        <isNotEmpty prepend="," property="DEPENT_ID">
            DEPENT_ID = #DEPENT_ID#
        </isNotEmpty>
        <isNotEmpty prepend="," property="DEPENT_NAME">
            DEPENT_NAME = #DEPENT_NAME#
        </isNotEmpty>
        <isNotEmpty prepend="," property="DOCTOR_ID">
            DOCTOR_ID = #DOCTOR_ID#
        </isNotEmpty>
        <isNotEmpty prepend="," property="DOCTOR_NAME">
            DOCTOR_NAME = #DOCTOR_NAME#
        </isNotEmpty>
        <isNotEmpty prepend="," property="DOCTOR_PHONE">
            DOCTOR_PHONE = #DOCTOR_PHONE#
        </isNotEmpty>
        <isNotEmpty prepend="," property="SCHEDULE_DATE">
            SCHEDULE_DATE = TO_DATE(#SCHEDULE_DATE#,'YYYY-MM-DD')
        </isNotEmpty>
        <isNotEmpty prepend="," property="WEEK_TXT">
            WEEK_TXT = #WEEK_TXT#
        </isNotEmpty>
        <isNotEmpty prepend="," property="WB_TYPE">
            WB_TYPE = #WB_TYPE#
        </isNotEmpty>
        <isNotEmpty prepend="," property="CLOSE_TZ">
            CLOSE_TZ = #CLOSE_TZ#
        </isNotEmpty>
        <isNotEmpty prepend="," property="REPLACE_TZ">
            REPLACE_TZ = #REPLACE_TZ#
        </isNotEmpty>
        <isNotEmpty prepend="," property="DOCTOR_ID_TZ">
            DOCTOR_ID_TZ = #DOCTOR_ID_TZ#
        </isNotEmpty>
        <isNotEmpty prepend="," property="DOCTOR_NAME_TZ">
            DOCTOR_NAME_TZ = #DOCTOR_NAME_TZ#
        </isNotEmpty>
        <isNotNull prepend="," property="REMARK">
            REMARK = #REMARK#
        </isNotNull>
    </dynamic>
    WHERE CONSULT_SCHEDULE_ID IN ($CONSULT_SCHEDULE_ID$)
</update>

      Notice:

        a. This batch update can only uniformly change the value (status) of a certain (several) table fields;

        b. During batch operation, iBATIS is implemented by using the in() function. The content in the in() function can only be implemented through "$variable$", not through "#variable#";

        c. Modify according to the id. If the id is a string, when passing parameters in the front desk, you need to manually splicing the string.

      Example:

        Taking id as a string as an example, explain how the front desk obtains the value of the page and transmits it to the backend and how iBATIS maps the passed value

        The first part: js value

          See article: Checkbox-checkbox

        Part 2: Dao calls SQL

/**
 * Dynamically modify shift schedule table records
 *
 * @param paramMap Schedule table map object collection
 * @return returns the number of rows affected by the operation
 * @throws DaoException
 */
public int updateCONSULT_SCHEDULEDynamic(Map paramMap) throws DaoException {
    try {
        return sqlMapClient.update("telemedicine.service.bo.remoteCons.schedule.updateCONSULT_SCHEDULEDynamic", paramMap);
    } catch (SQLException e) {
        String err = "Error in modifying the schedule table -> Reason for error:" + e.getMessage();
        log.error(err, e);
        throw new DaoException(err, e);
    }
}

      Part 3: SQL, see above

    illustrate:

      a. Using in(#CONSULT_SCHEDULE_ID#), the parsed result is: in('id1,id2'); (error)

      b. Using in($CONSULT_SCHEDULE_ID$), the parsed result is: in('id1','id2'); (correct)

wrong usage

  Scenario description

 

 related suggestion:

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325256686&siteId=291194637