zoukankan      html  css  js  c++  java
  • mybatisPlus的一些用法(一)trim、foreach、if、case、when、then

    1、在项目开发中遇到一些新的知识点、在这里做以总结。

      (1)

        <trim></trim>标签、

    <foreach></foreach>标签
     <update id="updateBatch" parameterType="java.util.Map">
            update salary_insurance_benefit_person
            <trim prefix="set" suffixOverrides=",">
                <trim prefix="remarks=case" suffix="end,">
                    <foreach collection="list" item="cus">
                        <if test="cus.remarks != null  and cus.remarks != ''">
                            when id=#{cus.id} then #{cus.remarks}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="enabled=case" suffix="end,">
                    <foreach collection="list" item="cus">
                        <if test="cus.enabled != null ">
                            when id=#{cus.id} then #{cus.enabled}
                        </if>
                    </foreach>
                </trim>
    
                <trim prefix="tenant_code=case" suffix="end,">
                    <foreach collection="list" item="cus">
                        <if test="cus.tenantCode != null and cus.tenantCode != '' ">
                            when id=#{cus.id} then #{cus.tenantCode}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="salary_common_type_id=case" suffix="end,">
                    <foreach collection="list" item="cus">
                        <if test="cus.salaryCommonTypeId != null ">
                            when id=#{cus.id} then #{cus.salaryCommonTypeId}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="salary_accounting_person_id=case" suffix="end,">
                    <foreach collection="list" item="cus">
                        <if test="cus.salaryAccountingPersonId != null ">
                            when id=#{cus.id} then #{cus.salaryAccountingPersonId}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="seniority=case" suffix="end,">
                    <foreach collection="list" item="cus">
                        <if test="cus.seniority != null ">
                            when id=#{cus.id} then #{cus.seniority}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="attendance_months=case" suffix="end,">
                    <foreach collection="list" item="cus">
                        <if test="cus.attendanceMonths != null ">
                            when id=#{cus.id} then #{cus.attendanceMonths}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="endowment_insurance=case" suffix="end,">
                    <foreach collection="list" item="cus">
                        <if test="cus.endowmentInsurance != null ">
                            when id=#{cus.id} then #{cus.endowmentInsurance}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="medical_insurance=case" suffix="end,">
                    <foreach collection="list" item="cus">
                        <if test="cus.medicalInsurance != null ">
                            when id=#{cus.id} then #{cus.medicalInsurance}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="unemployment_insurance=case" suffix="end,">
                    <foreach collection="list" item="cus">
                        <if test="cus.unemploymentInsurance != null ">
                            when id=#{cus.id} then #{cus.unemploymentInsurance}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="physical_welfare=case" suffix="end,">
                    <foreach collection="list" item="cus">
                        <if test="cus.physicalWelfare != null ">
                            when id=#{cus.id} then #{cus.physicalWelfare}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="spring_welfare=case" suffix="end,">
                    <foreach collection="list" item="cus">
                        <if test="cus.springWelfare != null ">
                            when id=#{cus.id} then #{cus.springWelfare}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="other_welfare=case" suffix="end,">
                    <foreach collection="list" item="cus">
                        <if test="cus.otherWelfare != null ">
                            when id=#{cus.id} then #{cus.otherWelfare}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="last_modified_by =case" suffix="end,">
                    <foreach collection="list" item="cus">
                        <if test="cus.lastModifiedBy != null">
                            when id=#{cus.id} then #{cus.lastModifiedBy}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="last_modified_date =case" suffix="end,">
                    <foreach collection="list" item="cus">
                        <if test="cus.lastModifiedDate != null ">
                            when id=#{cus.id} then #{cus.lastModifiedDate}
                        </if>
                    </foreach>
                </trim>
            </trim>
            <where>
                <foreach collection="list" separator="or" item="cus">
                    id = #{cus.id}
                </foreach>
            </where>
        </update>

    2<foreach></foreach>标签

     <foreach collection="list" index="index" item="item" separator="," >
                (
                #{item.organizationId}
              )
    </foreach>

    <foreach item="id" collection="list" open="(" separator="," close=")">
    #{id}
    </foreach>

    3.在做修改的时候、修改版本(version)字段的。

    <update id="updateById">
            UPDATE salary_accounting_person
            SET organization_id=#{et.organizationId},
                salary_common_type_id=#{et.salaryCommonTypeId},
                salary_program_id=#{et.salaryProgramId},
                employee_id=#{et.employeeId},
                salary_year=#{et.salaryYear},
                salary_month=#{et.salaryMonth},
                accounting=#{et.accounting},
                stop_salary_date=#{et.stopSalaryDate},
                overtime_days=#{et.overtimeDays},
                absenteeism_days=#{et.absenteeismDays},
                dimission_absenteeism_days=#{et.dimissionAbsenteeismDays},
                entry_absenteeism_days=#{et.entryAbsenteeismDays},
                leaved=#{et.leaved},
                editable=#{et.editable},
                employee_no=#{et.employeeNo},
                employee_name=#{et.employeeName},
                office_id=#{et.officeId},
                position_id=#{et.positionId},
                job_id=#{et.jobId},
                department_id=#{et.departmentId},
                entry_date=#{et.entryDate},
                regular_date=#{et.regularDate},
                leave_date=#{et.leaveDate},
                mobile_phone=#{et.mobilePhone},
                idcard=#{et.idcard},
                position_name=#{et.positionName},
                created_by=#{et.createdBy},
                last_modified_by=#{et.lastModifiedBy},
                created_date=#{et.createdDate},
                last_modified_date=#{et.lastModifiedDate},
                remarks=#{et.remarks},
                version=#{et.version} + 1,   
                enabled=#{et.enabled},
                tenant_code=#{et.tenantCode}
                WHERE id=#{et.id}
        </update>

    以上代码主要是做一个记录、以备后期学习使用

  • 相关阅读:
    北京太速科技股份有限公司产品手册V201903020
    204-基于Xilinx Virtex-6 XC6VLX240T 和TI DSP TMS320C6678的信号处理板
    375-基于TI DSP TMS320C6657、XC7K325T的高速数据处理核心板
    116-基于5VLX110T FPGA FMC接口功能验证6U CPCI平台 光纤PCIe卡
    115-基于TI TMS320DM6467无操作系统Camera Link智能图像分析平台
    95-基于FMC接口的2路CameraLink Base输出子卡模块
    88-基于FMC接口的2路CameraLink Base输入子卡模块
    IT男的别样人生,爱折腾,竟然辞职跑丽江去了
    如何扩展/删除swap分区
    Linux 中交换空间 (swap)应该分多大才好?
  • 原文地址:https://www.cnblogs.com/mzlb520/p/12082234.html
Copyright © 2011-2022 走看看