我是靠谱客的博主 现实抽屉,最近开发中收集的这篇文章主要介绍使用mybatis不需要拼凑各种resultMap,通过extends和resultMap直接对应自定义实体类,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
商品信息表对应的实体类PmsProduct
/**
* 商品信息表
*/
public class PmsProduct implements Serializable {
private Long id;
private Long brandId;
private Long productCategoryId;
private Long feightTemplateId;
private Long productAttributeCategoryId;
private String name;
private String pic;
@ApiModelProperty(value = "货号")
private String productSn;
@ApiModelProperty(value = "删除状态:0->未删除;1->已删除")
private Integer deleteStatus;
@ApiModelProperty(value = "上架状态:0->下架;1->上架")
private Integer publishStatus;
@ApiModelProperty(value = "新品状态:0->不是新品;1->新品")
private Integer newStatus;
@ApiModelProperty(value = "推荐状态;0->不推荐;1->推荐")
private Integer recommandStatus;
@ApiModelProperty(value = "审核状态:0->未审核;1->审核通过")
private Integer verifyStatus;
@ApiModelProperty(value = "排序")
private Integer sort;
@ApiModelProperty(value = "销量")
private Integer sale;
private BigDecimal price;
@ApiModelProperty(value = "促销价格")
private BigDecimal promotionPrice;
@ApiModelProperty(value = "赠送的成长值")
private Integer giftGrowth;
@ApiModelProperty(value = "赠送的积分")
private Integer giftPoint;
@ApiModelProperty(value = "限制使用的积分数")
private Integer usePointLimit;
@ApiModelProperty(value = "副标题")
private String subTitle;
@ApiModelProperty(value = "市场价")
private BigDecimal originalPrice;
@ApiModelProperty(value = "库存")
private Integer stock;
@ApiModelProperty(value = "库存预警值")
private Integer lowStock;
@ApiModelProperty(value = "单位")
private String unit;
@ApiModelProperty(value = "商品重量,默认为克")
private BigDecimal weight;
@ApiModelProperty(value = "是否为预告商品:0->不是;1->是")
private Integer previewStatus;
@ApiModelProperty(value = "以逗号分割的产品服务:1->无忧退货;2->快速退款;3->免费包邮")
private String serviceIds;
private String keywords;
private String note;
@ApiModelProperty(value = "画册图片,连产品图片限制为5张,以逗号分割")
private String albumPics;
private String detailTitle;
@ApiModelProperty(value = "促销开始时间")
private Date promotionStartTime;
@ApiModelProperty(value = "促销结束时间")
private Date promotionEndTime;
@ApiModelProperty(value = "活动限购数量")
private Integer promotionPerLimit;
@ApiModelProperty(value = "促销类型:0->没有促销使用原价;1->使用促销价;2->使用会员价;3->使用阶梯价格;4->使用满减价格;5->限时购")
private Integer promotionType;
@ApiModelProperty(value = "品牌名称")
private String brandName;
@ApiModelProperty(value = "商品分类名称")
private String productCategoryName;
@ApiModelProperty(value = "商品描述")
private String description;
private String detailDesc;
@ApiModelProperty(value = "产品详情网页内容")
private String detailHtml;
@ApiModelProperty(value = "移动端网页详情")
private String detailMobileHtml;
private static final long serialVersionUID = 1L;
get方法....
set方法....
商品信息表对应的BaseResultMap
<resultMap id="BaseResultMap" type="com.macro.mall.model.PmsProduct">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="brand_id" jdbcType="BIGINT" property="brandId" />
<result column="product_category_id" jdbcType="BIGINT" property="productCategoryId" />
<result column="feight_template_id" jdbcType="BIGINT" property="feightTemplateId" />
<result column="product_attribute_category_id" jdbcType="BIGINT" property="productAttributeCategoryId" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="pic" jdbcType="VARCHAR" property="pic" />
<result column="product_sn" jdbcType="VARCHAR" property="productSn" />
<result column="delete_status" jdbcType="INTEGER" property="deleteStatus" />
<result column="publish_status" jdbcType="INTEGER" property="publishStatus" />
<result column="new_status" jdbcType="INTEGER" property="newStatus" />
<result column="recommand_status" jdbcType="INTEGER" property="recommandStatus" />
<result column="verify_status" jdbcType="INTEGER" property="verifyStatus" />
<result column="sort" jdbcType="INTEGER" property="sort" />
<result column="sale" jdbcType="INTEGER" property="sale" />
<result column="price" jdbcType="DECIMAL" property="price" />
<result column="promotion_price" jdbcType="DECIMAL" property="promotionPrice" />
<result column="gift_growth" jdbcType="INTEGER" property="giftGrowth" />
<result column="gift_point" jdbcType="INTEGER" property="giftPoint" />
<result column="use_point_limit" jdbcType="INTEGER" property="usePointLimit" />
<result column="sub_title" jdbcType="VARCHAR" property="subTitle" />
<result column="original_price" jdbcType="DECIMAL" property="originalPrice" />
<result column="stock" jdbcType="INTEGER" property="stock" />
<result column="low_stock" jdbcType="INTEGER" property="lowStock" />
<result column="unit" jdbcType="VARCHAR" property="unit" />
<result column="weight" jdbcType="DECIMAL" property="weight" />
<result column="preview_status" jdbcType="INTEGER" property="previewStatus" />
<result column="service_ids" jdbcType="VARCHAR" property="serviceIds" />
<result column="keywords" jdbcType="VARCHAR" property="keywords" />
<result column="note" jdbcType="VARCHAR" property="note" />
<result column="album_pics" jdbcType="VARCHAR" property="albumPics" />
<result column="detail_title" jdbcType="VARCHAR" property="detailTitle" />
<result column="promotion_start_time" jdbcType="TIMESTAMP" property="promotionStartTime" />
<result column="promotion_end_time" jdbcType="TIMESTAMP" property="promotionEndTime" />
<result column="promotion_per_limit" jdbcType="INTEGER" property="promotionPerLimit" />
<result column="promotion_type" jdbcType="INTEGER" property="promotionType" />
<result column="brand_name" jdbcType="VARCHAR" property="brandName" />
<result column="product_category_name" jdbcType="VARCHAR" property="productCategoryName" />
</resultMap>
sku库存表 PmsSkuStock
/**
* sku的库存
*/
public class PmsSkuStock implements Serializable {
private Long id;
private Long productId;
@ApiModelProperty(value = "sku编码")
private String skuCode;
private BigDecimal price;
@ApiModelProperty(value = "库存")
private Integer stock;
@ApiModelProperty(value = "预警库存")
private Integer lowStock;
@ApiModelProperty(value = "展示图片")
private String pic;
@ApiModelProperty(value = "销量")
private Integer sale;
@ApiModelProperty(value = "单品促销价格")
private BigDecimal promotionPrice;
@ApiModelProperty(value = "锁定库存")
private Integer lockStock;
@ApiModelProperty(value = "商品销售属性,json格式")
private String spData;
private static final long serialVersionUID = 1L;
get方法....
set方法....
sku库存表对应的BaseResultMap
<resultMap id="BaseResultMap" type="com.macro.mall.model.PmsSkuStock">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="product_id" jdbcType="BIGINT" property="productId" />
<result column="sku_code" jdbcType="VARCHAR" property="skuCode" />
<result column="price" jdbcType="DECIMAL" property="price" />
<result column="stock" jdbcType="INTEGER" property="stock" />
<result column="low_stock" jdbcType="INTEGER" property="lowStock" />
<result column="pic" jdbcType="VARCHAR" property="pic" />
<result column="sale" jdbcType="INTEGER" property="sale" />
<result column="promotion_price" jdbcType="DECIMAL" property="promotionPrice" />
<result column="lock_stock" jdbcType="INTEGER" property="lockStock" />
<result column="sp_data" jdbcType="VARCHAR" property="spData" />
</resultMap>
产品阶梯价格表 PmsProductLadder
/**
* 产品阶梯价格表(只针对同商品)
*/
public class PmsProductLadder implements Serializable {
private Long id;
private Long productId;
@ApiModelProperty(value = "满足的商品数量")
private Integer count;
@ApiModelProperty(value = "折扣")
private BigDecimal discount;
@ApiModelProperty(value = "折后价格")
private BigDecimal price;
private static final long serialVersionUID = 1L;
get方法...
set方法....
产品阶梯价格表 对应的BaseResultMap
<resultMap id="BaseResultMap" type="com.macro.mall.model.PmsProductLadder">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="product_id" jdbcType="BIGINT" property="productId" />
<result column="count" jdbcType="INTEGER" property="count" />
<result column="discount" jdbcType="DECIMAL" property="discount" />
<result column="price" jdbcType="DECIMAL" property="price" />
</resultMap>
产品满减表(只针对同商品) PmsProductFullReduction
/**
* 产品满减表(只针对同商品)
*/
public class PmsProductFullReduction implements Serializable {
private Long id;
private Long productId;
private BigDecimal fullPrice;
private BigDecimal reducePrice;
private static final long serialVersionUID = 1L;
产品满减表(只针对同商品) 对应的BaseResultMap
<resultMap id="BaseResultMap" type="com.macro.mall.model.PmsProductFullReduction">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="product_id" jdbcType="BIGINT" property="productId" />
<result column="full_price" jdbcType="DECIMAL" property="fullPrice" />
<result column="reduce_price" jdbcType="DECIMAL" property="reducePrice" />
</resultMap>
现在有个dao要通过产品id 获取促销商品信息列表
public interface PortalProductDao {
/**
* 获取促销商品信息列表
*/
List<PromotionProduct> getPromotionProductList(@Param("ids") List<Long> ids);
}
对应的mapper.xml
<select id="getPromotionProductList" resultMap="promotionProductMap">
SELECT
p.id,
p.`name`,
p.promotion_type,
p.gift_growth,
p.gift_point,
sku.id sku_id,
sku.price sku_price,
sku.sku_code sku_sku_code,
sku.promotion_price sku_promotion_price,
sku.stock sku_stock,
sku.lock_stock sku_lock_stock,
ladder.id ladder_id,
ladder.count ladder_count,
ladder.discount ladder_discount,
full_re.id full_id,
full_re.full_price full_full_price,
full_re.reduce_price full_reduce_price
FROM
pms_product p
LEFT JOIN pms_sku_stock sku ON p.id = sku.product_id
LEFT JOIN pms_product_ladder ladder ON p.id = ladder.product_id
LEFT JOIN pms_product_full_reduction full_re ON p.id = full_re.product_id
WHERE
p.id IN
<foreach collection="ids" open="(" close=")" item="id" separator=",">
#{id}
</foreach>
</select>
PromotionProduct 类对应的resultMap
<resultMap id="promotionProductMap" type="com.macro.mall.portal.domain.PromotionProduct" extends="com.macro.mall.mapper.PmsProductMapper.BaseResultMap">
<id column="id" jdbcType="BIGINT" property="id" />
<collection property="skuStockList" columnPrefix="sku_" resultMap="com.macro.mall.mapper.PmsSkuStockMapper.BaseResultMap">
</collection>
<collection property="productLadderList" columnPrefix="ladder_" resultMap="com.macro.mall.mapper.PmsProductLadderMapper.BaseResultMap">
</collection>
<collection property="productFullReductionList" columnPrefix="full_" resultMap="com.macro.mall.mapper.PmsProductFullReductionMapper.BaseResultMap">
</collection>
</resultMap>
PromotionProduct
/**
*
* 商品的促销信息,包括sku、打折优惠、满减优惠
*/
public class PromotionProduct extends PmsProduct {
//商品库存信息
private List<PmsSkuStock> skuStockList;
//商品打折信息
private List<PmsProductLadder> productLadderList;
//商品满减信息
private List<PmsProductFullReduction> productFullReductionList;
get...
set...
和其他方法
通过这种办法就不需要去拼凑各种resultMap,可以通过extends和<collection resultMap=“ ”></collection>直接对应实体,例如这里的PromotionProduct
最后
以上就是现实抽屉为你收集整理的使用mybatis不需要拼凑各种resultMap,通过extends和resultMap直接对应自定义实体类的全部内容,希望文章能够帮你解决使用mybatis不需要拼凑各种resultMap,通过extends和resultMap直接对应自定义实体类所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复