mybatis一对多collection,连表查询参数横跨两张表,子查询参数传递父查询没有的字段,模糊查询

父查询中添加临时列,以便映射到子查询中:

case when ('${sellingDate}' != '') then '${sellingDate}' else '' end as sellingDate添加临时列
<?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="cn.edu.bcu.longtermroom.hotel.pc.mybatis.mapper.RoomSellingExtendMapper">
    <select id="selectRoomSellingAndDates" resultMap="BaseMap">
        select id, room_id, gmt_creat,
               gmt_modified, peoples, meal,
               bed_type, room_type, offline,
               deposit,
        case when ('${sellingDate}' != '') then '${sellingDate}' else '' end as sellingDate
        from room_selling
        where room_id = #{roomId}
    </select>
    <resultMap id="BaseMap" type="cn.edu.bcu.longtermroom.hotel.pc.entity.RoomSellingExtend">
        <id property="id" column="id"/>
        <result property="roomId" column="room_id" />
        <result property="gmtCreat" column="gmt_creat" />
        <result property="gmtModified" column="gmt_modified" />
        <result property="peoples" column="peoples" />
        <result property="meal" column="meal" />
        <result property="bedType" column="bed_type" />
        <result property="roomType" column="room_type" />
        <result property="offline" column="offline" />
        <result property="deposit" column="deposit" />
        <collection property="roomSellingDateList"
                    column="{id=id,sellingDate=sellingDate}"
                    javaType="ArrayList"
                    ofType="cn.edu.bcu.longtermroom.hotel.pc.entity.RoomSellingDate"
                    select="cn.edu.bcu.longtermroom.hotel.pc.mybatis.mapper.RoomSellingExtendMapper.selectRoomSellingDate">
        </collection>
    </resultMap>
    <select id="selectRoomSellingDate" resultMap="BaseResult2" parameterType="java.util.Map">
        select *
        from room_selling_date
        where  room_selling_id = #{id} and selling_date like '%${sellingDate}%'
    </select>
    <resultMap id="BaseResult2" type="cn.edu.bcu.longtermroom.hotel.pc.entity.RoomSellingDate">
        <id property="id" column="id"/>
        <result property="roomSellingId" column="room_selling_id" />
        <result property="sellingDate" column="selling_date" />
        <result property="sellingStage" column="selling_stage" />
        <result property="price" column="price" />
        <result property="num" column="num" />
        <result property="soldNum" column="sold_num" />
        <result property="autoOff" column="auto_off" />
        <result property="lastOrder" column="last_order" />
    </resultMap>

</mapper>

dao类型

 

发布了30 篇原创文章 · 获赞 18 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_40898368/article/details/91983361
今日推荐