多输入框查询
需求分析
需求:任意一个输入框,输入内容点击搜索都可以精准搜索到对应的内容。
代码实现
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数据: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;
}
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>:泛型类封装分页查询结果,包含页面信息、页码、每页条目数、总记录数以及当前页面的数据项列表
PageResult.<DisputeMerchantManageResponse>builder():创建了用于构建PageResult<DisputeMerchantManageResponse>对象的构造器;后续代码可以通过该构造器设置分页信息、总记录数和当前页面的数据项列表,最终得到一个完整的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); }
Mapper
List<DisputeMerchantManageResponse> merchantDisputeManage(DisputeMerchantManageBO 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>
测试