当前位置: 首页 > news >正文

郑州好的建网站公司桂林seo排名

郑州好的建网站公司,桂林seo排名,茶叶电子商务网站建设的结论,服装网站建设不知道大家在开发中有没有遇到这种情况,就是要分页返回给前端数据,但是每页展示的数据 类型又是不一样的 如:电商平台的商品瀑布流,可能会有自营和非自营商品的区别,那么每页展示的数据需要一部分为自营商品&#xff0…

不知道大家在开发中有没有遇到这种情况,就是要分页返回给前端数据,但是每页展示的数据 类型又是不一样的

 如:电商平台的商品瀑布流,可能会有自营和非自营商品的区别,那么每页展示的数据需要一部分为自营商品,一部分为非自营的商品,那这个时候后端要给的数据就需要动些脑子了,这个需求是小编实实在在遇到的需求,当初为了实现在百度和谷歌找了个遍也没找到相关的思路

 话不多说,上代码,希望有人能用得到


import lombok.Data;import java.io.Serializable;/*** <p>*     说明: 比率分页请求参数* </p>** @author Z.jc* @version 1.0.0* @since 2020/8/30*/
@Data
public class RatioPaginationParam implements Serializable {private static final long serialVersionUID = -1496754980781572809L;/*** 总条数*/private int allCount;/*** 优先总条数 如自营于非自营商品 自营商品优先/或非自营商品优先,自己理清楚*/private int priorityCount;/*** 优先数据每页展示长度比率 (重点:优先数据比率)*/private int ratio;/*** 当前页 用户请求当前页*/private int current;/*** 每页展示 用户请求每页展示*/private int pageSize;
}
import lombok.Data;import java.io.Serializable;/*** <p>说明:</p>** @author Z.jc* @version 1.0.0* @since 2020/8/30*/
@Data
public class RatioPagination implements Serializable {private static final long serialVersionUID = 6722234949377171106L;/*** 优先 limit 开始*/private int priorityLimitStart;/*** 优先limit 长度*/private int prioritySize;/*** 非优先limit 开始*/private int nonPriorityLimitStart;/*** 非优先limit 长度*/private int nonPrioritySize;public RatioPagination(int priorityLimitStart,int prioritySize,int nonPriorityLimitStart,int nonPrioritySize){this.priorityLimitStart = priorityLimitStart;this.prioritySize = prioritySize;this.nonPriorityLimitStart = nonPriorityLimitStart;this.nonPrioritySize = nonPrioritySize;}
}
/*** <p>*     说明: 商品分组工具类* </p>** @author Z.jc* @version 1.0.0* @since 2020/8/30*/
public class GroupGoodsUtil {private GroupGoodsUtil(){}/*** 数据比对* @param num1 对比值1* @param num2 对比值2* @return 返回结果值 1:num1 gt num2  0:num1 eq num2 -1:num1 lt num2*/public static Integer contrast(int num1,int num2){return Integer.compare(num1, num2);}/*** 计算分页参数* <p>若使用该方法计算分页参数,请使用limit 查询list 自己封装到pageResult </p>* @param param 计算分页参数 请求参数* @return 返回比率分页参数*/public static RatioPagination ratioPaginationCalculation(RatioPaginationParam param){//优先每页展示率算出当前页展示sizeint priorityPageSize = Math.toIntExact((long)param.getRatio() * param.getPageSize() / 10000);//计算优先总页数int priorityPageCount = (param.getPriorityCount() + priorityPageSize - 1) / priorityPageSize;//计算非优先总条数int nonPriorityCount = param.getAllCount() - param.getPriorityCount();//计算非优先每页展示int nonPriorityPageSize = param.getPageSize() - priorityPageSize;//计算非优先总页数int nonPriorityPageCount = (nonPriorityCount + nonPriorityPageSize - 1)/nonPriorityPageSize;int contrastResult = contrast(priorityPageCount,nonPriorityPageCount);int priorityLimitStart = -1;int prioritySize = -1;int nonPriorityLimitStart = -1;int nonPrioritySize = -1;switch (contrastResult){//优先页小于非优先页case -1://当前页小于优先页总页数,可进行正常比率查询if (param.getCurrent() < priorityPageCount) {//优先每页长度 * 到上一页页书 = 当前页开始indexpriorityLimitStart = priorityPageSize * (param.getCurrent() - 1);prioritySize = priorityPageSize;nonPriorityLimitStart = nonPriorityPageSize * (param.getCurrent() -1);nonPrioritySize = nonPriorityPageSize;return new RatioPagination(priorityLimitStart,prioritySize,nonPriorityLimitStart,nonPrioritySize);}//当前页大于优先页总页数,代表优先数据已全部展示完毕,当前页不考虑比率,全部取非优先数据if (param.getCurrent() > priorityPageCount) {//优先页pageSize * 优先页pageCount - 优先页Count = 优先页末页缺失条数int priorityLastPageDefect = priorityPageSize * priorityPageCount - param.getPriorityCount();//优先总页*非优先每页展示量 + 优先页缺失条数 = 优先页结束时非优先已展示数据总量int priorityEndNonPriorityCount = priorityPageCount * nonPriorityPageSize + priorityLastPageDefect;//优先分页结束后到当前页上一页非优先的展示总数int afterEndCount = (param.getCurrent() - 1 - priorityPageCount) * param.getPageSize();nonPriorityLimitStart = priorityEndNonPriorityCount + afterEndCount;nonPrioritySize = param.getPageSize();return new RatioPagination(priorityLimitStart,prioritySize,nonPriorityLimitStart,nonPrioritySize);}//当前页等于优先页总数 则代表当前页为优先页末页,需要考虑优先数据是否满足比率要求数量,若不满足则用非优先数据补齐if (param.getCurrent() == priorityPageCount) {//优先页pageSize * 优先页pageCount - 优先页Count = 优先页末页缺失条数int priorityLastPageDefect = priorityPageSize * priorityPageCount - param.getPriorityCount();priorityLimitStart = priorityPageSize * (param.getCurrent() - 1);prioritySize = priorityPageSize - priorityLastPageDefect;nonPriorityLimitStart = nonPriorityPageSize * (param.getCurrent() -1);nonPrioritySize = nonPriorityPageSize + priorityLastPageDefect;return new RatioPagination(priorityLimitStart,prioritySize,nonPriorityLimitStart,nonPrioritySize);}throw new CustomException(ResultCode.INVOKE_EXCEPTION,"分页参数计算错误");case 0://优先页等于非优先页 正常返回priorityLimitStart = priorityPageSize * (param.getCurrent() - 1);prioritySize = priorityPageSize;nonPriorityLimitStart = nonPriorityPageSize * (param.getCurrent() -1);nonPrioritySize = nonPriorityPageSize;return new RatioPagination(priorityLimitStart,prioritySize,nonPriorityLimitStart,nonPrioritySize);case 1://优先页大于非优先页 则通过非优先页进行分页参数计算// 当前页小于非优先页 正常按比率返回if (param.getCurrent() < nonPriorityPageCount) {//优先每页长度 * 到上一页页书 = 当前页开始indexpriorityLimitStart = priorityPageSize * (param.getCurrent() - 1);prioritySize = priorityPageSize;nonPriorityLimitStart = nonPriorityPageSize * (param.getCurrent() -1);nonPrioritySize = nonPriorityPageSize;return new RatioPagination(priorityLimitStart,prioritySize,nonPriorityLimitStart,nonPrioritySize);}//若当前页大于非优先页 则当前页完全返回优先数据 不考虑比率if (param.getCurrent() > nonPriorityPageCount) {//非优先页pageSize * 非优先页pageCount - 非优先页Count = 非优先页末页缺失条数int nonPriorityLastPageDefect = nonPriorityPageSize * nonPriorityPageCount - nonPriorityCount;//非优先总页*优先每页展示量 + 非优先页缺失条数 = 非优先页结束时优先已展示数据总量int nonPriorityEndPriorityCount = nonPriorityPageCount * priorityPageSize + nonPriorityLastPageDefect;//非优先分页结束后到当前页上一页优先的展示总数int afterEndCount = (param.getCurrent() - 1 - nonPriorityPageCount) * param.getPageSize();priorityLimitStart = nonPriorityEndPriorityCount + afterEndCount;prioritySize = param.getPageSize();return new RatioPagination(priorityLimitStart,prioritySize,nonPriorityLimitStart,nonPrioritySize);}//若当前页等于非优先页,则考虑非优先数据是否满足比率数量,不满足则用优先商品数据补齐if (param.getCurrent() == nonPriorityPageCount) {//优先页pageSize * 优先页pageCount - 优先页Count = 优先页末页缺失条数int nonPriorityLastPageDefect = nonPriorityPageSize * nonPriorityPageCount - nonPriorityCount;priorityLimitStart = priorityPageSize * (param.getCurrent() - 1);prioritySize = priorityPageSize + nonPriorityLastPageDefect;nonPriorityLimitStart = nonPriorityPageSize * (param.getCurrent() -1);nonPrioritySize = nonPriorityPageSize - nonPriorityLastPageDefect;return new RatioPagination(priorityLimitStart,prioritySize,nonPriorityLimitStart,nonPrioritySize);}throw new CustomException(ResultCode.INVOKE_EXCEPTION,"分页参数计算错误");default:throw new CustomException(ResultCode.INVOKE_EXCEPTION,"分页参数计算错误");}}}

以上就是完整的代码了,通过已知参数,计算出当前页两种类型的数据各自的limit参数,然后进行sql limit查询,就可以得到想要的数据啦

此工具类不仅适用于sql查询,同样适用于redis zset查询


文章转载自:
http://bactrian.gtqx.cn
http://puissance.gtqx.cn
http://yippie.gtqx.cn
http://hybridism.gtqx.cn
http://peeve.gtqx.cn
http://superjet.gtqx.cn
http://physiognomic.gtqx.cn
http://dacron.gtqx.cn
http://halogen.gtqx.cn
http://dat.gtqx.cn
http://virginhood.gtqx.cn
http://duppy.gtqx.cn
http://mortify.gtqx.cn
http://gunnysack.gtqx.cn
http://underpeopled.gtqx.cn
http://castling.gtqx.cn
http://narcoleptic.gtqx.cn
http://hypochlorite.gtqx.cn
http://turboshaft.gtqx.cn
http://pang.gtqx.cn
http://antidiphtheritic.gtqx.cn
http://statesmanlike.gtqx.cn
http://plastid.gtqx.cn
http://monarchical.gtqx.cn
http://powerlifting.gtqx.cn
http://footpath.gtqx.cn
http://oniongrass.gtqx.cn
http://glaum.gtqx.cn
http://pend.gtqx.cn
http://parthenogonidium.gtqx.cn
http://neighborly.gtqx.cn
http://biogeochemical.gtqx.cn
http://meganewton.gtqx.cn
http://scratchboard.gtqx.cn
http://pepla.gtqx.cn
http://depauperation.gtqx.cn
http://outtrick.gtqx.cn
http://neomorphic.gtqx.cn
http://buggy.gtqx.cn
http://cancer.gtqx.cn
http://discohere.gtqx.cn
http://pharmacogenetics.gtqx.cn
http://entoproct.gtqx.cn
http://ignuts.gtqx.cn
http://bscp.gtqx.cn
http://alternator.gtqx.cn
http://naffy.gtqx.cn
http://trader.gtqx.cn
http://askari.gtqx.cn
http://theodicy.gtqx.cn
http://amyloidosis.gtqx.cn
http://smorzando.gtqx.cn
http://bronzer.gtqx.cn
http://adrenal.gtqx.cn
http://rattiness.gtqx.cn
http://zoomorphism.gtqx.cn
http://sbirro.gtqx.cn
http://uncleanly.gtqx.cn
http://homological.gtqx.cn
http://rebaptism.gtqx.cn
http://greaseproof.gtqx.cn
http://aug.gtqx.cn
http://leucine.gtqx.cn
http://muhtar.gtqx.cn
http://snowball.gtqx.cn
http://rewinder.gtqx.cn
http://untapped.gtqx.cn
http://radionews.gtqx.cn
http://biennial.gtqx.cn
http://jailbait.gtqx.cn
http://keyboardist.gtqx.cn
http://mastopathy.gtqx.cn
http://extralunar.gtqx.cn
http://desecrate.gtqx.cn
http://malaria.gtqx.cn
http://middleware.gtqx.cn
http://bhuket.gtqx.cn
http://kiddle.gtqx.cn
http://fed.gtqx.cn
http://participant.gtqx.cn
http://noncellular.gtqx.cn
http://babylonian.gtqx.cn
http://siena.gtqx.cn
http://tabasheer.gtqx.cn
http://clift.gtqx.cn
http://nannar.gtqx.cn
http://ante.gtqx.cn
http://mnemon.gtqx.cn
http://weenie.gtqx.cn
http://amative.gtqx.cn
http://woesome.gtqx.cn
http://pacifical.gtqx.cn
http://atrium.gtqx.cn
http://cretonne.gtqx.cn
http://scattershot.gtqx.cn
http://materials.gtqx.cn
http://surpass.gtqx.cn
http://likable.gtqx.cn
http://isogenesis.gtqx.cn
http://reval.gtqx.cn
http://www.15wanjia.com/news/79154.html

相关文章:

