第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

將 XML 響應(yīng)拆分為頁(yè)面

將 XML 響應(yīng)拆分為頁(yè)面

泛舟湖上清波郎朗 2021-11-03 15:06:35
我想將 XML 響應(yīng)拆分為多個(gè)頁(yè)面,因?yàn)槲矣刑嗟?XML 項(xiàng)要發(fā)回。我試過(guò)這個(gè):XML 請(qǐng)求:<?xml version="1.0" encoding="UTF-8"?><reconcile>  <start_date>2018-04-08T11:02:44</start_date>  <end_date>2019-10-08T11:02:44</end_date>  <page>1</page></reconcile>JAXB:@XmlRootElement(name = "reconcile")@XmlAccessorType(XmlAccessType.FIELD)public class Reconcile {    @XmlElement(name = "start_date")    @XmlJavaTypeAdapter(LocalDateTimeXmlAdapter.class)    private LocalDateTime start_date;    @XmlElement(name = "end_date")    @XmlJavaTypeAdapter(LocalDateTimeXmlAdapter.class)    private LocalDateTime end_date;    @XmlElement(name = "page")    private String page;    ...../// getters and setters}SQL查詢:public List<PaymentTransactions> transactionsByDate(LocalDateTime start_date, LocalDateTime end_date, Merchants merchant, Terminals terminal) throws Exception {        String hql = "select e from " + PaymentTransactions.class.getName() + " e where e.created_at >= ? and e.created_at <= ?";        Query query = entityManager.createQuery(hql).setParameter(0, start_date).setParameter(1, end_date);        List<PaymentTransactions> paymentTransactions = (List<PaymentTransactions>) query.getResultList();        return paymentTransactions;}我想以某種方式<payment_response>....</payment_response>分成頁(yè)面以減少內(nèi)存開(kāi)銷。例如,當(dāng)我發(fā)送 1 時(shí),我想返回前 10 個(gè)。我該如何實(shí)施?
查看完整描述

1 回答

?
瀟湘沐

TA貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超6個(gè)贊

你怎么看這樣的事情?對(duì)不起,這是未經(jīng)測(cè)試的代碼,但這樣的事情應(yīng)該可以工作。


我創(chuàng)建了一個(gè)新的 PageInfo 類來(lái)存儲(chǔ)分頁(yè)信息。添加了一個(gè)查詢以獲取總行數(shù)并設(shè)置我的 page_info。然后限制查詢結(jié)果的數(shù)量。最后將值設(shè)置為 ReconcilePaymentResponse。


Class PageInfo {

    int current_page;

    int page_count;

    int per_page;

    int total_page;


    //constructor

    public PageInfo(int current_page, int page_count, int per_page) {

        //assign them

    }

    //getters

    //setters

}

SQL查詢:


public List<PaymentTransactions> transactionsByDate(LocalDateTime start_date, LocalDateTime end_date, Merchants merchant, Terminals terminal,

    PageInfo pageInfo) throws Exception {


    //figure out number of total rows

    String count_hql = "select count(*) from " + PaymentTransactions.class.getName() + " e where e.created_at >= ? and e.created_at <= ?";

    Query count_query = entityManager.createQuery(count_hql);

    int count = countQuery.uniqueResult();


    //figure out total pages

    int total_page = (int)Math.ceil(count/(double)pageInfo.getPerPage());

    pageInfo.setTotal_Page(total_page);


    String hql = "select e from " + PaymentTransactions.class.getName() + " e where e.created_at >= ? and e.created_at <= ?";

    Query query = entityManager.createQuery(hql)

        //set starting point

        .setFirstResult((pageInfo.getCurrentPage()-1) * pageInfo.getPerPage)

        //set max rows to return

        .setMaxResults(pageInfo.getPerPage)

        .setParameter(0, start_date).setParameter(1, end_date);

    List<PaymentTransactions> paymentTransactions = (List<PaymentTransactions>) query.getResultList();

    return paymentTransactions;

}

返回 XML:


        //initialize PageInfo with desired values

        PageInfo page_info = new PageInfo(1,10,4);

        List<PaymentTransactions> paymentTransactions = transactionsService

            .transactionsByDate(reconcile.getStart_date(), reconcile.getEnd_date(), merchant, terminal, page_info);  // pass in page_info


        ReconcilePaymentResponses pr = new ReconcilePaymentResponses();

        pr.setPage(page_info.getCurrentPage());

        pr.setPages_count(page_info.getPageCount());

        pr.setPer_page(page_info.getPerPage());

        pr.setTotal_count(String.valueOf(paymentTransactions.size()));


        for (int e = 0; e < paymentTransactions.size(); e++) {

            PaymentTransactions pt = paymentTransactions.get(e);


            ReconcilePaymentResponse obj = new ReconcilePaymentResponse();

            obj.setTransaction_type(pt.getType());

            pr.getPaymentResponse().add(obj);

        }


        return pr;


查看完整回答
反對(duì) 回復(fù) 2021-11-03
  • 1 回答
  • 0 關(guān)注
  • 138 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)