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

网站 选项卡 图标wordpress 开发h5页面

网站 选项卡 图标,wordpress 开发h5页面,做黄金期货的网站,设计网址合集PageHelper自定义Count查询及其优化 文章目录 PageHelper自定义Count查询及其优化一#xff1a;背景1.1、解决方法 二#xff1a;利用反射判断请求参数是否有模糊查询2.1、分页不执行count2.2、思路2.3、代码示例 三#xff1a;自定义COUNT查询SQL(只适用于单表)3.1、局限性…PageHelper自定义Count查询及其优化 文章目录 PageHelper自定义Count查询及其优化一背景1.1、解决方法 二利用反射判断请求参数是否有模糊查询2.1、分页不执行count2.2、思路2.3、代码示例 三自定义COUNT查询SQL(只适用于单表)3.1、局限性3.2、使用方式 四各种模糊查询XML中示例 一背景 PageHelper默认情况下会帮我们根据查询语句自动生成COUNT查询SQL但是有些情况下PageHelper自动生成COUNT查询SQL存在效率问题。比如其中使用了GROUP BY语句多表关联生成的COUNT查询SQL查询效率很慢 1.1、解决方法 1.count()有优化空间的直接优化Count执行条件慢无外乎索引是否命中执行SQL是否多表关联 2.count()没办法优化的只能从业务入手取消关联的一些条件查询 3.不返回count总条数只能一页一页往下翻 4.缓存总条数实时性保证不保证 5.异步查询加载前端后端一起优化 也就是点击一次请求查询两个接口list接口肯定很快返回可以直接进行列展示供用户操作查看等 count接口返回较慢分页插件下面展示loading提示正在加载异步执行完成后告诉前端6.彻底解决引入ES或其他数据库 7.代码层面投机取巧二利用反射判断请求参数是否有模糊查询 每次请求分页接口没有任何条件查询的时候count会计算总条数数据量大时非常耗时但是模糊查询的话速度还可以接受是否有一种方法可以如果只是有pageIndex和pageSize参数的时候我用自定义的count如果有其他模糊条件查询的时候我选择pageHelper自带的count执行原有复杂SQL语句维持count准确性二利用反射判断请求参数是否有模糊查询 2.1、分页不执行count PageHelper.startPage(req.getCurPage(), req.getPageSize(),false); 如果将此参数设置为falsepageHlper不执行count方法2.2、思路 1.只有分页参数--》不执行默认count方法设置为false--》自定义count--》返回自定义count总条数2.有模糊查询分页参数--》执行默认count方法设置为true--》pageHelper自带count--》count参数pageHelper会返回2.3、代码示例 // 定义一个私有静态列表来存储需要忽略的字段名称,填写当前类的字段private static final ListString IGNORED_FIELDS Arrays.asList(curPage, pageSize);//用作分页count选择,如果原始分页,选择全表差,反之用条件查public boolean areAllFieldsEmptyExceptIgnored() {//获取父类的字段//Field[] declaredFields this.getClass().getSuperclass().getDeclaredFields();//只获取了当前类的字段for (Field field : this.getClass().getDeclaredFields()) {// 忽略静态字段和transient字段if (java.lang.reflect.Modifier.isStatic(field.getModifiers()) ||java.lang.reflect.Modifier.isTransient(field.getModifiers())) {continue;}// 忽略配置列表中的字段if (IGNORED_FIELDS.contains(field.getName())) {continue;}// 确保私有字段也可以访问field.setAccessible(true);try {// 获取字段值Object value field.get(this);//检查字段值是否为空// 检查字段值是否为空if (value instanceof String ((String) value).isEmpty()) {//字段为空字符串这是允许的继续检查下一个字段continue;} else if (value instanceof String) {// 字段为非空字符串return false;} else if (value instanceof List ((List?) value).isEmpty()) {// 字段为非空列表这是允许的继续检查下一个字段continue;}else if (value instanceof List) {//字段为非空集合return false;} else if (value ! null) {//字段为非空对象return false;}} catch (IllegalAccessException e) {// 处理可能的非法访问异常throw new RuntimeException(Error accessing field: field.getName(), e);}}//所有字段都是空的return true;}这段反射说明如果只有分页参数会返回true如果有模糊查询参数会返回false需要忽略的字段支持自己设置 boolean status req.areAllFieldsEmptyExceptIgnored();PageHelper.startPage(req.getCurPage(), req.getPageSize(),!status);ListGoodsSpu resultList goodsSpuMapper.goodsSpuList(daoReq);PageInfoGoodsSpu pageInfo new PageInfo(resultList);if (status) {//count全查pageInfo.setTotal(goodsSpuMapper.goodsSpuListCount(daoReq));}else{//count条件查,走默认分页的count}select idgoodsSpuList parameterTypecom.kkd.goods.model.in.GoodsSpuListDaoReq resultTypecom.kkd.goods.entity.GoodsSpuselect DISTINCT r.id dis_id,r.* from(select gsp.* from gd_goods_spu gspLEFT JOIN gd_goods_sku gsk on gsp.spugsk.spuLEFT JOIN gd_goods_sku_upc gsu on gsp.spugsu.spuLEFT JOIN gd_goods_shop_category_relation gscr on gsp.spugscr.spuwheregsp.is_delete0and gsp.org_id#{orgId}if testname ! null and name ! and gsp.namelike concat(%,#{name},%)/ifif testspuList ! null and spuList.size 0AND gsp.spu INforeach itemid indexindex collectionspuList open( separator, close)#{id}/foreach/ifif testskuList ! null and skuList.size 0AND gsk.sku INforeach itemid indexindex collectionskuList open( separator, close)#{id}/foreach/ifif testupcList ! null and upcList.size 0AND gsu.upc INforeach itemid indexindex collectionupcList open( separator, close)#{id}/foreach/ifif testcategoryCodes ! null and categoryCodes.size 0AND gsp.category_code INforeach itemid indexindex collectioncategoryCodes open( separator, close)#{id}/foreach/ifif testshopCategoryIds ! null and shopCategoryIds.size 0AND gscr.shop_category_id INforeach itemid indexindex collectionshopCategoryIds open( separator, close)#{id}/foreach/ifif testePlatformCategoryId ! nulland gsp.e_platform_category_id#{ePlatformCategoryId}/ifif testisNormal ! nulland gsp.normal#{isNormal}/ifif testimageEmpty ! null and imageEmpty 1 and gsp.images is null/ifif testisMaster ! null and gsp.master #{isMaster}/ifif testmasterSpu ! null and masterSpu ! and gsp.master_spu #{masterSpu}/ifORDER BY gsp.update_time desc) r /selectselect idgoodsSpuListCount resultTypejava.lang.Long parameterTypecom.kkd.goods.model.in.GoodsSpuListDaoReqselect count(*) from gd_goods_spu gspwheregsp.is_delete0and gsp.org_id#{orgId} /select三自定义COUNT查询SQL(只适用于单表) 3.1、局限性 1.对于单表查询:分页执行的sql执行效率都慢count执行的时候首先考虑命中索引如果拆分出来效率能得到提升再用 2.对于多表查询如果查询条件仅仅只是主表中的条件此方法适用如果查询条件需要从表中的条件自定义的这个count就不满足 3.缓存count业务上总数实时性要求不高或者总数变化不快的情况下可以使用dependencygroupIdcom.github.pagehelper/groupIdartifactIdpagehelper/artifactIdversion5.0.4/version /dependency3.2、使用方式 原有的代码不需要动只需要在Mybatis的xml文件里添加一个count查询 这里注意以下三点即可 id和对应的查询语句保持一致并且以 _COUNT 结尾入参和对应的查询语句保持一致出参为 resultType“Long” select idgoodsSpuList_COUNT parameterTypecom.kkd.goods.model.in.GoodsSpuListDaoReq resultTypejava.lang.Longselect count(*)from gd_goods_spu gspwhere gsp.is_delete 0and gsp.org_id #{orgId} /select四各种模糊查询XML中示例 select idgoodsSpuList parameterTypecom.kkd.goods.model.in.GoodsSpuListDaoReq resultTypecom.kkd.goods.entity.GoodsSpuselect DISTINCT r.id dis_id,r.* from(select gsp.* from gd_goods_spu gspLEFT JOIN gd_goods_sku gsk on gsp.spugsk.spuLEFT JOIN gd_goods_sku_upc gsu on gsp.spugsu.spuLEFT JOIN gd_goods_shop_category_relation gscr on gsp.spugscr.spuwheregsp.is_delete0and gsp.org_id#{orgId}if testname ! null and name ! and gsp.namelike concat(%,#{name},%)/ifif testspuList ! null and spuList.size 0AND gsp.spu INforeach itemid indexindex collectionspuList open( separator, close)#{id}/foreach/ifif testskuList ! null and skuList.size 0AND gsk.sku INforeach itemid indexindex collectionskuList open( separator, close)#{id}/foreach/ifif testupcList ! null and upcList.size 0AND gsu.upc INforeach itemid indexindex collectionupcList open( separator, close)#{id}/foreach/ifif testcategoryCodes ! null and categoryCodes.size 0AND gsp.category_code INforeach itemid indexindex collectioncategoryCodes open( separator, close)#{id}/foreach/ifif testshopCategoryIds ! null and shopCategoryIds.size 0AND gscr.shop_category_id INforeach itemid indexindex collectionshopCategoryIds open( separator, close)#{id}/foreach/ifif testePlatformCategoryId ! nulland gsp.e_platform_category_id#{ePlatformCategoryId}/ifif testisNormal ! nulland gsp.normal#{isNormal}/ifif testimageEmpty ! null and imageEmpty 1 and gsp.images is null/ifif testisMaster ! null and gsp.master #{isMaster}/ifif testmasterSpu ! null and masterSpu ! and gsp.master_spu #{masterSpu}/ifORDER BY gsp.update_time desc) r/select参考Pagehelper自定义count查询
http://www.yingshimen.cn/news/116315/

