Python 官方文档:入门教程 => 点击学习
mybatis配置对象包含对象及List 这里隐藏get set方法 public class BatchManagerViewVo implements Serializab
这里隐藏get set方法
public class BatchManagerViewVo implements Serializable{
private static final long serialVersionUID = 1L;
private List<ResourcesItemDto> resourceItem;
private List<PriceInfoDto> priceInfo;
@Id
@Column(name = "ID")
private String id;
public List<ResourcesItemDto> getResourceItem() {
return resourceItem;
}
public void setResourceItem(List<ResourcesItemDto> resourceItem) {
this.resourceItem = resourceItem;
}
public List<PriceInfoDto> getPriceInfo() {
return priceInfo;
}
public void setPriceInfo(List<PriceInfoDto> priceInfo) {
this.priceInfo = priceInfo;
}
@Column(name = "BATCH_NAME")
private String batchName;
@Column(name = "MEMBER_NAME")
private String memberName;
@Column(name = "MEMBER_CODE")
private String memberCode;
@Column(name = "BATCH_STATE")
private String batchState;
@Column(name = "BATCH_DATE")
private Date batchDate;
@Column(name = "END_TIME")
private Date endTime;
@Column(name = "START_TIME")
private Date startTime;
@Column(name = "BOND_PAYMENT_STATUS")
private String bondPaymentStatus;
@Column(name = "SETTLEMENT_MODE")
private String settlementMode;
@Column(name = "INVALID_DATE")
private Date invalidDate;
@Column(name = "AUDIT_OPERATOR")
private String auditOperator;
@Column(name = "STOP_OPERATOR")
private String stopOperator;
@Column(name = "INVALID_OPERATOR")
private String invalidOperator;
@Column(name = "APPLY_OPERATOR")
private String applyOperator;
@Column(name = "ANNOUNCEMENT_DAY")
private Date announcementDay;
@Column(name = "BID_DAY")
private Date bidDay;
@Column(name = "BUYER_DEPOSIT")
private BigDecimal buyerDeposit;
@Column(name = "SELLER_BOND")
private BigDecimal sellerBond;
@Column(name = "FORCED_TERMINATION_REASON")
private String forcedTerminationReason;
@Column(name = "AUDIT_STOP_REASON")
private String auditStopReason;
@Column(name = "AUDIT_STOP_DATE")
private Date auditStopDate;
@Column(name = "APPLY_STOP_REASON")
private String applyStopReason;
@Column(name = "APPLY_STOP_DATE")
private Date applyStopDate;
@Column(name = "REFUSE_AUDIT_REASON")
private String refuseAuditReason;
@Column(name = "AUDIT_TIME")
private Date auditTime;
@Column(name = "IS_DIRECTIONAL_BID")
private String isDirectionalBid;
@Column(name = "DIRECTIONAL_REASON")
private String directionalReason;
@Column(name = "IS_SEND_MESSAGE")
private String isSendMessage;
@Column(name = "IS_SHOW_DEAL_PRICE")
private String isshowDealPrice;
@Column(name = "IS_SHOW_ORDER_PRICE")
private String isShoWorderPrice;
@Column(name = "IS_SHOW_DEAL_MEMBER")
private String isShowDealMember;
@Column(name = "MINIMUM_RESPONSE")
private String minimumResponse;
@Column(name = "ISSHOWDEALRESULT")
private String isshowdealresult;
@Column(name = "BIDDING_TYPE")
private String biddingType;
@Column(name = "OFFER_TYPE")
private String offerType;
@Column(name = "IS_SHOW_STARTING_PIRCE")
private String isShowStartingPirce;
@Column(name = "DOAMIN")
private String doamin;
@Column(name = "EDITMENT")
private String editment;
}
<select id="findSellerBatchInfo" parameterType="com.ouyeel.chem.bdt.search.BatchManagerSerachModel" resultMap="batchInfoMap">
select
batch.ID,
batch.BATCH_NAME,
batch.BATCH_STATE batch_state,
batch.START_TIME batch_start_time,
batch.END_TIME batch_end_time,
batch.IS_DIRECTIONAL_BID batch_is_direc,
batch.BUYER_DEPOSIT batch_buyer_deposit,
batch.BIDDING_TYPE batch_bidding_type,
batch.OFFER_TYPE batch_offer_type,
batch.BATCH_DATE batch_date,
batch.ANNOUNCEMENT_DAY batch_announ,
batch.BID_DAY batch_bid_day,
price.id price_id,
price.STARTING_PIRCE price_starting_price,
price.BIDDING_GRADIENT price_bidding_gradient,
price.TAX_RATE price_tax_rate,
price.TAX_FREE_PRICE price_tax_free_price,
price.RESERVE_PRICE price_reserve_price,
item.PRODUCT_NAME item_product_name,
item.PRODUCT_NO item_product_no,
item.PACKAGES item_packages,
item.ORIGIN_PLACE item_origin_place,
item.WAREHOUSE_NAME item_warehouse,
item.PIECE_UNIT item_piece_unit,
item.TRADING_WEIGHT item_trading_weight
from bdt_batch batch
left join bdt_resources_item item on item.batch_id = batch.id
left join bdt_price_info price on price.batch_id = batch.id and item.id = price.item_id
where batch.member_code = #{memberCode,jdbcType=VARCHAR}<!-- and batch.id = 'P170508005' -->
<if test="id != null and id != '' ">
and batch.id like '%${id}%'
</if>
<if test="startTime != null and startTime != '' ">
and batch.batch_date >= #{startTime,jdbcType=TIMESTAMP}
</if>
<if test="endTime != null and endTime != '' ">
and batch.batch_date <= #{endTime,jdbcType=TIMESTAMP}
</if>
<if test="batchState != null and batchState != '' ">
and batch.batch_state = #{batchState,jdbcType=VARCHAR}
</if>
<if test="sidx != null and sidx != '' ">
order by batch.${sidx} ${sord}
</if>
<if test="sidx == null or sidx ==''">
order by batch.id desc
</if>
</select>
<resultMap type="com.ouyeel.chem.bdt.entity.vo.BatchManagerViewVo" id="batchInfoMap">
<!-- association字面意思关联,这里只专门做一对一关联; property表示是com.mybatis.bean.StudentTemp中的属性名称;
javaType表示该属性是什么类型对象 -->
<!-- property 表示com.mybatis.bean.Class中的属性; column 表示表中的列名 -->
<id property="id" column="id"/>
<result property="batchName" column="batch_name"/>
<result property="startTime" column="batch_start_time"/>
<result property="endTime" column="batch_end_time"/>
<result property="isDirectionalBid" column="batch_is_direc"/>
<result property="batchState" column="batch_state"/>
<result property="buyerDeposit" column="batch_buyer_deposit"/>
<result property="biddingType" column="batch_bidding_type"/>
<result property="offerType" column="batch_offer_type"/>
<result property="batchDate" column="batch_date"/>
<result property="announcementDay" column="batch_announ"/>
<result property="bidDay" column="batch_bid_day"/>
<!-- property表示集合类型属性名称,ofType表示集合中的对象是什么类型 -->
<collection property="priceInfo" ofType="com.ouyeel.chem.bdt.entity.PriceInfoDto">
<id property="id" column="price_id"/>
<result property="startingPirce" column="price_starting_price"/>
<result property="biddingGradient" column="price_bidding_gradient"/>
<result property="taxRate" column="price_tax_rate"/>
<result property="taxFreePrice" column="price_tax_free_price"/>
<result property="reservePrice" column="price_reserve_price"/>
</collection>
<!-- property表示集合类型属性名称,ofType表示集合中的对象是什么类型 -->
<collection property="resourceItem" ofType="com.ouyeel.chem.bdt.entity.ResourcesItemDto">
<result property="productName" column="item_product_name"/>
<result property="productNo" column="item_product_no"/>
<result property="packages" column="item_packages"/>
<result property="originPlace" column="item_origin_place"/>
<result property="warehouseName" column="item_warehouse"/>
<result property="pieceUnit" column="item_piece_unit"/>
<result property="tradingWeight" column="item_trading_weight"/>
</collection>
</resultMap>
mybatis是一个非常好用且灵活的持久层框架,但也正是因为太过灵活,导致有时候参数很难整理。我把我在项目中遇到的一个特殊情况列出来,希望下次再碰到时,也有个印象。
实体类如下:
package com.kxlive.erp.sc.stock.vo;
import java.util.Date;
import java.util.List;
import org.springframework.fORMat.annotation.DateTimeFormat;
import com.kxlive.erp.sc.stock.po.PurchaseDeliver;
public class QueryPurchaseDeliverVo extends PurchaseDeliver{
private Long merchantId;
private Long stockId;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date startTime;//发货开始时间
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date endTime;//发货结束时间
private Integer page;//当前页
private Integer rows;//每页记录数
private String stockName;//仓库名
private String supplierName;//供应商名称
private List<Long> condSupplierIds;//供应商IDs
private List<Integer> condStatuss;//状态s
public Date getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public Date getEndTime() {
return endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
public Integer getPage() {
return page;
}
public void setPage(Integer page) {
this.page = page;
}
public Integer getRows() {
return rows;
}
public void setRows(Integer rows) {
this.rows = rows;
}
public String getStockName() {
return stockName;
}
public void setStockName(String stockName) {
this.stockName = stockName;
}
public String getSupplierName() {
return supplierName;
}
public void setSupplierName(String supplierName) {
this.supplierName = supplierName;
}
public List<Long> getCondSupplierIds() {
return condSupplierIds;
}
public void setCondSupplierIds(List<Long> condSupplierIds) {
this.condSupplierIds = condSupplierIds;
}
public List<Integer> getCondStatuss() {
return condStatuss;
}
public void setCondStatuss(List<Integer> condStatuss) {
this.condStatuss = condStatuss;
}
public Long getMerchantId() {
return merchantId;
}
public void setMerchantId(Long merchantId) {
this.merchantId = merchantId;
}
public Long getStockId() {
return stockId;
}
public void setStockId(Long stockId) {
this.stockId = stockId;
}
}
这里的实体类中,包含了一个List对象,所以在写xml文件的时候多少对我这种菜鸟有点难度。
<select id="selectPurchaseDeliverByPrimaryKeySelective" resultMap="purchaseResultMap">
select
t2. name stock_name,
t3. supplier_name, t1.*
from
T_SC_PURCHASE_DELIVER t1
left join T_SC_STOCK t2 on t1.purchase_stock_id = t2.id
left join T_SC_SUPPLIER t3 on t1.supplier_id = t3.id
<where>
<if test="queryCondition.ifDel != null">
and t1.if_del=#{queryCondition.ifDel,jdbcType=INTEGER}
</if>
<if test="queryCondition.condSupplierIds != null">
and t1.supplier_id in
<foreach collection="queryCondition.condSupplierIds" item="supplierId" index="index" separator="," open="(" close=")">
#{queryCondition.condSupplierIds[${index}],jdbcType=BIGINT}
</foreach>
</if>
<if test="queryCondition.condStatuss != null">
and t1.status in
<span style="color:#ff0000;"><foreach collection="queryCondition.condStatuss" item="status" separator="," index="index" open="(" close=")">
#{queryCondition.condStatuss[${index}],jdbcType=INTEGER}
</foreach></span>
</if>
<if test="queryCondition.merchantId != null">
and t1.merchant_id=#{queryCondition.merchantId,jdbcType=BIGINT}
</if>
<if test="queryCondition.stockId != null">
and t1.purchase_stock_id=#{queryCondition.stockId,jdbcType=BIGINT}
</if>
<if test="queryCondition.startTime != null">
<![CDATA[ and DATE_FORMAT(t1.create_time, '%Y-%m-%d') >= DATE_FORMAT(#{queryCondition.startTime}, '%Y-%m-%d')]]>
</if>
<if test="queryCondition.endTime != null">
<![CDATA[ and DATE_FORMAT(t1.create_time, '%Y-%m-%d') <= DATE_FORMAT(#{queryCondition.endTime}, '%Y-%m-%d')]]>
</if>
<if test="queryCondition.name != null and queryCondition.name != '' ">
and t1.name like CONCAT('%', #{queryCondition.name, jdbcType=VARCHAR}, '%')
</if>
<if test="queryCondition.deliverNo != null">
and t1.deliver_no like CONCAT('%', #{queryCondition.deliverNo, jdbcType=VARCHAR}, '%')
</if>
</where>
order by t1.create_time desc
</select>
标红的地方,即为应用。在foreach循环中,引用index作为list的下标,这样即可将对象中的所有数据取出。
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: mybatis配置对象包含对象以及List的方式
本文链接: https://lsjlt.com/news/128671.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0