MyBatis使用总结

    xiaoxiao2026-02-28  9

    1、MyBatis参数传递 - 需要传递多个参数时,可以用map结构进行传递 - service调用:

    Map<String, Object> conditons = new HashMap<String, Object>(); conditons.put("resId", liveId.toString()); conditons.put("resType",10); - mapper定义: deleteByResourceAndType(Map<String, Object> conditions); - xml: <delete id="deleteByResourceAndType"> DELETE FROM PEIXUN_SPEAKER_RELATED <where> RES_ID=#{resId} AND RES_TYPE=#{resType} </where> </delete>

    2、MyBatis的XML配置文件相关

    xml配置文件中的继承extends参数 继承resultMap:添加参数: <resultMap type="CoursePO" id="courseWithRelationLive" extends="courseResult"> <result property="liveId" column="liveId" /> <result property="liveName" column="liveName" /> </resultMap>

    继承resultMap:添加select,以list形式添加:

    <resultMap type="CoursePO" id="courseWithElements" extends="courseResult"> <collection property="elementList" column="ID" javaType="ArrayList" ofType="ElementPO" select="getElementsByCourseId" /> </resultMap> <select id="getElementsByCourseId" parameterType="long" resultMap="elementwithOrderMap"> SELECT CE.COURSE_ID, CE.ELEMENT_ORDER , E.ID, E.TYPE, E.NAME, E.DESCRIPTION, E.CREATOR_ID, E.CREATOR_NAME, E.COVER_PATH, E.ATTACH_PATH, E.CREATE_TIME, E.UPDATE_TIME, E.TRANS_STATUS, E.VOICE_PATH, E.KEY_WORDS from PEIXUN_COURSE_ELEMENT CE INNER JOIN PEIXUN_ELEMENT E on CE.ElEMENT_ID=E.ID where CE.COURSE_ID=#{id} order by CE.ELEMENT_ORDER ASC </select>
    转载请注明原文地址: https://ju.6miu.com/read-1307481.html
    最新回复(0)