myBatis association和collection用法实例

来源:互联网 发布:什么是单片机 编辑:程序博客网 时间:2024/05/21 21:39
Xml代码:
<resultMap id="BaseResultMap" type="com.yc.pojo.Crouse">    <id column="crouse_id" property="crouseId" jdbcType="BIGINT"/>    <result column="title" property="title" jdbcType="VARCHAR"/>    <result column="crouse_code" property="crouseCode" jdbcType="VARCHAR"/>    <result column="user_id" property="userId" jdbcType="BIGINT"/>    <result column="max_persons" property="maxPersons" jdbcType="INTEGER"/>    <result column="price" property="price" jdbcType="DECIMAL"/>    <result column="crouse_all_times" property="crouseAllTimes" jdbcType="INTEGER"/>    <result column="create_time" property="createTime" jdbcType="VARCHAR"/>    <result column="state" property="state" jdbcType="INTEGER"/><association property="students" javaType="com.yc.pojo.CrouseStudent"> <!--association用于数组 -->    <result column="s_id" property="id"            jdbcType="BIGINT"/>    <result column="s_user_id" property="userId"            jdbcType="BIGINT"/>    <result column="s_notes" property="notes"            jdbcType="VARCHAR"/>    <result column="s_state" property="state"            jdbcType="INTEGER"/>    <result column="s_user_status" property="userStatus"            jdbcType="INTEGER"/></association><collection column="user_id" property="user" ofType="com.yc.pojo.User"> <!--collection用于对象  -->    <result column="u_email" property="email"            jdbcType="VARCHAR"/>    <result column="u_name" property="name"            jdbcType="VARCHAR"/>    <result column="u_head_img" property="headImg"            jdbcType="VARCHAR"/>    <result column="u_tel" property="tel"            jdbcType="VARCHAR"/>    <result column="u_wx_number" property="wxNumber"            jdbcType="VARCHAR"/>    <result column="u_sex" property="sex"            jdbcType="VARCHAR"/>    <result column="u_create_time" property="createTime"            jdbcType="VARCHAR"/></collection></resultMap>
<select id="selectByQuery" resultMap="BaseResultMap" parameterType="com.yc.query.CrouseQuery">        SELECT        c.*, u.user_id AS u_user_id,        u.email AS u_email,        u.name as u_name,        u.head_img as u_head_img,        u.tel AS u_tel,        u.wx_number AS u_wx_number,        u.sex AS u_sex,        s.id AS s_id,        s.user_id AS s_user_id,        s.notes AS s_notes,        s.state AS s_state,        s.state AS s_state,        s.user_status AS s_user_status        FROM        crouse c        LEFT JOIN user u ON u.user_id = c.user_id        LEFT JOIN crouse_details d ON d.crouse_id = c.crouse_id        LEFT JOIN crouse_code cc ON c.crouse_id = cc.code_id        LEFT JOIN crouse_img i ON cc. CODE = c.crouse_code        LEFT JOIN rating r on r.crouse_id=c.crouse_id        LEFT JOIN crouse_student s on s.crouse_id=c.crouse_id        <where>            c.crouse_id is not null            <if test="crouseCode != null">                and c.crouseCode LIKE CONCAT('%', CONCAT(#{crouseCode}, '%'))            </if>            <if test="minPrice != null">                and c.price >= #{minPrice}            </if>            <if test="maxPrice != null">                and c.price < #{minPrice}            </if>            <if test="maxPersons != null">                and c.max_persons <= #{maxPersons}            </if>            <if test="minTimes != null">                and c.price >= #{minPrice}            </if>            <if test="maxTimes != null">                and c.price < #{maxTimes}            </if>            <if test="crouceState == null">                and d.state =1            </if>            <if test="address == null">                and d.address is not null            </if>            <if test="startTime == null">                and d.address is not null            </if>        </where> </select>
 
阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 纯种土狗 怎样训练土狗 土狗怎么训练 怎么训练土狗 黑色土狗 土狗养殖技术 小土狗多少钱 土狗打架 土狗多少钱一斤 土狗出售 土狗和宠物狗的区别 养殖土狗 土狗养殖利润 家养土狗 四眼土狗 小土狗怎么养 土狗品种 土狗批发 土狗儿 土狗好训练吗 养土狗 长不大的土狗 昆虫土狗 土狗饲料 长毛土狗 如何养土狗 土狗名字 土狗取名 土狗的特征 土狗装修 养土狗技术 土狗小时候 柴犬是土狗吗 被土狗咬了怎么办 土狗的名字 土狗要打疫苗吗 潮汕土狗 养土狗注意事项 比特土狗 土狗斗狗 铁包金土狗