欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java多輸入框查詢需求實(shí)現(xiàn)方法詳解

 更新時(shí)間:2023年10月08日 10:03:01   作者:wei_shuo  
這篇文章主要給大家介紹了Java多輸入框查詢需求實(shí)現(xiàn)的相關(guān)資料,文中通過代碼以及圖文介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Java具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

多輸入框查詢

需求分析

任意一個(gè)輸入框,輸入內(nèi)容點(diǎn)擊搜索都可以精準(zhǔn)搜索到對(duì)應(yīng)的內(nèi)容

代碼實(shí)現(xiàn)

Controller接口編寫

 @PostMapping("merchant/manage")
 public Result<PageResult<DisputeMerchantManageResponse>>
 merchantDisputeManage(@RequestBody DisputeMerchantManageRequest request) {
     return Result.succ(merchantDisputeFacade.merchantDisputeManage(request));
 }
  • Result<PageResult<DisputeMerchantManageResponse>>:返回給前端的字段:VO
  • @RequestBody DisputeMerchantManageRequest request:接收前端傳遞的JSON數(shù)據(jù):BO
  • merchantDisputeFacade.merchantDisputeManage(request):調(diào)用Service的merchantDisputeManage方法,傳遞接受的參數(shù)request

Service編寫

MerchantDisputeFacade.java

public PageResult<DisputeMerchantManageResponse> merchantDisputeManage(DisputeMerchantManageRequest request) {
       DisputeMerchantManageBO manageBO = DisputeMerchantManageBO.convert(request);
       List<DisputeMerchantManageResponse> list = merchantDisputeService.merchantDisputeManage(manageBO);
       PageResult<DisputeMerchantManageResponse> pageResult = PageResult.		        				           <DisputeMerchantManageResponse>builder().pageNo(Integer.parseInt(request.getPageNo()))
                .pageSize(Integer.parseInt(request.getPageSize()))
                .total(merchantDisputeService.merchantDisputeManageCount(manageBO)).items(list).build();
        return pageResult;
    }
  • DisputeMerchantManageBO manageBO = DisputeMerchantManageBO.convert(request):將DisputeMerchantManageRequest對(duì)象 request 轉(zhuǎn)換為 DisputeMerchantManageBO對(duì)象 manageBO
  • List<DisputeMerchantManageResponse> list = merchantDisputeService.merchantDisputeManage(manageBO):調(diào)用merchantDisputeService中的merchantDisputeManage方法,傳遞manageBO作為參數(shù),然后獲取一個(gè)List類型的結(jié)果列表
 PageResult<DisputeMerchantManageResponse> pageResult = PageResult.		        				           <DisputeMerchantManageResponse>builder()
     			.pageNo(Integer.parseInt(request.getPageNo()))
                .pageSize(Integer.parseInt(request.getPageSize()))
                .total(merchantDisputeService.merchantDisputeManageCount(manageBO))
     .items(list).build();
  • PageResult<DisputeMerchantManageResponse>:泛型類封裝分頁查詢結(jié)果,包含頁面信息、頁碼、每頁條目數(shù)、總記錄數(shù)以及當(dāng)前頁面的數(shù)據(jù)項(xiàng)列表
  • PageResult.<DisputeMerchantManageResponse>builder():創(chuàng)建了用于構(gòu)建PageResult<DisputeMerchantManageResponse>對(duì)象的構(gòu)造器;后續(xù)代碼可以通過該構(gòu)造器設(shè)置分頁信息、總記錄數(shù)和當(dāng)前頁面的數(shù)據(jù)項(xiàng)列表,最終得到一個(gè)完整的PageResult對(duì)象
  • .pageNo(Integer.parseInt(request.getPageNo())):設(shè)置PageResult對(duì)象的當(dāng)前頁碼
  • .pageSize(Integer.parseInt(request.getPageSize())):設(shè)置PageResult對(duì)象的每頁條目數(shù)
  • .total(merchantDisputeService.merchantDisputeManageCount(manageBO)):設(shè)置PageResult對(duì)象的總記錄數(shù)
  • .items(list).build():設(shè)置PageResult對(duì)象的數(shù)據(jù)項(xiàng)列表,并完成構(gòu)建PageResult對(duì)象
  • .items(list):獲取的數(shù)據(jù)項(xiàng)列表list設(shè)置為PageResult對(duì)象的數(shù)據(jù)項(xiàng)列表屬性
  • .build():完成PageResult對(duì)象的構(gòu)建,最終得到一個(gè)完整的PageResult對(duì)象

