关于Class MyBatisPagingItemReader<T> 读取数据只读第一条分页数据就结束了问题

来源:互联网 发布:淘宝网站模板下载 编辑:程序博客网 时间:2024/05/20 07:31
都是单条单表数据进行导入使用的JdbcPagingItemReader<T>设置分页参数,就可以分页读取。现在导入数据需要维护层级关系,使用jdbc完全不可以满足关系
进而选择MyBatisPagingItemReader<T>, 使用mabatis维持层级关系,问题来了:当我设置分页参数为500的时候,返回的结果list是420,然后springBatch就没有继续往下读取了?


解决办法: 使用联合查询的时候,设置了分页参数是500,必须保证返回结果是500.当少于了500 batch会判定为最后一页,标记读取结束,程序读取就结束了


问题2:项目中会出现sql不报错(如果sql报错,会有日志打印,debug模式),但是springBatch查不出结果?最坑爹的日志也没有报错?

解决思路:这个原因很有可能是、resultMap中对应字段和实体中的对应字段不匹配。这个只能逐个检查了。(这个小问题坑了我好几个小时)



这个是修正后的xml  分页查询代码。必须保证left join 左边是500条 (不重复)订单记录
  <select id="selectOrderAndOrderLine" resultMap="CommonResultMap">
   select 
  temp_a.*,
  sol.id as line_id,
  sol.so_id as line_so_id,
  sol.item_meal_name as line_item_meal_name,
  sol.pic_path  as line_pic_path,
  
  sol.seller_nick    as    line_seller_nick  ,
  sol.buyer_nick     as    line_buyer_nick  ,
  sol.refund_status  as    line_refund_status  ,
  sol.outer_iid      as    line_outer_iid  ,
  sol.snapshot_url   as  line_snapshot_url  ,
  sol.snapshot       as  line_snapshot  ,
  sol.timeout_action_time  as  line_timeout_action_time  ,
  sol.buyer_rate  as  line_buyer_rate  ,
  sol.seller_rate  as  line_seller_rate  ,
  sol.seller_type  as  line_seller_type  ,
  sol.cid  as  line_cid  ,
  sol.sub_order_tax_fee  as  line_sub_order_tax_fee  ,
  sol.sub_order_tax_rate  as  line_sub_order_tax_rate  ,
  sol.oid  as  line_oid  ,
  sol.status  as  line_status  ,
  sol.title  as  line_title  ,
  sol.type  as  line_type  ,
  sol.iid  as  line_iid  ,
  sol.price  as  line_price  ,
  sol.num_iid  as  line_num_iid  ,
  sol.item_meal_id  as  line_item_meal_id  ,
  sol.sku_id  as  line_sku_id  ,
  sol.num  as  line_num  ,
  sol.outer_sku_id  as  line_outer_sku_id  ,
  sol.order_from  as  line_order_from  ,
  sol.total_fee  as  line_total_fee  ,
  sol.payment  as  line_payment  ,
  sol.discount_fee  as  line_discount_fee  ,
  sol.adjust_fee  as  line_adjust_fee  ,
  sol.modified  as  line_modified  ,
  sol.sku_properties_name  as  line_sku_properties_name  ,
  sol.refund_id  as  line_refund_id  ,
  sol.is_oversold  as  line_is_oversold  ,
  sol.is_service_order  as  line_is_service_order  ,
  sol.end_time  as  line_end_time  ,
  sol.consign_time  as  line_consign_time  ,
  sol.order_attr  as  line_order_attr  ,
  sol.shipping_type  as  line_shipping_type  ,
  sol.bind_oid  as  line_bind_oid  ,
  sol.logistics_company  as  line_logistics_company  ,
  sol.invoice_no  as  line_invoice_no  ,
  sol.is_daixiao  as  line_is_daixiao  ,
  sol.divide_order_fee  as  line_divide_order_fee  ,
  sol.part_mjz_discount  as  line_part_mjz_discount  ,
  sol.ticket_outer_id  as  line_ticket_outer_id  ,
  sol.ticket_expdate_key  as  line_ticket_expdate_key  ,
  sol.store_code  as  line_store_code  ,
  sol.is_www  as  line_is_www  ,
  sol.tmser_spu_code  as  line_tmser_spu_code  ,
  sol.bind_oids  as  line_bind_oids  ,
  sol.zhengji_status  as  line_zhengji_status  ,
  sol.md_qualification  as  line_md_qualification  ,
  sol.md_fee  as  line_md_fee  ,
  sol.customization  as  line_customization  ,
  sol.inv_type  as  line_inv_type  ,
  sol.is_sh_ship  as  line_is_sh_ship  ,
  sol.shipper  as  line_shipper  ,
  sol.f_type  as  line_f_type  ,
  sol.f_status  as  line_f_status  ,
  sol.f_term  as  line_f_term  ,
  sol.assembly_rela  as  line_assembly_rela  ,
  sol.assembly_price  as  line_assembly_price  ,
  sol.assembly_item  as  line_assembly_item  ,
  sol.last_modified_time  as  line_last_modified_time  ,
  sol.create_time  as  line_create_time 
       from 
