步骤 1: 分页工具类
// // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // package com.mideaframework.core.bean; import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; public class PagingDomain { private Integer pageNo; private Integer start = 0; private Integer pageSize = 30; private Date startTime; private Date endTime; private String orderBy = "1"; private String orderByType = "asc"; private String asc = " asc"; private MapdataMap = new HashMap(); public PagingDomain() { }
-----添加get set 方法 }
返回客户端响应类工具
// // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // package com.mideaframework.core.web; import com.google.common.collect.Lists; import java.io.Serializable; import java.util.List; public class PageResponseimplements Serializable { private static final long serialVersionUID = -2103014265407834780L; public List list; public Integer totalCount; public Integer totalPage; public Integer pageNo; public Integer pageSize; public Integer offset; public PageResponse() { this.list = Lists.newArrayList(); this.totalCount = 0; this.totalPage = 0; this.pageNo = 1; this.pageSize = 30; this.offset = 0; } public List getList() { return this.list; } public void setList(List list) { this.list = list; } public Integer getTotalCount() { return this.totalCount; } public void setTotalCount(Integer totalCount) { this.totalCount = totalCount; } public Integer getTotalPage() { return this.totalPage; } public void setTotalPage(Integer totalPage) { this.totalPage = totalPage; } public Integer getPageNo() { return this.pageNo; } public void setPageNo(Integer pageNo) { this.pageNo = pageNo; } public Integer getPageSize() { return this.pageSize; } public void setPageSize(Integer pageSize) { this.pageSize = pageSize; } public Integer getOffset() { return this.offset; } public void setOffset(Integer offset) { this.offset = offset; } public PageResponse(Integer pageNo, Integer pageSize, Integer totalCount, List list) { this.list = Lists.newArrayList(); this.totalCount = 0; this.totalPage = 0; this.pageNo = 1; this.pageSize = 30; this.offset = 0; this.init(pageNo, pageSize, totalCount, list); } public PageResponse(Integer pageNo, Integer pageSize, Integer totalCount) { this(pageNo, pageSize, totalCount, (List)null); } public PageResponse(Integer pageNo, Integer pageSize) { this(pageNo, pageSize, (Integer)null); } public void init(Integer pageNo, Integer pageSize, Integer totalCount, List list) { if (pageNo != null) { this.pageNo = pageNo; } if (pageSize != null) { this.pageSize = pageSize; } if (this.pageNo > 0) { this.offset = this.pageSize * this.pageNo; } if (totalCount != null) { this.totalCount = totalCount; this.totalPage = this.totalCount % pageSize > 0 ? this.totalCount / pageSize + 1 : this.totalCount / pageSize; } if (list != null) { this.list = list; } } }
步骤2:实体类继承 PagingDomain
public class ErpWorkOrder extends PagingDomain{}
步骤3 数据层 :
import com.midea.lmes.intelligent.logistics.domain.mes.base.entity.base.ErpWorkOrder; import com.midea.lmes.intelligent.logistics.dto.mes.base.ErpWorkOrderDto; import com.mideaframework.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; @Mapper public interface ErpWorkOrderMapper extends BaseMapper{}
步骤4:业务层 使用分页
@Override public PageResponseselectErpWorkOrderPage(ErpWorkOrder erpWorkOrder) { PageResponse pagingData = new PageResponse (); if (null == erpWorkOrder) { LOGGER.warn("select erpWorkOrder page, but erpWorkOrder is null..."); return pagingData; } //设置工单状态 用于IN 关键字查询 if(StringUtils.isNotEmpty(erpWorkOrder.getStatusTypeName())){ String[] str=erpWorkOrder.getStatusTypeName().split(","); StringBuffer stringBuffer =new StringBuffer(); String statusTypeName=""; List list =new ArrayList (); for (int i = 0; i erpWorkOrders = selectErpWorkOrderByIndex(erpWorkOrder); if(erpWorkOrders !=null && erpWorkOrders.size()>0){ SysOrg sysOrg = new SysOrg();; for (int i = 0; i listSysOrg =sysOrgClient.queryLineCodeByCodeAndOrgId(sysOrg); if(listSysOrg !=null && listSysOrg.size()>0){ for (int j = 0; j 步骤5 控制层
/** * @return 查询集合 */ @PostMapping(value = "/fndContainerInvRelations/search") public JsonResponse search(@RequestBody FndContainerInvRelation fndContainerInvRelation,HttpServletRequest request) { RestDoing doing = jsonResponse -> { PageResponsePageResponse = fndContainerInvRelationServiceImpl.selectFndContainerInvRelationPage(fndContainerInvRelation); jsonResponse.data = PageResponse; }; return doing.go(request, logger); } 返回客户端响应类
// // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // package com.mideaframework.core.web; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.serializer.SerializerFeature; import com.mideaframework.core.constants.BaseCodeEnum; import com.mideaframework.core.exception.IBusinessException; import java.io.Serializable; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; public class JsonResponseimplements Serializable { private static final long serialVersionUID = -6609499448346439617L; private String code; private String msg; private String timestamp; public T data; public JsonResponse() { this.code = BaseCodeEnum.SUCCESS.getCode(); this.msg = BaseCodeEnum.SUCCESS.getMsg(); } public JsonResponse(IBusinessException resultCodeConstant) { this.code = BaseCodeEnum.SUCCESS.getCode(); this.msg = BaseCodeEnum.SUCCESS.getMsg(); this.code = resultCodeConstant.getCode(); this.msg = resultCodeConstant.getMsg(); } public JsonResponse(String code, String msg) { this.code = BaseCodeEnum.SUCCESS.getCode(); this.msg = BaseCodeEnum.SUCCESS.getMsg(); this.code = code; this.msg = msg; } private void saveJsonResult(IBusinessException resultCodeConstant) { this.code = resultCodeConstant.getCode(); this.msg = resultCodeConstant.getMsg(); } public void errorParam(String msg, Logger log) { this.code = BaseCodeEnum.FAILED.getCode(); this.msg = BaseCodeEnum.FAILED.getMsg() + msg; log.error("error code|{}|msg|{}|", this.code, msg); } public void errorParam(String code, String msg, Logger log) { this.custom(code, msg, log); } public void custom(String code, String msg, Logger log) { this.code = code; this.msg = msg; log.error("error code|{}|msg:{}", code, msg); } public void saveResult(String codeInput, Logger log) { this.saveResult(codeInput, (String)null, (Logger)null); } public void saveResult(String codeInput, String msg, Logger log) { byte var5 = -1; switch(codeInput.hashCode()) { case 48: if (codeInput.equals("0")) { var5 = 0; } default: switch(var5) { case 0: this.saveJsonResult(BaseCodeEnum.SUCCESS); break; default: this.saveJsonResult(BaseCodeEnum.FAILED); } if (StringUtils.isNotBlank(msg)) { this.setMsg(msg); } if (null != log) { log.error("error code:{}|msg:{}", this.code, msg); } } } public String getTimestamp() { return this.timestamp; } public void setTimestamp(String timestamp) { this.timestamp = timestamp; } public String getCode() { return this.code; } public void setCode(String code) { this.code = code; } public String getMsg() { return this.msg; } public void setMsg(String msg) { this.msg = msg; } public T getData() { return this.data; } public void setData(T data) { this.data = data; } public void go(Logger logger) { StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); StackTraceElement[] var3 = stackTrace; int var4 = stackTrace.length; for(int var5 = 0; var5 < var4; ++var5) { StackTraceElement s = var3[var5]; logger.error(s.getClassName() + ",-" + s.getMethodName() + ":[ " + s.getLineNumber() + "]"); } } public JsonResponse build(String code, String msg) { this.code = code; this.msg = msg; LocalDateTime arrivalDate = LocalDateTime.now(); DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss:SSS"); String timestamp = arrivalDate.format(format); this.timestamp = timestamp; return this; } public String toString() { return JSON.toJSONStringWithDateFormat(this, "yyyy-MM-dd HH:mm:ss", new SerializerFeature[0]); } public static JsonResponse // // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // package com.mideaframework.core.web; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.mideaframework.core.constants.BaseCodeEnum; import com.mideaframework.core.exception.BusinessException; import com.mideaframework.core.exception.CommonException; import com.mideaframework.core.utils.SpringContextHolder; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Locale; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.MessageSource; import org.springframework.transaction.NoTransactionException; import org.springframework.transaction.interceptor.TransactionAspectSupport; @FunctionalInterface public interface RestDoing{ Logger log = LoggerFactory.getLogger(RestDoing.class); String sqlReturnFormat = "======================>return data : |{}|"; default JsonResponse go(Logger log) { return this.invoke((Object)null, (Object)null, (HttpServletRequest)null, (ObjectMapper)null, log); } default JsonResponse go(HttpServletRequest r, Logger log) { return this.invoke((Object)null, (Object)null, r, (ObjectMapper)null, log); } default JsonResponse go(HttpServletRequest r, ObjectMapper objectMapper, Logger log) { return this.invoke((Object)null, (Object)null, r, objectMapper, log); } default JsonResponse go(Object visitor, HttpServletRequest request, ObjectMapper objectMapper, Logger log) { return this.invoke((Object)null, visitor, request, objectMapper, log); } default JsonResponse go(Object inputData, Object visitor, HttpServletRequest request, ObjectMapper objectMapper, Logger log) { return this.invoke(inputData, visitor, request, objectMapper, log); } default JsonResponse invoke(Object inputData, Object visitor, HttpServletRequest request, ObjectMapper objectMapper, Logger log) { JsonResponse jr = new JsonResponse(); Object[] args = null; try { this.service(jr); } catch (CommonException var24) { log.error("throw CommonException{}|", var24); throw var24; } catch (BusinessException var25) { try { TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } catch (NoTransactionException var23) { log.error("NoTransactionException happen|{}|", var25); } jr.errorParam(var25.getCode(), var25.getMessage(), log); args = var25.getArgs(); } catch (Exception var26) { try { TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } catch (NoTransactionException var22) { log.error("NoTransactionException happen|{}|", var26); } log.error("error happen|{}|", var26); jr.saveResult(BaseCodeEnum.FAILED.getCode(), log); } finally { this.showReturnData(jr, objectMapper, log); } LocalDateTime arrivalDate = LocalDateTime.now(); DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); String timestamp = arrivalDate.format(format); if (StringUtils.isBlank(jr.getMsg())) { try { MessageSource messageSource = (MessageSource)SpringContextHolder.getBean(MessageSource.class); Locale locale = Locale.SIMPLIFIED_CHINESE; String msg = messageSource.getMessage(jr.getCode(), args, locale); jr.setMsg(msg); } catch (Exception var21) { log.error("cannot find messageSource,error:{}", var21.getMessage()); } } jr.setTimestamp(timestamp); return jr; } default void showReturnData(JsonResponse jr, ObjectMapper objectMapper, Logger log) { if (objectMapper != null) { try { String returnData = objectMapper.writeValueAsString(jr); log.warn("======================>return data : |{}|", returnData); } catch (JsonProcessingException var5) { log.error(var5.getMessage(), var5); } } } void service(JsonResponse var1) throws Exception; } 步骤6 xml 文件
前端传给后台 字段 vue.js
{"pageNo":1,"pageSize":10}