ChildMapper.xml 2.73 KB
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="weaver.portal.mapper.commonAbstract.ChildMapper">
    <!--void updateById(Child child);-->
    <update id="updateById">
        update ${secondaryTableName}
        <set>
            <if test="setting != null and setting != ''">
                setting = #{setting},
            </if>
            <if test="orderIndex != null and orderIndex!=0">
                order_index = #{orderIndex}
            </if>
        </set>
        where id =#{id}
    </update>
    <!--void deleteByIds(@Param("ids") List<Integer> ids,@Param("child")Child child);-->
    <delete id="deleteByIds">
        delete from ${child.secondaryTableName} where id in
        <foreach collection="ids" item="item" index="index" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </delete>
    <!--void save(Child child);-->
    <insert id="save" databaseId="mysql">
        insert into ${secondaryTableName}(setting,parent_id,order_index) select #{setting},#{parentId},coalesce(max(id),0)+1 from ${secondaryTableName}
    </insert>
    <insert id="save" databaseId="sqlserver">
        insert into ${secondaryTableName}(setting,parent_id,order_index) values(#{setting},#{parentId},(select coalesce(max(id),0)+1 from ${secondaryTableName}))
    </insert>
    <insert id="save">
        <selectKey order="BEFORE" keyProperty="id" resultType="_int">
            select ${secondaryTableSequenceName}.nextval from dual
        </selectKey>
        insert into ${secondaryTableName}(id,setting,parent_id,order_index) values(#{id},#{setting},#{parentId},(select coalesce(max(id),0)+1 from ${secondaryTableName}))
    </insert>

    <!-- List<Child> findByParentId(String parentId);-->
    <select id="findByParentId" resultMap="resultMap1">
        select * from ${secondaryTableName} where parent_id = #{parentId} order by order_index asc
    </select>
    <resultMap id="resultMap1" type="weaver.portal.entity.commonAbstract.Child">
        <id column="id" property="id"></id>
        <result column="setting" property="setting"></result>
        <result column="parent_id" property="parentId"></result>
        <result column="order_index" property="orderIndex"></result>
    </resultMap>
    <!--Child findById(Child child);-->
    <select id="findById" resultMap="resultMap2">
        select * from ${secondaryTableName} where id = #{id}
    </select>
    <resultMap id="resultMap2" type="weaver.portal.entity.commonAbstract.Child">
        <id column="id" property="id"></id>
        <result column="setting" property="setting"></result>
        <result column="parent_id" property="parentId"></result>
    </resultMap>


</mapper>