(
SELECT so.* FROM t_tm_sales_order so 
where so.last_modified_time >= to_timestamp('2015-05-05','yyyy-mm-dd hh24:mi:ss') 
order by so.id limit #{_pagesize} OFFSET #{_skiprows}  
) temp_a 
inner join t_tm_sales_order_line sol on temp_a.id=sol.so_id 
  </select>
  
  
  resultMap  如下
  
    <resultMap id="BaseResultMap" type="cn.baozun.entity.ods.crm.TmSalesOrder">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="seller_nick" jdbcType="VARCHAR" property="sellerNick" />
    <result column="pic_path" jdbcType="VARCHAR" property="picPath" />
    <result column="payment" jdbcType="NUMERIC" property="payment" />
    <result column="seller_rate" jdbcType="INTEGER" property="sellerRate" />
    <result column="post_fee" jdbcType="NUMERIC" property="postFee" />
    <result column="receiver_name" jdbcType="VARCHAR" property="receiverName" />
    <result column="receiver_state" jdbcType="VARCHAR" property="receiverState" />
    <result column="receiver_address" jdbcType="VARCHAR" property="receiverAddress" />
    <result column="receiver_zip" jdbcType="VARCHAR" property="receiverZip" />
    <result column="receiver_mobile" jdbcType="VARCHAR" property="receiverMobile" />
    <result column="receiver_phone" jdbcType="VARCHAR" property="receiverPhone" />
    <result column="consign_time" jdbcType="TIMESTAMP" property="consignTime" />
    <result column="received_payment" jdbcType="NUMERIC" property="receivedPayment" />
    <result column="est_con_time" jdbcType="TIMESTAMP" property="estConTime" />
    <result column="invoice_kind" jdbcType="INTEGER" property="invoiceKind" />
    <result column="receiver_country" jdbcType="VARCHAR" property="receiverCountry" />
    <result column="receiver_town" jdbcType="VARCHAR" property="receiverTown" />
    <result column="order_tax_fee" jdbcType="NUMERIC" property="orderTaxFee" />
    <result column="paid_coupon_fee" jdbcType="NUMERIC" property="paidCouponFee" />
    <result column="shop_pick" jdbcType="VARCHAR" property="shopPick" />
    <result column="tid" jdbcType="BIGINT" property="tid" />
    <result column="num" jdbcType="NUMERIC" property="num" />
    <result column="num_iid" jdbcType="BIGINT" property="numIid" />
    <result column="status" jdbcType="VARCHAR" property="status" />
    <result column="title" jdbcType="VARCHAR" property="title" />
    <result column="type" jdbcType="VARCHAR" property="type" />
    <result column="price" jdbcType="NUMERIC" property="price" />
    <result column="discount_fee" jdbcType="NUMERIC" property="discountFee" />
    <result column="has_post_fee" jdbcType="INTEGER" property="hasPostFee" />
    <result column="total_fee" jdbcType="NUMERIC" property="totalFee" />
    <result column="created" jdbcType="TIMESTAMP" property="created" />
    <result column="pay_time" jdbcType="TIMESTAMP" property="payTime" />
    <result column="modified" jdbcType="TIMESTAMP" property="modified" />
    <result column="end_time" jdbcType="TIMESTAMP" property="endTime" />
    <result column="buyer_message" jdbcType="VARCHAR" property="buyerMessage" />
    <result column="buyer_memo" jdbcType="VARCHAR" property="buyerMemo" />
    <result column="buyer_flag" jdbcType="BIGINT" property="buyerFlag" />
    <result column="seller_memo" jdbcType="VARCHAR" property="sellerMemo" />
    <result column="seller_flag" jdbcType="BIGINT" property="sellerFlag" />
    <result column="invoice_name" jdbcType="VARCHAR" property="invoiceName" />
    <result column="invoice_type" jdbcType="VARCHAR" property="invoiceType" />
    <result column="buyer_nick" jdbcType="VARCHAR" property="buyerNick" />
    <result column="trade_attr" jdbcType="VARCHAR" property="tradeAttr" />
    <result column="credit_card_fee" jdbcType="NUMERIC" property="creditCardFee" />
    <result column="step_trade_status" jdbcType="VARCHAR" property="stepTradeStatus" />
    <result column="step_paid_fee" jdbcType="NUMERIC" property="stepPaidFee" />
    <result column="mark_desc" jdbcType="VARCHAR" property="markDesc" />
    <result column="shipping_type" jdbcType="VARCHAR" property="shippingType" />
    <result column="buyer_cod_fee" jdbcType="NUMERIC" property="buyerCodFee" />
    <result column="adjust_fee" jdbcType="NUMERIC" property="adjustFee" />
    <result column="trade_from" jdbcType="VARCHAR" property="tradeFrom" />
    <result column="buyer_rate" jdbcType="INTEGER" property="buyerRate" />
    <result column="receiver_city" jdbcType="VARCHAR" property="receiverCity" />
    <result column="receiver_district" jdbcType="VARCHAR" property="receiverDistrict" />
    <result column="o2o" jdbcType="VARCHAR" property="o2o" />
    <result column="o2o_guide_id" jdbcType="VARCHAR" property="o2oGuideId" />
    <result column="o2o_shop_id" jdbcType="VARCHAR" property="o2oShopId" />
    <result column="o2o_guide_name" jdbcType="VARCHAR" property="o2oGuideName" />
    <result column="o2o_shop_name" jdbcType="VARCHAR" property="o2oShopName" />
    <result column="o2o_delivery" jdbcType="VARCHAR" property="o2oDelivery" />
    <result column="coupon_fee" jdbcType="NUMERIC" property="couponFee" />
    <result column="o2o_et_order_id" jdbcType="VARCHAR" property="o2oEtOrderId" />
    <result column="post_gate_declare" jdbcType="INTEGER" property="postGateDeclare" />
    <result column="cross_bonded_declare" jdbcType="INTEGER" property="crossBondedDeclare" />
    <result column="assembly" jdbcType="INTEGER" property="assembly" />
    <result column="last_modified_time" jdbcType="TIMESTAMP" property="lastModifiedTime" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="rawdata_id" jdbcType="INTEGER" property="rawdataId" />
    <result column="platform_id" jdbcType="VARCHAR" property="platformId" />
  </resultMap>
  
  <!-- orderlineMap  主要是order  表中的字段和line表中的字段有相同的,干脆统一去别名 -->
    <resultMap id="OrderlineMap" type="cn.baozun.entity.ods.crm.TmSalesOrderLine">
    <result column="line_id" jdbcType="BIGINT" property="id" />
    <result column="line_so_id" jdbcType="BIGINT" property="soId" />
    <result column="line_item_meal_name" jdbcType="VARCHAR" property="itemMealName" />
    <result column="line_pic_path" jdbcType="VARCHAR" property="picPath" />
    <result column="line_seller_nick" jdbcType="VARCHAR" property="sellerNick" />
    <result column="line_buyer_nick" jdbcType="VARCHAR" property="buyerNick" />
    <result column="line_refund_status" jdbcType="VARCHAR" property="refundStatus" />
    <result column="line_outer_iid" jdbcType="VARCHAR" property="outerIid" />
    <result column="line_snapshot_url" jdbcType="VARCHAR" property="snapshotUrl" />
    <result column="line_snapshot" jdbcType="VARCHAR" property="snapshot" />
    <result column="line_timeout_action_time" jdbcType="TIMESTAMP" property="timeoutActionTime" />
    <result column="line_buyer_rate" jdbcType="INTEGER" property="buyerRate" />
    <result column="line_seller_rate" jdbcType="INTEGER" property="sellerRate" />
    <result column="line_seller_type" jdbcType="VARCHAR" property="sellerType" />
    <result column="line_cid" jdbcType="BIGINT" property="cid" />
    <result column="line_sub_order_tax_fee" jdbcType="NUMERIC" property="subOrderTaxFee" />
    <result column="line_sub_order_tax_rate" jdbcType="NUMERIC" property="subOrderTaxRate" />
    <result column="line_oid" jdbcType="BIGINT" property="oid" />
    <result column="line_status" jdbcType="VARCHAR" property="status" />
    <result column="line_title" jdbcType="VARCHAR" property="title" />
    <result column="line_type" jdbcType="VARCHAR" property="type" />
    <result column="line_iid" jdbcType="VARCHAR" property="iid" />
    <result column="line_price" jdbcType="VARCHAR" property="price" />
    <result column="line_num_iid" jdbcType="BIGINT" property="numIid" />
    <result column="line_item_meal_id" jdbcType="INTEGER" property="itemMealId" />
    <result column="line_sku_id" jdbcType="BIGINT" property="skuId" />
    <result column="line_num" jdbcType="INTEGER" property="num" />
    <result column="line_outer_sku_id" jdbcType="VARCHAR" property="outerSkuId" />
    <result column="line_order_from" jdbcType="VARCHAR" property="orderFrom" />
    <result column="line_total_fee" jdbcType="NUMERIC" property="totalFee" />
    <result column="line_payment" jdbcType="NUMERIC" property="payment" />
    <result column="line_discount_fee" jdbcType="NUMERIC" property="discountFee" />
    <result column="line_adjust_fee" jdbcType="NUMERIC" property="adjustFee" />
    <result column="line_modified" jdbcType="TIMESTAMP" property="modified" />
    <result column="line_sku_properties_name" jdbcType="VARCHAR" property="skuPropertiesName" />
    <result column="line_refund_id" jdbcType="BIGINT" property="refundId" />
    <result column="line_is_oversold" jdbcType="INTEGER" property="isOversold" />
    <result column="line_is_service_order" jdbcType="INTEGER" property="isServiceOrder" />
    <result column="line_end_time" jdbcType="TIMESTAMP" property="endTime" />
    <result column="line_consign_time" jdbcType="TIMESTAMP" property="consignTime" />
    <result column="line_order_attr" jdbcType="VARCHAR" property="orderAttr" />
    <result column="line_shipping_type" jdbcType="VARCHAR" property="shippingType" />
    <result column="line_bind_oid" jdbcType="BIGINT" property="bindOid" />
    <result column="line_logistics_company" jdbcType="VARCHAR" property="logisticsCompany" />
    <result column="line_invoice_no" jdbcType="VARCHAR" property="invoiceNo" />
    <result column="line_is_daixiao" jdbcType="INTEGER" property="isDaixiao" />
    <result column="line_divide_order_fee" jdbcType="NUMERIC" property="divideOrderFee" />
    <result column="line_part_mjz_discount" jdbcType="NUMERIC" property="partMjzDiscount" />
    <result column="line_ticket_outer_id" jdbcType="VARCHAR" property="ticketOuterId" />
    <result column="line_ticket_expdate_key" jdbcType="VARCHAR" property="ticketExpdateKey" />
    <result column="line_store_code" jdbcType="VARCHAR" property="storeCode" />
    <result column="line_is_www" jdbcType="INTEGER" property="isWww" />
    <result column="line_tmser_spu_code" jdbcType="VARCHAR" property="tmserSpuCode" />
    <result column="line_bind_oids" jdbcType="VARCHAR" property="bindOids" />
    <result column="line_zhengji_status" jdbcType="INTEGER" property="zhengjiStatus" />
    <result column="line_md_qualification" jdbcType="VARCHAR" property="mdQualification" />
    <result column="line_md_fee" jdbcType="NUMERIC" property="mdFee" />
    <result column="line_customization" jdbcType="VARCHAR" property="customization" />
    <result column="line_inv_type" jdbcType="VARCHAR" property="invType" />
    <result column="line_is_sh_ship" jdbcType="INTEGER" property="isShShip" />
    <result column="line_shipper" jdbcType="VARCHAR" property="shipper" />
    <result column="line_f_type" jdbcType="VARCHAR" property="fType" />
    <result column="line_f_status" jdbcType="VARCHAR" property="fStatus" />
    <result column="line_f_term" jdbcType="VARCHAR" property="fTerm" />
    <result column="line_assembly_rela" jdbcType="VARCHAR" property="assemblyRela" />
    <result column="line_assembly_price" jdbcType="NUMERIC" property="assemblyPrice" />
    <result column="line_assembly_item" jdbcType="VARCHAR" property="assemblyItem" />
    <result column="line_last_modified_time" jdbcType="TIMESTAMP" property="lastModifiedTime" />
    <result column="line_create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="line_platform_id" jdbcType="VARCHAR" property="platformId" />
  </resultMap>
  
    <!--为减少数据库IO,使用一对多查询出关联信息-->
  <resultMap id="CommonResultMap" type="cn.baozun.entity.ods.crm.TmSalesOrder" extends="BaseResultMap" >
    <collection property="orderLineList" resultMap="OrderlineMap" />
  </resultMap>

原创粉丝点击