生活随笔
收集整理的這篇文章主要介紹了
Mybatis对象中含有list对象
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
mybatis是一個非常好用且靈活的持久層框架,但也正是因為太過靈活,導致有時候參數很難整理。我把我在項目中遇到的一個特殊情況列出來,希望下次再碰到時,也有個印象。
實體類如下:
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;?? }???
這里的實體類中,包含了2個List對象,所以在寫xml文件的時候多少對我這種菜鳥有點難度。
<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}?? ????<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表示該屬性是什么類型對象?-->?? ?????????? ????????<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"/>?? ?????????? ????????<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>?? ????????? ????????<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对象中含有list对象的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。