Service編寫

MerchantDisputeService.java

    public List<DisputeMerchantManageResponse> merchantDisputeManage(DisputeMerchantManageBO disputeMerchantManageBO) {
        Merchant merchant = AuthContextHolder.getLoginMerchant();
        disputeMerchantManageBO.setMerchantNo(merchant.getMerchantNo());
        return merchantDisputeMapper.merchantDisputeManage(disputeMerchantManageBO);
    }
  • Merchant merchant = AuthContextHolder.getLoginMerchant():通過AuthContextHolder獲取當(dāng)前登錄的商家(Merchant)對(duì)象;AuthContextHolder:用于在當(dāng)前線程的上下文中存儲(chǔ)和管理認(rèn)證信息
  • disputeMerchantManageBO.setMerchantNo(merchant.getMerchantNo()):獲取merchant中的MerchantNo(商戶號(hào)),并存儲(chǔ)在disputeMerchantManageBO中
  • merchantDisputeMapper.merchantDisputeManage(disputeMerchantManageBO):調(diào)用Mapper層merchantDisputeManage方法將disputeMerchantManageBO作為參數(shù)傳遞給Mapper

Mapper

    List<DisputeMerchantManageResponse> merchantDisputeManage(DisputeMerchantManageBO disputeMerchantManageBO);

Mapper.xml

通過聯(lián)表查詢,查詢merchant_dispute和transaction_order表對(duì)應(yīng)字段,通過對(duì)disputeMerchantManageBO字段傳入的條件動(dòng)態(tài)生成查詢語句,并按照創(chuàng)建時(shí)間進(jìn)行降序排序,最后返回指定分頁范圍內(nèi)的結(jié)果

    <select id="merchantDisputeManage" resultType="com.moozumi.bean.response.dispute.DisputeMerchantManageResponse">
        select md.id disputeId,md.status disputeStatus,md.type disputeType,o.merchant_no merchantNo,o.unique_id
        uniqueId,md.content disputeContent,
        o.transaction_id transactionId,md.is_reply isReply,md.created_at disputeCreatedAt,o.is_chargeback isChargeback,
        o.billing_email billingEmail,o.create_at paymentCreatedAt,
        o.application_domain,md.order_id
        from merchant_dispute md,transaction_order o
        where md.order_id = o.unique_id
        <if test="merchantNo != null and merchantNo != ''">
            and o.merchant_no = #{merchantNo}
        </if>
        <if test="uniqueId != null and uniqueId != ''">
            and o.unique_id = #{uniqueId}
        </if>
        <if test="disputeStatus != null">
            and md.status = #{disputeStatus}
        </if>
        <if test="disputeType != null">
            and md.type = #{disputeType}
        </if>
        <if test="isReply != null">
            and md.is_reply = #{isReply}
        </if>
        <if test="isChargeback != null">
            and o.is_chargeback = #{isChargeback}
        </if>
        <if test="applicationDomain != null and applicationDomain != ''">
            and o.application_domain = #{applicationDomain}
        </if>
        <if test="orderId != null and orderId != ''">
            and md.order_id = #{orderId}
        </if>
        order by md.created_at desc
        limit #{limit} offset #{offset}
    </select>

BO:對(duì)前端傳遞參數(shù)進(jìn)行接收處理

使用DisputeMerchantManageBO處理request的主要目的是為了在業(yè)務(wù)邏輯層(Service層)中更好地封裝業(yè)務(wù)邏輯和數(shù)據(jù)處理