相关文章:

  • 做网站的网站网站的建设分析及意义
  • 网站获取qq号码 代码校园网站的建设与管理
  • 网站添加搜索关键字资阳地seo
  • 学习php网站开发海报在线制作免费网站
  • 南京建设公司网站环保网站怎么做
  • app网站建设教程视频教程国外网站流量查询
  • 深圳手机模板建站建设优质网站需要什么
  • 做版面的网站网站建设新方向
  • 做高端品牌网站wordpress 分页静态
  • 免费seo网站网站制作的一般过程
  • 淮北建网站公司网站公司网站
  • 网站开发游戏程序开发知识付费网站源码
  • 网站云空间大小做seo_教你如何选择网站关键词
  • 长沙营销型网站制作wordpress 导航
  • 网站建设的步骤有哪些门户网站名词解释
  • 医疗网站备案要怎么做 需要准备什么材料做微商建自己的网站有用吗
  • 何炅做的代言网站鞍山做网站企业
  • 营销型网站开发网站建设的需求要素
  • 湖州营销网站建设网页设计心得体会600
  • 门户网站属于新媒体吗趣头条自媒体平台
  • weekly做网站适合做网站背景的图片
  • 各大电商购物网站转化率报表同城免费发布信息网
  • 房地产网站案例全栈工程师是做网站吗
  • 网站实时K线怎么做个人网站备案 照片
  • 网页界面设计教材seo专业术语
  • 营销型网站能解决什么问题网站如何生成app
  • 景安一个空间怎么做多个网站广告宣传费用一般多少
  • asp网站改php网站方法网站建设 网站优化营销型网站建设专家
  • 国外做化工产品的网站河北廊坊建设银行网站
  • 购买网站空间大小做网站好的书