美文网首页
2018-09-13

2018-09-13

作者: 小小鸟12 | 来源:发表于2018-09-13 11:18 被阅读0次

    List 的map配置

    类
    public class TrainingTask extends AbsBusinessObject {
        private Topic topic=null;//实训主题
        private Date startDate=null;//实训开始时间
        private Date endDate=null;//实训结束时间
        private int practiceCount=0;//实训实践课时数
        private int theoryCount=0;//实训理论课时数
        private List<Teacher> teachers=null;//实训导师
        private List<StudentClass> classes=null;//实训班级
        private List<Student> students=null;//实训学生
    
    
    xml配置
    <?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="dao.training.inter.ITrainingTask">
        <resultMap id="BaseResultMap" type="entity.training.TrainingTask">
            <id column="id" property="id"/>
            <result column="id" property="oldId"/>
            <result column="name" property="name"/>
            <result column="createDate" property="createDate"/>
            <result column="status" property="status"/>
            <result column="description" property="description"/>
    
            <result column="startDate" property="startDate"/>
            <result column="endDate" property="endDate"/>
            <result column="practiceCount" property="practiceCount"/>
            <result column="theoryCount" property="theoryCount"/>
    
            <association property="user" javaType="kesun.entity.system.User">
                <id column="user" property="id"></id>
            </association>
    
            <association property="topic" javaType="entity.training.Topic">
                <id column="topic" property="id"></id>
                <result property="name" column="topicName"/>
            </association>
            <association property="actor" javaType="kesun.entity.system.Actor">
                <id column="actor" property="id"></id>
            </association>
    
            <association property="org" javaType="kesun.entity.system.Organization">
                <id column="org" property="id"></id>
            </association>
    
        </resultMap>
        <resultMap id="ResultMap" extends="BaseResultMap" type="entity.training.TrainingTask">
    
            <collection property="teachers" javaType="java.util.List" ofType="entity.educationbaseinfo.Teacher"
                        select="selectTeacher"
                        column="id">
                <result property="id" column="id"/>
                <result property="number" column="number"/>
                <result property="name" column="name"/>
            </collection>
    
            <collection property="students" javaType="java.util.List" ofType="entity.educationbaseinfo.Student"
                        select="selectStudents"
                        column="id">
                <result property="id" column="id"/>
                <result property="number" column="number"/>
                <result property="name" column="name"/>
            </collection>
    
            <collection property="classes" javaType="java.util.List" ofType="entity.educationbaseinfo.StudentClass"
                        select="selectStudentClass"
                        column="id">
                <result property="id" column="id"/>
                <result property="name" column="name"/>
            </collection>
        </resultMap>
    
        <sql id="Base_Column_List">
            id,name,createDate,status,description,startDate,endDate,practiceCount,theoryCount,user,org,actor,topic,topicName
        </sql>
    
        <sql id="colums">
        <trim suffix="" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="name != null">
                name,
            </if>
            <if test="createDate != null">
                createDate,
            </if>
            <if test="description != null">
                description,
            </if>
            <if test="startDate != null">
                startDate,
            </if>
            <if test="endDate != null">
                endDate,
            </if>
            <if test="practiceCount != null">
                practiceCount,
            </if>
            <if test="theoryCount != null">
                theoryCount,
            </if>
            <if test="status != null">
                status,
            </if>
            <if test="topic != null">
                topic,
            </if>
            <if test="user != null">
                user,
            </if>
    
            <if test="actor != null">
                actor,
            </if>
    
            <if test="org != null">
                org,
            </if>
        </trim>
    </sql>
    
        <sql id="columsValue">
            <trim suffix="" suffixOverrides=",">
                <if test="id != null">
                    #{id},
                </if>
                <if test="name != null">
                    #{name},
                </if>
                <if test="createDate != null">
                    #{createDate},
                </if>
                <if test="description != null">
                    #{description},
                </if>
                <if test="startDate != null">
                    #{startDate},
                </if>
                <if test="endDate != null">
                    #{endDate},
                </if>
                <if test="practiceCount != null">
                    #{practiceCount},
                </if>
                <if test="theoryCount != null">
                    #{theoryCount},
                </if>
                <if test="status != null">
                    #{status},
                </if>
                <if test="topic != null">
                    #{topic.id},
                </if>
                <if test="user != null">
                    #{user.id},
                </if>
    
                <if test="actor != null">
                    #{actor.id},
                </if>
                <if test="org != null">
                    #{org.id},
                </if>
            </trim>
        </sql>
        <sql id="columsItemsValue">
            <trim suffix="" suffixOverrides=",">
                <if test="item.id != null">
                    #{item.id},
                </if>
                <if test="item.name != null">
                    #{item.name},
                </if>
                <if test="item.createDate != null">
                    #{item.createDate},
                </if>
                <if test="item.description != null">
                    #{item.description},
                </if>
                <if test="item.startDate != null">
                    #{item.startDate},
                </if>
                <if test="item.endDate != null">
                    #{item.endDate},
                </if>
                <if test="item.practiceCount != null">
                    #{item.practiceCount},
                </if>
                <if test="item.theoryCount != null">
                    #{item.theoryCount},
                </if>
                <if test="item.status != null">
                    #{item.status},
                </if>
                <if test="item.topic != null">
                    #{item.topic.id},
                </if>
                <if test="item.user != null">
                    #{item.user.id},
                </if>
                <if test="item.actor != null">
                    #{item.actor.id},
                </if>
                <if test="item.org != null">
                    #{item.org.id},
                </if>
            </trim>
        </sql>
        <sql id="condition">
            <where>
                <trim suffixOverrides="and">
                    <if test="name!=null">
                        name like '%${name}%' and
                    </if>
                    <if test="org!=null">
                        org='${org}' and
                    </if>
                </trim>
            </where>
        </sql>
    
    
    
        <resultMap id="teacher" type="entity.educationbaseinfo.Teacher">
            <id column="teacher" property="id"/>
            <result column="number" property="number"/>
            <result column="teaName" property="name"/>
        </resultMap>
        <resultMap id="classes" type="entity.educationbaseinfo.StudentClass">
            <id column="class" property="id"/>
            <result column="className" property="name"/>
        </resultMap>
        <resultMap id="students" type="entity.educationbaseinfo.Student">
            <id column="id" property="id"/>
            <result column="name" property="name"/>
            <result column="number" property="number"/>
        </resultMap>
        <!--查询相关的老师信息-->
        <select id="selectTeacher" parameterType="entity.training.TrainingTask" resultMap="teacher">
            select teacher,number,teaName from trainms_vw_trainingtask_teachers where parent=#{id}
        </select>
        <!--查询相关的学生信息-->
        <select id="selectStudents" parameterType="entity.training.TrainingTask"  resultMap="students">
            select id , name,number,sex from trainms_vw_trainingtask_students where parent=#{id}
        </select>
    
        <!--查询相关的班级信息-->
        <select id="selectStudentClass" parameterType="entity.training.TrainingTask"  resultMap="classes">
            select class,className from trainms_vw_trainingtask_classes where parent=#{id}
        </select>
    
        <!--单个对象新增-->
        <insert id="save" parameterType="entity.training.TrainingTask">
            insert into trainms_trainingtask (
            <include refid="colums"/>
            ) values (
            <include refid="columsValue"/>);
            <if test="teachers!=null">
                <foreach collection="teachers" item="item" index="index">
                    insert into trainms_trainingtask_teachers (
                    id,teacher,parent
                    ) values
                    (
                   '${item.id}','${item.id}','${id}'
                    );
                </foreach>
            </if>
            <if test="students!=null">
                <foreach collection="students" item="item" index="index">
                    insert into trainms_trainingtask_students (
                    id,student,parent
                    ) values
                    (
                    '${item.id}','${item.id}','${id}'
                    );
                </foreach>
            </if>
            <if test="classes!=null">
                <foreach collection="classes" item="item" index="index">
                    insert into trainms_trainingtask_classes (
                    id,class,parent
                    ) values
                    (
                    '${item.id}','${item.id}','${id}'
                    );
                </foreach>
            </if>
        </insert>
        <!--批量新增-->
        <insert id="batchSave" parameterType="java.util.List">
            <foreach collection="list" item="item" index="index">
                insert into trainms_trainingtask (
                <include refid="colums"></include>
                ) values
                (
                 <include refid="columsItemsValue"></include>
                );
            </foreach>
        </insert>
        <!--单个对象更新-->
        <update id="update" parameterType="entity.training.TrainingTask">
            update trainms_trainingtask set
            <trim suffix="" suffixOverrides=",">
                <if test="name != null">
                    name=#{name},
                </if>
                <if test="createDate != null">
                    createDate=#{createDate},
                </if>
                <if test="description != null">
                    description=#{description},
                </if>
           
                <if test="startDate!=null">
                    startDate=#{startDate},
                </if>
                <if test="endDate!=null">
                    endDate=#{endDate},
                </if>
                <if test="practiceCount!=null">
                    practiceCount=#{practiceCount},
                </if>
                <if test="theoryCount!=null">
                    theoryCount=#{theoryCount},
                </if>
                <if test="status != null">
                    status=#{status},
                </if>
                <if test="user != null">
                    user=#{user.id},
                </if>
                <if test="actor != null">
                    actor=#{actor.id},
                </if>
                <if test="org != null">
                    org=#{org.id},
                </if>
            </trim>
            where id=#{oldId,jdbcType=VARCHAR}
        </update>
        <!--对象批量更新-->
        <update id="batchUpdate" parameterType="java.util.List">
            <foreach collection="list" item="item" index="index" open="" close="" separator=";">
                update trainms_trainingtask set
                <trim suffix="" suffixOverrides=",">
                    <if test="item.name != null">
                        name=#{item.name},
                    </if>
                    <if test="item.createDate != null">
                        createDate=#{item.createDate},
                    </if>
                    <if test="item.description != null">
                        description=#{item.description},
                    </if>
                  
                    <if test="item.startDate!=null">
                        startDate=#{item.startDate},
                    </if>
                    <if test="item.endDate!=null">
                        endDate=#{item.endDate},
                    </if>
                    <if test="item.practiceCount!=null">
                        practiceCount=#{item.practiceCount},
                    </if>
                    <if test="item.theoryCount!=null">
                        theoryCount=#{item.theoryCount},
                    </if>
                    <if test="item.status != null">
                        status=#{item.status},
                    </if>
                    <if test="item.user != null">
                        user=#{item.user.id},
                    </if>
                    <if test="item.actor != null">
                        actor=#{item.actor.id},
                    </if>
                    <if test="item.org != null">
                        org=#{item.org.id},
                    </if>
                </trim>
                where id=#{item.oldId,jdbcType=VARCHAR}
            </foreach>
        </update>
        <!--状态更新-->
        <update id="changeStatus" parameterType="entity.training.TrainingTask">
            update trainms_trainingtask set status=#{status} where id=#{id}
        </update>
        <!--单个对象删除-->
        <delete id="delete" parameterType="java.lang.String">
            delete from trainms_trainingtask where id = #{id,jdbcType=VARCHAR}
        </delete>
        <!--批量删除-->
        <delete id="batchDelete" parameterType="java.util.List">
            delete from trainms_trainingtask
            <where>
                id in
                <foreach collection="list" item="item" separator="," open="(" close=")">#{item,jdbcType=VARCHAR}</foreach>
            </where>
        </delete>
    
        <!--单个对象查找-->
        <select id="getMe" parameterType="entity.training.Topic" resultMap="ResultMap">
            select * from trainms_vw_trainingtask where id=#{id}
        </select>
        <!--查找,以Map返回-->
        <select id="findForMap" parameterType="java.util.Map" resultType="java.util.Map">
            select
            <include refid="Base_Column_List"/>
            from trainms_vw_trainingtask
            <include refid="condition"></include>
            order by name ASC
        </select>
    
        <!--快速查找,以Map返回-->
        <select id="fastFind" parameterType="java.util.Map" resultType="java.util.Map">
            select id,name
            from trainms_vw_trainingtask
            <include refid="condition"></include>
            order by name ASC
        </select>
        <!--查询,以对象集合返回-->
        <select id="find" parameterType="java.util.Map" resultMap="BaseResultMap">
            select
            <include refid="Base_Column_List"/>
            from trainms_vw_trainingtask
             <include refid="condition"></include>
            order by name ASC
        </select>
        <!--返回查找条数-->
        <select id="getRowsCount" parameterType="java.util.Map" resultType="java.lang.Integer">
            select count(1) as total from trainms_vw_trainingtask
             <include refid="condition"></include>
        </select>
        <!--分页查找-->
        <select id="findByPage" parameterType="java.util.Map" resultType="java.util.Map">
            select
            <include refid="Base_Column_List"/>
            from trainms_vw_trainingtask
            <where>
                <if test="parent !=null">
                    where name=#{parent}
                </if>
            </where>
            order by name ASC
            <if test="start >=0 and limit>=0">
                limit #{start},#{limit}
            </if>
        </select>
        <!--判断数据是否在使用中,指令根据实际情况编写-->
        <select id="objectInUse" parameterType="java.lang.String" resultType="java.lang.Boolean">
            <![CDATA[ select case when count(id)>0 then 1 else 0  end as count from trainms_trainingtask where name=#{id}
             ]]>
        </select>
    
    </mapper>
    
    

    相关文章

      网友评论

          本文标题:2018-09-13

          本文链接:https://www.haomeiwen.com/subject/hzqwgftx.html