@Data
public class DisputeMerchantManageBO {
    private String merchantNo;
    private String uniqueId;
    private Integer disputeStatus;
    private Integer disputeType;
    private Boolean isReply;
    private Boolean isChargeback;
    private Integer offset;
    private Integer limit;
    private String orderId;
    private String applicationDomain;
    public void setOffset(String pageNo, String pageSize) {
        this.offset = (Integer.parseInt(pageNo) - 1) * Integer.parseInt(pageSize);
    }
    public void setLimit(String pageSize) {
        this.limit = Integer.parseInt(pageSize);
    }
    //DisputeMerchantManageRequest 轉(zhuǎn)換成 BO
    public static DisputeMerchantManageBO convert(DisputeMerchantManageRequest disputeMerchantManageRequest) {
        DisputeMerchantManageBO disputeMerchantManageBO = new DisputeMerchantManageBO();
        disputeMerchantManageBO.setMerchantNo(AuthContextHolder.getLoginMerchant().getMerchantNo());
        disputeMerchantManageBO.setUniqueId(disputeMerchantManageRequest.getUniqueId());
        disputeMerchantManageBO.setDisputeStatus(disputeMerchantManageRequest.getDisputeStatus());
        disputeMerchantManageBO.setDisputeType(disputeMerchantManageRequest.getDisputeType());
        disputeMerchantManageBO.setIsReply(disputeMerchantManageRequest.getIsReply());
        disputeMerchantManageBO.setIsChargeback(disputeMerchantManageRequest.getIsChargeback());
        disputeMerchantManageBO.setOffset(disputeMerchantManageRequest.getPageNo(), disputeMerchantManageRequest.getPageSize());
        disputeMerchantManageBO.setLimit(disputeMerchantManageRequest.getPageSize());
        disputeMerchantManageBO.setOrderId(disputeMerchantManageRequest.getOrderId());
        disputeMerchantManageBO.setApplicationDomain(disputeMerchantManageRequest.getApplicationDomain());
        return disputeMerchantManageBO;
    }
}

request:請(qǐng)求類,前端向后端請(qǐng)求的字段

DisputeMerchantManageRequest.java

DisputeMerchantManageRequest:字段對(duì)應(yīng)搜索框需要搜索的字段

@Data
public class DisputeMerchantManageRequest extends PageQuery {
    private String merchantNo;
    private String uniqueId;
    private Integer disputeStatus;
    private Integer disputeType;
    private Boolean isReply;
    private Boolean isChargeback;
    private String orderId;
    private String applicationDomain;
}

response:響應(yīng)類,后端響應(yīng)給前端的字段

DisputeMerchantManageResponse:后端通過DisputeMerchantManageRequest字段查詢數(shù)據(jù)庫返回查詢出的數(shù)據(jù)

@Data
public class DisputeMerchantManageResponse {
    private Long disputeId;
    private Integer disputeStatus;
    private Integer disputeType;
    private String disputeContent;
    private String merchantNo;
    private String uniqueId;
    private String transactionId;
    private Boolean isReply;
    private Boolean isChargeback;
    private String billingEmail;
    private Date disputeCreatedAt;
    private Date paymentCreatedAt;
    private String orderId;
    private String applicationDomain;
}

PageResult類

@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class PageResult<T> implements Serializable {
    @ApiModelProperty("總記錄數(shù)")
    private Integer total;
    private Integer pageNo;
    private Integer pageSize;
    private Integer totalPage;
    @ApiModelProperty("列表數(shù)據(jù)")
    @Builder.Default
    private List<T> items = Collections.emptyList();
    public static <T> PageResult<T> toPage(IPage<T> page) {
        PageResult<T> result = new PageResult<>();
        result.setItems(page.getRecords());
        result.setTotal((int) page.getTotal());
        result.setPageNo((int) page.getCurrent());
        result.setPageSize((int) page.getSize());
        result.setTotalPage(page.getTotal() % page.getSize() == 0 ?
                (int) (page.getTotal() / page.getSize()) : (int) (page.getTotal() / page.getSize() + 1));
        return result;
    }
    public static <T> PageResult<T> toPage(IPage<?> page, List<T> list) {
        PageResult<T> result = new PageResult<>();
        result.setItems(list);
        result.setTotal((int) page.getTotal());
        result.setPageNo((int) page.getCurrent());
        result.setPageSize((int) page.getSize());
        result.setTotalPage(page.getTotal() % page.getSize() == 0 ?
                (int) (page.getTotal() / page.getSize()) : (int) (page.getTotal() / page.getSize() + 1));
        return result;
    }
    public static <T> PageResult<T> toPage(PageResult<?> res, List<T> list) {
        PageResult<T> result = new PageResult<>();
        BeanUtils.copyProperties(res, result);
        result.setItems(list);
        return result;
    }
}

postman測試

總結(jié)

