• Java 多输入框查询需求实现


    在这里插入图片描述

    💗wei_shuo的个人主页

    💫wei_shuo的学习社区

    🌐Hello World !


    输入框查询

    需求分析

    在这里插入图片描述

    任意一个输入框,输入内容点击搜索都可以精准搜索到对应的内容

    代码实现

    Controller接口编写

     @PostMapping("merchant/manage")
     public Result<PageResult<DisputeMerchantManageResponse>>
     merchantDisputeManage(@RequestBody DisputeMerchantManageRequest request) {
         return Result.succ(merchantDisputeFacade.merchantDisputeManage(request));
     }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • Result>:返回给前端的字段:VO
    • @RequestBody DisputeMerchantManageRequest request:接收前端传递的JSON数据:BO
    • merchantDisputeFacade.merchantDisputeManage(request):调用Service的merchantDisputeManage方法,传递接受的参数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;
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • DisputeMerchantManageBO manageBO = DisputeMerchantManageBO.convert(request):将DisputeMerchantManageRequest对象 request 转换为 DisputeMerchantManageBO对象 manageBO
    • List list = merchantDisputeService.merchantDisputeManage(manageBO):调用merchantDisputeService中的merchantDisputeManage方法,传递manageBO作为参数,然后获取一个List类型的结果列表
     PageResult<DisputeMerchantManageResponse> pageResult = PageResult.		        				           <DisputeMerchantManageResponse>builder()
         			.pageNo(Integer.parseInt(request.getPageNo()))
                    .pageSize(Integer.parseInt(request.getPageSize()))
                    .total(merchantDisputeService.merchantDisputeManageCount(manageBO))
         .items(list).build();
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • PageResult:泛型类封装分页查询结果,包含页面信息、页码、每页条目数、总记录数以及当前页面的数据项列表
    • PageResult.builder():创建了用于构建PageResult对象的构造器;后续代码可以通过该构造器设置分页信息、总记录数和当前页面的数据项列表,最终得到一个完整的PageResult对象
    • .pageNo(Integer.parseInt(request.getPageNo())):设置PageResult对象的当前页码
    • .pageSize(Integer.parseInt(request.getPageSize())):设置PageResult对象的每页条目数
    • .total(merchantDisputeService.merchantDisputeManageCount(manageBO)):设置PageResult对象的总记录数
    • .items(list).build():设置PageResult对象的数据项列表,并完成构建PageResult对象
    • .items(list):获取的数据项列表list设置为PageResult对象的数据项列表属性
    • .build():完成PageResult对象的构建,最终得到一个完整的PageResult对象

    Service编写

    MerchantDisputeService.java

        public List<DisputeMerchantManageResponse> merchantDisputeManage(DisputeMerchantManageBO disputeMerchantManageBO) {
            Merchant merchant = AuthContextHolder.getLoginMerchant();
            disputeMerchantManageBO.setMerchantNo(merchant.getMerchantNo());
            return merchantDisputeMapper.merchantDisputeManage(disputeMerchantManageBO);
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • Merchant merchant = AuthContextHolder.getLoginMerchant():通过AuthContextHolder获取当前登录的商家(Merchant)对象;AuthContextHolder:用于在当前线程的上下文中存储和管理认证信息
    • disputeMerchantManageBO.setMerchantNo(merchant.getMerchantNo()):获取merchant中的MerchantNo(商户号),并存储在disputeMerchantManageBO中
    • merchantDisputeMapper.merchantDisputeManage(disputeMerchantManageBO):调用Mapper层merchantDisputeManage方法将disputeMerchantManageBO作为参数传递给Mapper

    Mapper

        List<DisputeMerchantManageResponse> merchantDisputeManage(DisputeMerchantManageBO disputeMerchantManageBO);
    
    • 1

    Mapper.xml

    • 通过联表查询,查询merchant_dispute和transaction_order表对应字段,通过对disputeMerchantManageBO字段传入的条件动态生成查询语句,并按照创建时间进行降序排序,最后返回指定分页范围内的结果
        <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>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35

    BO:对前端传递参数进行接收处理

    • 使用DisputeMerchantManageBO处理request的主要目的是为了在业务逻辑层(Service层)中更好地封装业务逻辑和数据处理
    @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 转换成 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;
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37

    request:请求类,前端向后端请求的字段

    DisputeMerchantManageRequest.java

    DisputeMerchantManageRequest:字段对应搜索框需要搜索的字段

    @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;
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    response:响应类,后端响应给前端的字段

    DisputeMerchantManageResponse:后端通过DisputeMerchantManageRequest字段查询数据库返回查询出的数据

    @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;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    PageResult类

    @Data
    @SuperBuilder
    @NoArgsConstructor
    @AllArgsConstructor
    public class PageResult<T> implements Serializable {
    
        @ApiModelProperty("总记录数")
        private Integer total;
        private Integer pageNo;
        private Integer pageSize;
        private Integer totalPage;
    
        @ApiModelProperty("列表数据")
        @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;
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46

    postman测试

    在这里插入图片描述

    在这里插入图片描述

    在这里插入图片描述


    🌼 结语:创作不易,如果觉得博主的文章赏心悦目,还请——点赞👍收藏⭐️评论📝


    在这里插入图片描述

  • 相关阅读:
    SLAM从入门到精通(用c++实现机器人运动控制)
    STM32的HAL库SPI操作(master 模式)-根据时序图配置SPI
    网易To B,柔外刚中
    (附源码)基于Springboot的球鞋调货管理系统设计与实现 毕业设计 160942
    Spring-FactoryBean的源码——简略解析(上)
    获取1688店铺详情 API接口(获取卖家昵称、店铺类型、公司信息、店铺标题、店铺主页)
    二叉树的前序遍历
    Ansible之playbook剧本
    封装读取配置类python&java实现
    【Linux】第七章 进程控制(进程创建+进程终止+进程等待+进程替换+min_shell)
  • 原文地址:https://blog.csdn.net/weixin_62765017/article/details/132038818