2018-09-13

List 的map配置

類(lèi)
public class TrainingTask extends AbsBusinessObject {
    private Topic topic=null;//實(shí)訓(xùn)主題
    private Date startDate=null;//實(shí)訓(xùn)開(kāi)始時(shí)間
    private Date endDate=null;//實(shí)訓(xùn)結(jié)束時(shí)間
    private int practiceCount=0;//實(shí)訓(xùn)實(shí)踐課時(shí)數(shù)
    private int theoryCount=0;//實(shí)訓(xùn)理論課時(shí)數(shù)
    private List<Teacher> teachers=null;//實(shí)訓(xùn)導(dǎo)師
    private List<StudentClass> classes=null;//實(shí)訓(xùn)班級(jí)
    private List<Student> students=null;//實(shí)訓(xùn)學(xué)生


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>
    <!--查詢(xún)相關(guān)的老師信息-->
    <select id="selectTeacher" parameterType="entity.training.TrainingTask" resultMap="teacher">
        select teacher,number,teaName from trainms_vw_trainingtask_teachers where parent=#{id}
    </select>
    <!--查詢(xún)相關(guān)的學(xué)生信息-->
    <select id="selectStudents" parameterType="entity.training.TrainingTask"  resultMap="students">
        select id , name,number,sex from trainms_vw_trainingtask_students where parent=#{id}
    </select>

    <!--查詢(xún)相關(guān)的班級(jí)信息-->
    <select id="selectStudentClass" parameterType="entity.training.TrainingTask"  resultMap="classes">
        select class,className from trainms_vw_trainingtask_classes where parent=#{id}
    </select>

    <!--單個(gè)對(duì)象新增-->
    <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>
    <!--單個(gè)對(duì)象更新-->
    <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>
    <!--對(duì)象批量更新-->
    <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>
    <!--狀態(tài)更新-->
    <update id="changeStatus" parameterType="entity.training.TrainingTask">
        update trainms_trainingtask set status=#{status} where id=#{id}
    </update>
    <!--單個(gè)對(duì)象刪除-->
    <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>

    <!--單個(gè)對(duì)象查找-->
    <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>
    <!--查詢(xún)戴涝,以對(duì)象集合返回-->
    <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>
    <!--返回查找條數(shù)-->
    <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>
    <!--分頁(yè)查找-->
    <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>
    <!--判斷數(shù)據(jù)是否在使用中,指令根據(jù)實(shí)際情況編寫(xiě)-->
    <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>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,919評(píng)論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件瞧栗,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡海铆,警方通過(guò)查閱死者的電腦和手機(jī)迹恐,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,567評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)卧斟,“玉大人殴边,你說(shuō)我怎么就攤上這事憎茂。” “怎么了锤岸?”我有些...
    開(kāi)封第一講書(shū)人閱讀 163,316評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵竖幔,是天一觀(guān)的道長(zhǎng)。 經(jīng)常有香客問(wèn)我是偷,道長(zhǎng)拳氢,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,294評(píng)論 1 292
  • 正文 為了忘掉前任蛋铆,我火速辦了婚禮馋评,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘刺啦。我一直安慰自己留特,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,318評(píng)論 6 390
  • 文/花漫 我一把揭開(kāi)白布玛瘸。 她就那樣靜靜地躺著蜕青,像睡著了一般。 火紅的嫁衣襯著肌膚如雪糊渊。 梳的紋絲不亂的頭發(fā)上右核,一...
    開(kāi)封第一講書(shū)人閱讀 51,245評(píng)論 1 299
  • 那天,我揣著相機(jī)與錄音再来,去河邊找鬼蒙兰。 笑死磷瘤,一個(gè)胖子當(dāng)著我的面吹牛芒篷,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播采缚,決...
    沈念sama閱讀 40,120評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼针炉,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了扳抽?” 一聲冷哼從身側(cè)響起篡帕,我...
    開(kāi)封第一講書(shū)人閱讀 38,964評(píng)論 0 275
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎贸呢,沒(méi)想到半個(gè)月后镰烧,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,376評(píng)論 1 313
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡楞陷,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,592評(píng)論 2 333
  • 正文 我和宋清朗相戀三年怔鳖,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片固蛾。...
    茶點(diǎn)故事閱讀 39,764評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡结执,死狀恐怖度陆,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情献幔,我是刑警寧澤懂傀,帶...
    沈念sama閱讀 35,460評(píng)論 5 344
  • 正文 年R本政府宣布,位于F島的核電站蜡感,受9級(jí)特大地震影響蹬蚁,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜郑兴,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,070評(píng)論 3 327
  • 文/蒙蒙 一缚忧、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧杈笔,春花似錦闪水、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,697評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至禁筏,卻和暖如春持钉,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背篱昔。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,846評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工每强, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人州刽。 一個(gè)月前我還...
    沈念sama閱讀 47,819評(píng)論 2 370
  • 正文 我出身青樓空执,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親穗椅。 傳聞我的和親對(duì)象是個(gè)殘疾皇子辨绊,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,665評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • https://juejin.im/entry/5b87815651882542f1054e6c?utm_sour...
    Albert陳凱閱讀 239評(píng)論 0 0
  • http://skrshop.tech 《電商設(shè)計(jì)手冊(cè)》 Do design No code | 只設(shè)計(jì)不碼碼 s...
    Albert陳凱閱讀 1,655評(píng)論 0 4
  • SQLiteOpenHelper 管理的是一個(gè)數(shù)據(jù)庫(kù)门坷,而不是一個(gè)表此數(shù)據(jù)庫(kù)可管理多個(gè)表,構(gòu)造函數(shù)的版本號(hào)也是數(shù)據(jù)庫(kù)...
    章魚(yú)閱讀 176評(píng)論 0 0
  • 曾國(guó)藩曾言:“大處著眼袍镀,小處著手默蚌,群聚守口,獨(dú)居守心”“行事不可任心苇羡,說(shuō)話(huà)不可任口”“禁大言以務(wù)實(shí)”绸吸。大的事情看你...
    鄒開(kāi)志閱讀 263評(píng)論 0 0
  • 12月28日是不一樣的一天,孩子們期待的一元生存挑戰(zhàn)賽終于開(kāi)始了。我?guī)У氖堑诙M——挑戰(zhàn)不可能組惯裕,對(duì)于今天我有很多...
    山茶_5c91閱讀 609評(píng)論 0 1