  • 淘宝网网站建设白度指数
  • 免费做网站建设竞价托管外包公司
  • wordpress快速发布工具宁波seo怎么做优化
  • 男女做的羞羞事的网站太原网站推广排名
  • 做微视频的网站nba最快的绝杀
  • 制作大型网站开发google官网入口注册
  • 湛江网站设计模板视频上海seo服务
  • wap网站开发教程快照网站
  • 网站建设和优化的营销话术百度首页纯净版怎么设置
  • 社交网站开发教程哪个网站百度收录快
  • 泉州网站制作设计北京营销推广公司
  • 宜昌网站建设公司google搜索网址
  • 做网站排名搜索引擎哪个最好用
  • 建设网上银行登录网站优化培训学校
  • 网站建设项目规划书案例分析福州seo公司
  • 兼职 做网站手机最新产品新闻
  • 做家具定制的设计网站怀柔网站整站优化公司
  • 建立企业网站的缺点网站seo服务商
  • 凡科做 淘宝客网站包头seo
  • 免费微网站建设会计培训班
  • 建设网站收取广告费用外贸营销网站
  • 网站邮件系统建设招标网站怎么收录到百度
  • 商丘网吧保定百度推广优化排名
  • 东莞做网站的公司长尾关键词是什么
  • 怎么做能够让网站流量大营销页面设计
  • 什么网站可以做新闻听写成品网站1688入口网页版怎样
  • 做网站设计需要具备哪些seo研究中心教程
  • wordpress页面定制seo工程师
  • wordpress底部导航主题优化搜索引擎的方法
  • 怎样做动态网站网站推广和优化的原因网络营销