mybatis 复杂对象

来源:互联网 发布:计算机英语翻译软件 编辑:程序博客网 时间:2024/06/18 02:13
<?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="com.chudong.xy.dao.item.IItemDao">      <resultMap type="Item" id="itemResultMap" >          <id property="id" column="id" />          <result property="numIid" column="num_iid" />          <result property="title" column="title" />          <result property="subTitle" column="sub_title" />          <result property="cat" column="cat" />          <result property="picUrl" column="pic_url" />          <result property="picThumUrl" column="pic_thum_url" />          <result property="outerId" column="outer_id" />          <result property="props" column="props" />              <result property="marketPrice" column="market_price" />             <result property="price" column="price" />              <result property="num" column="num" />              <result property="listTime" column="list_time" />           <result property="delistTime" column="delist_time" />           <result property="sales" column="sales" />              <result property="created" column="created" />              <result property="modified" column="modified" />            <result property="enableStatus" column="enable_status" />       </resultMap>      <!-- 与活动和搭配套餐进行关联 -->      <resultMap type="Item" id="itemDetailResultMap" extends="itemResultMap">          <association property="active" column="id" javaType="com.chudong.xy.domain.active.Active" select="selectActive"/>          <collection property="withPackages" column="id" javaType="java.util.ArrayList" ofType="com.chudong.xy.domain.item.Item" select="selectWithPackages"/>        </resultMap>      <resultMap type="Active" id="activeResultMap">          <id property="id" column="id" />          <result property="title" column="title" />          <result property="picUrl" column="pic_url" />      </resultMap>      <!-- 查询单个商品,并装载活动和搭配套餐 -->      <select id="queryDetailById" parameterType="long" resultMap="itemDetailResultMap">          SELECT * from item where id = #{id} and enable_status = 1      </select>      <!-- 根据商品id得到一个活动 -->      <select id="selectActive" parameterType="long" resultMap="activeResultMap">            select id,title,pic_url from active where id = (select active_id from active_item where item_id = #{id} and enable_status=1 limit 0,1)       </select>      <!-- 根据商品id得到搭配套餐中的商品 -->      <select id="selectWithPackages" parameterType="long" resultMap="itemResultMap">          select * from item where id in(select mapping_id from item_relation where item_id = #{id} and type=1 and enable_status=1)      </select>  </mapper>
public class Item implements Serializable {      /**      *       */      private static final long serialVersionUID = 3969923837162162882L;      /**      *       */      private Long id;      /**      * 商品编码      */      private Long numIid;      /**      * 商品标题      */      private String title;      /**      * 副标题      */      private String subTitle;      /**      * 商品类目,      */      private Integer cat;      /**      * 商品主图地址      */      private String picUrl;      /**      * 商品缩略图      */      private String picThumUrl;      /**      * 商家编码,      */      private String outerId;      /**      * 商品属性      */      private String props;      /**      * 销售价格      */      private Double price;      /**      * 商品的市场价格      */      private Double marketPrice;      /**      * 商品数量      */      private Integer num;      /**      * 商品上架时间      */      private Date listTime;      /**      * 商品下架时间      */      private Date delistTime;      /**      * 商品销量      */      private Integer sales;        private Date created;      private Date modified;      /**      * 数据可用状态,0表示不可用,1表示可用      */      private Integer enableStatus;      /**      * 商品的url,不存储数据库      */      private String itemTaobaoUrl;      /**      * 商品所关联的活动      */      private Active active;      /**      * 该商品的搭配套餐      */      private List<Item> withPackages;      //省略了set get方法  }  

原文:http://blog.csdn.net/xwnxwn/article/details/53201113