到此這篇關(guān)于Java多輸入框查詢需求實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Java多輸入框查詢內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • SpringBoot對(duì)接Twilio實(shí)現(xiàn)發(fā)送驗(yàn)證碼和驗(yàn)證短信碼

    SpringBoot對(duì)接Twilio實(shí)現(xiàn)發(fā)送驗(yàn)證碼和驗(yàn)證短信碼

    Twilio是一家提供云通信服務(wù)的公司,旨在幫助開發(fā)者和企業(yè)通過簡單的API實(shí)現(xiàn)各種通信功能,下面我們來看看如何對(duì)接Twilio實(shí)現(xiàn)發(fā)送驗(yàn)證碼和驗(yàn)證短信碼吧
    2025-03-03
  • Java回調(diào)機(jī)制解讀

    Java回調(diào)機(jī)制解讀

    本文主要介紹了Java回調(diào)機(jī)制的相關(guān)知識(shí),具有很好的參考價(jià)值,下面跟著小編一起來看下吧
    2017-02-02
  • MyBatis-Plus樂觀鎖插件的用法小結(jié)

    MyBatis-Plus樂觀鎖插件的用法小結(jié)

    樂觀鎖很樂觀,對(duì)任何事情都保持著一個(gè)樂觀的態(tài)度,認(rèn)為別人不會(huì)修改數(shù)據(jù),所以不會(huì)上鎖,只是在更新數(shù)據(jù)的時(shí)候,去判斷這條數(shù)據(jù)有沒有被別人修改過,這篇文章主要介紹了MyBatis-Plus樂觀鎖插件的用法,需要的朋友可以參考下
    2022-08-08
  • Java中Set集合的基本使用方法舉例

    Java中Set集合的基本使用方法舉例

    在Java中可以使用不同的實(shí)現(xiàn)類來創(chuàng)建和初始化Set集合,下面這篇文章主要給大家介紹了關(guān)于Java中Set集合的基本使用方法,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-07-07
  • 詳解SpringBoot注入數(shù)據(jù)的方式

    詳解SpringBoot注入數(shù)據(jù)的方式

    這篇文章主要介紹了詳解SpringBoot注入數(shù)據(jù)的方式,詳細(xì)的介紹了幾種注入方式,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-12-12
  • Spring Boot使用模板引擎JSP實(shí)例解析

    Spring Boot使用模板引擎JSP實(shí)例解析

    這篇文章主要介紹了Spring Boot使用模板引擎JSP實(shí)例解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-10-10
  • SpringBoot2.0 整合 SpringSecurity 框架實(shí)現(xiàn)用戶權(quán)限安全管理方法

    SpringBoot2.0 整合 SpringSecurity 框架實(shí)現(xiàn)用戶權(quán)限安全管理方法

    Spring Security是一個(gè)能夠?yàn)榛赟pring的企業(yè)應(yīng)用系統(tǒng)提供聲明式的安全訪問控制解決方案的安全框架。這篇文章主要介紹了SpringBoot2.0 整合 SpringSecurity 框架,實(shí)現(xiàn)用戶權(quán)限安全管理 ,需要的朋友可以參考下
    2019-07-07
  • java多線程文件下載器的實(shí)現(xiàn)

    java多線程文件下載器的實(shí)現(xiàn)

    本文主要介紹了java多線程文件下載器的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-11-11
  • Java解決浮點(diǎn)數(shù)計(jì)算不精確問題的方法詳解

    Java解決浮點(diǎn)數(shù)計(jì)算不精確問題的方法詳解

    在 Java 中,浮點(diǎn)數(shù)計(jì)算不精確問題指的是使用浮點(diǎn)數(shù)進(jìn)行運(yùn)算時(shí),由于浮點(diǎn)數(shù)的內(nèi)部表示方式和十進(jìn)制數(shù)的表示方式存在差異,導(dǎo)致計(jì)算結(jié)果可能出現(xiàn)誤差,本文就給大家介紹一下Java如何解決浮點(diǎn)數(shù)計(jì)算不精確問題,需要的朋友可以參考下
    2023-09-09
  • Spring中Bean的三種實(shí)例化方式詳解

    Spring中Bean的三種實(shí)例化方式詳解

    這篇文章主要給大家介紹了關(guān)于Spring中實(shí)例化bean的三種方式:構(gòu)造方法、靜態(tài)工廠和實(shí)例工廠,對(duì)我們學(xué)習(xí)有一定的參考價(jià)值,需要的小伙伴可以了解一下
    2022-06-06

最新評(píng)論