mybatis配置對象包含對象以及List的方式
mybatis配置對象包含對象及List
這里隱藏get set方法
public class BatchManagerViewVo implements Serializable{
/**
* @Description: serialVersionUID : TODO
*/
private static final long serialVersionUID = 1L;
private List<ResourcesItemDto> resourceItem;
private List<PriceInfoDto> priceInfo;
/**
* 主鍵(PM200600001)
*/
@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;
/**
* 發(fā)起競價的會員代碼
*/
@Column(name = "MEMBER_CODE")
private String memberCode;
/**
* 委托狀態(tài):0-已生成,1-已發(fā)布,2.競價中 3-已撤消,4--已作廢,5-已完成
*/
@Column(name = "BATCH_STATE")
private String batchState;
/**
* 委托申請時間
*/
@Column(name = "BATCH_DATE")
private Date batchDate;
/**
* 結(jié)束時間
*/
@Column(name = "END_TIME")
private Date endTime;
/**
* 開始時間
*/
@Column(name = "START_TIME")
private Date startTime;
/**
* 履約保證金是否已經(jīng)支付 1 - 已經(jīng)支付 0 - 未支付(只有此狀態(tài)為1才允許開始拍賣)
*/
@Column(name = "BOND_PAYMENT_STATUS")
private String bondPaymentStatus;
/**
* 結(jié)算方式:1-場外結(jié)算(默認(rèn)) 2- 場內(nèi)結(jié)算
*/
@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;
/**
* 定向競價0否1是1
*/
@Column(name = "IS_DIRECTIONAL_BID")
private String isDirectionalBid;
/**
* 定向的原因,當(dāng)場次定向時必須輸入
*/
@Column(name = "DIRECTIONAL_REASON")
private String directionalReason;
/**
* 是否需要發(fā)送短信0不發(fā)送1發(fā)送
*/
@Column(name = "IS_SEND_MESSAGE")
private String isSendMessage;
/**
* 是否顯示中標(biāo)價格
*/
@Column(name = "IS_SHOW_DEAL_PRICE")
private String isShowDealPrice;
/**
* 是否顯示定價
*/
@Column(name = "IS_SHOW_ORDER_PRICE")
private String isShowOrderPrice;
/**
* 是否顯示中標(biāo)會員
*/
@Column(name = "IS_SHOW_DEAL_MEMBER")
private String isShowDealMember;
/**
* 最少響應(yīng)人數(shù)
*/
@Column(name = "MINIMUM_RESPONSE")
private String minimumResponse;
/**
* 是否顯示成交結(jié)果
*/
@Column(name = "ISSHOWDEALRESULT")
private String isshowdealresult;
/**
* 競價模式:1-公開增價,2自由報價,3-荷式競價
*/
@Column(name = "BIDDING_TYPE")
private String biddingType;
/**
* 報盤方式:1-單價,2-總價
*/
@Column(name = "OFFER_TYPE")
private String offerType;
/**
* 是否顯示起拍價 1顯示(默認(rèn)) 2不顯示
*/
@Column(name = "IS_SHOW_STARTING_PIRCE")
private String isShowStartingPirce;
/**
* 域名
*/
@Column(name = "DOAMIN")
private String doamin;
/**
* 協(xié)議
*/
@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字面意思關(guān)聯(lián),這里只專門做一對一關(guān)聯(lián); 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參數(shù)為對象中包含list情況處理
mybatis是一個非常好用且靈活的持久層框架,但也正是因為太過靈活,導(dǎo)致有時候參數(shù)很難整理。我把我在項目中遇到的一個特殊情況列出來,希望下次再碰到時,也有個印象。
實體類如下:
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;//發(fā)貨開始時間
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date endTime;//發(fā)貨結(jié)束時間
private Integer page;//當(dāng)前頁
private Integer rows;//每頁記錄數(shù)
private String stockName;//倉庫名
private String supplierName;//供應(yīng)商名稱
private List<Long> condSupplierIds;//供應(yīng)商IDs
private List<Integer> condStatuss;//狀態(tài)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>
標(biāo)紅的地方,即為應(yīng)用。在foreach循環(huán)中,引用index作為list的下標(biāo),這樣即可將對象中的所有數(shù)據(jù)取出。
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Java數(shù)據(jù)結(jié)構(gòu)和算法之鏈表詳解
鏈表是一種物理存儲單元上非連續(xù)、非順序的存儲結(jié)構(gòu),java代碼實現(xiàn)單鏈表,插入,刪除和遍歷等功能,這篇文章主要給大家介紹了關(guān)于Java數(shù)據(jù)結(jié)構(gòu)和算法之鏈表的相關(guān)資料,需要的朋友可以參考下2024-01-01
java數(shù)字和中文算數(shù)驗證碼的實現(xiàn)
這篇文章主要介紹了java數(shù)字和中文算數(shù)驗證碼的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07
springboot配置項目啟動后自動打開瀏覽器訪問項目方式
這篇文章主要介紹了springboot配置項目啟動后自動打開瀏覽器訪問項目方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-01-01
Mybatis-Plus中的@TableName 和 table-prefix使用
table-prefix 是一個全局配置,它會自動在所有表名前添加指定的前綴,這個配置對于那些使用一致命名約定的數(shù)據(jù)庫表非常有用,這篇文章主要介紹了Mybatis-Plus中的@TableName 和 table-prefix使用,需要的朋友可以參考下2024-08-08
Spring Boot容器加載時執(zhí)行特定操作(推薦)
這篇文章主要介紹了Spring Boot容器加載時執(zhí)行特定操作及spring內(nèi)置的事件,需要的朋友可以參考下2018-01-01

