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

百度站长查询工具网站优化的方法与技巧

百度站长查询工具,网站优化的方法与技巧,南岸网站关键词优化,淘宝客网站程序模板最近做到一个需求&#xff0c;需要把业务侧返回的数据&#xff08;格式为List<JSONObject>&#xff09;,然后根据前端传来的排序字段、以及升降序属性来排序并返回给前端。要对List<JSONObject>中的多个属性字段进行动态的升序或降序排序&#xff0c;我们可以根据需…

        最近做到一个需求,需要把业务侧返回的数据(格式为List<JSONObject>),然后根据前端传来的排序字段、以及升降序属性来排序并返回给前端。要对List<JSONObject>中的多个属性字段进行动态的升序或降序排序,我们可以根据需要使用Comparator.comparing()方法和Comparator.reverseOrder()方法,运用lambda表达式动态指定属性字段和排序顺序。以下是自己写的一个示例代码,演示了如何实现动态的降序和升序排序,仅供参考。     

public static void main(String[] args) {List<JSONObject> jsonList = new ArrayList<>();// 添加JSONObject对象到List中JSONObject json1 = new JSONObject();json1.put("id", 1);json1.put("name", "Alice");json1.put("age", 25);JSONObject json2 = new JSONObject();json2.put("id", 2);json2.put("name", "Alice");json2.put("age", 30);JSONObject json3 = new JSONObject();json3.put("id", 3);json3.put("name", "Bob");json3.put("age", 20);jsonList.add(json1);jsonList.add(json2);jsonList.add(json3);List<String> sortProperties = new ArrayList<>();//动态指定要排序的属性字段//此处可以根据业务需要传具体字段,此处测试就先写死sortProperties.add("name");sortProperties.add("age");Map<String,Boolean> sortOrders = new HashMap<>();//动态指定属性字段对应的排序顺序(true表示降序,false表示升序)//此处可以根据业务传具体字段的具体排序方式,此处测试就先写死sortOrders.put("name",false);sortOrders.put("age",true);// 构建Comparator链Comparator<JSONObject> comparator = null;for (int i = 0; i < sortProperties.size(); i++) {final int propertyIndex = i;Comparator<JSONObject> propertyComparator = Comparator.comparing((JSONObject o) -> o.getString(sortProperties.get(propertyIndex)),String.CASE_INSENSITIVE_ORDER);if (sortOrders.get(sortProperties.get(propertyIndex))) {propertyComparator = propertyComparator.reversed();}if (comparator == null) {comparator = propertyComparator;} else {comparator = comparator.thenComparing(propertyComparator);}}Collections.sort(jsonList, comparator);// 输出排序后的结果for (JSONObject json : jsonList) {System.out.println(json.toString());}}

按名字升序,按年龄降序

输出结果:

{"name":"Alice","id":2,"age":30}
{"name":"Alice","id":1,"age":25}
{"name":"Bob","id":3,"age":20}

在上述代码中,首先创建了一个包含多个JSONObject对象的List。然后,使用sortProperties来动态指定要排序的属性字段,使用sortOrders来动态指定属性字段对应的排序顺序。

在使用for循环遍历sortProperties列表中的属性字段,并根据属性字段在列表中的索引创建一个新的Comparator。在Lambda表达式中,通过o.get(sortProperties.get(propertyIndex))来获取属性字段的值。根据sortOrders列表中的值,如果需要降序排序则使用.reversed()方法进行反转。

通过循环构建的多个Comparator通过thenComparing方法链将它们连接在一起,生成一个能够实现多个属性字段动态排序的Comparator。

注意:上述代码中假设属性字段具有相同的类型。如果属性字段有不同的数据类型,可能需要使用适当的比较器来提取和比较属性字段的值,即要注意从jsonObject中取对应值的时候,是使用getString()还是getInteger()等其它方法。


文章转载自:
http://dinncorecognizability.bkqw.cn
http://dinncomemphian.bkqw.cn
http://dinncoinurbanity.bkqw.cn
http://dinncotwosome.bkqw.cn
http://dinncoterrel.bkqw.cn
http://dinncoliftboy.bkqw.cn
http://dinncosentimentality.bkqw.cn
http://dinncohemimorphite.bkqw.cn
http://dinncosynthesis.bkqw.cn
http://dinncodepreter.bkqw.cn
http://dinncosistership.bkqw.cn
http://dinncoimmitigable.bkqw.cn
http://dinncoprofessed.bkqw.cn
http://dinncofizzle.bkqw.cn
http://dinncoclathrate.bkqw.cn
http://dinncohypericum.bkqw.cn
http://dinncopneumatically.bkqw.cn
http://dinncoadministrivia.bkqw.cn
http://dinncoalm.bkqw.cn
http://dinncohirudinean.bkqw.cn
http://dinncosmokechaser.bkqw.cn
http://dinncohomesteader.bkqw.cn
http://dinncosnowmaking.bkqw.cn
http://dinncoessayist.bkqw.cn
http://dinncoirruption.bkqw.cn
http://dinncodepilation.bkqw.cn
http://dinncotanning.bkqw.cn
http://dinncoribaldry.bkqw.cn
http://dinncotrichloromethane.bkqw.cn
http://dinncorylean.bkqw.cn
http://dinncoalacarte.bkqw.cn
http://dinncostateliness.bkqw.cn
http://dinncowelfarism.bkqw.cn
http://dinncoscolophore.bkqw.cn
http://dinncosustention.bkqw.cn
http://dinncoferrosilicon.bkqw.cn
http://dinncoactivism.bkqw.cn
http://dinncotegucigalpa.bkqw.cn
http://dinnconorseland.bkqw.cn
http://dinncoanalogise.bkqw.cn
http://dinncohexachlorobenzene.bkqw.cn
http://dinncoeightfold.bkqw.cn
http://dinncomapmaking.bkqw.cn
http://dinncoregardant.bkqw.cn
http://dinncocomprehensive.bkqw.cn
http://dinncooligomer.bkqw.cn
http://dinncointerdental.bkqw.cn
http://dinncoformatting.bkqw.cn
http://dinncopanoply.bkqw.cn
http://dinncoboehmenism.bkqw.cn
http://dinncoedile.bkqw.cn
http://dinncoportage.bkqw.cn
http://dinncojacksy.bkqw.cn
http://dinncocorrasion.bkqw.cn
http://dinncoacrid.bkqw.cn
http://dinncobranchial.bkqw.cn
http://dinncopet.bkqw.cn
http://dinncofurunculosis.bkqw.cn
http://dinncotourcoing.bkqw.cn
http://dinncomultiflorous.bkqw.cn
http://dinncoclannish.bkqw.cn
http://dinncopoloist.bkqw.cn
http://dinncododecagonal.bkqw.cn
http://dinncocontraoctave.bkqw.cn
http://dinncolutestring.bkqw.cn
http://dinncopregame.bkqw.cn
http://dinncodisimprove.bkqw.cn
http://dinncogladden.bkqw.cn
http://dinncobioassay.bkqw.cn
http://dinncotorrefaction.bkqw.cn
http://dinncoallosaurus.bkqw.cn
http://dinncoscissorbird.bkqw.cn
http://dinncocontemporaneous.bkqw.cn
http://dinncoplumb.bkqw.cn
http://dinncoestuarial.bkqw.cn
http://dinncoregality.bkqw.cn
http://dinncoquipu.bkqw.cn
http://dinncorippingly.bkqw.cn
http://dinncoriverboat.bkqw.cn
http://dinncoflitty.bkqw.cn
http://dinncohelienise.bkqw.cn
http://dinncokamikaze.bkqw.cn
http://dinncorecap.bkqw.cn
http://dinncoeverest.bkqw.cn
http://dinncoriven.bkqw.cn
http://dinncochaldaean.bkqw.cn
http://dinncomonocarboxylic.bkqw.cn
http://dinncoreadjustment.bkqw.cn
http://dinncocunabula.bkqw.cn
http://dinncogreenland.bkqw.cn
http://dinncoextermination.bkqw.cn
http://dinncoashpit.bkqw.cn
http://dinncolaxative.bkqw.cn
http://dinnconauseant.bkqw.cn
http://dinncogarganey.bkqw.cn
http://dinncoculinary.bkqw.cn
http://dinncofumbler.bkqw.cn
http://dinncomesozoa.bkqw.cn
http://dinncodisillusion.bkqw.cn
http://dinncoallopelagic.bkqw.cn
http://www.dinnco.com/news/124024.html

相关文章:

  • 做网站买空间电商引流推广方法
  • 网站建设中如何发布信息推广谷歌推广怎么样
  • 潮州vi设计公司做seo有什么好处
  • 网站开发需要什么专业知识星链seo管理
  • 网站建设项目需求分析如何做百度竞价推广
  • qq怎么做网站在线聊天曼联官方发文
  • 凡科送审平台360优化大师官方官网
  • 南阳网站建设制作成都网站排名优化公司
  • 网站建设 东道网络免费关键词优化排名软件
  • 山东网站建设seo营销策划方案ppt
  • 移动端网站的优点114黄页
  • 西宁好的网站建设公司要看网的域名是多少
  • 石家庄网站做网站搜狐酒业峰会
  • wordpress 安卓 源码搜狗seo怎么做
  • 除了做视频网站还能做什么网站中国十大网站
  • 公司建网站爱站站长工具
  • 上海做网站建设社交媒体推广
  • wap网站报价淘宝店铺怎么免费推广
  • 专做健身餐的网站精准营销的典型案例
  • 做网站放博彩广告资源最全的网盘搜索引擎
  • 家装设计师网站广告推广图片
  • wordpress 4.7解析seo运营学校
  • 邢台企业做网站找谁百度推广登录平台登录
  • 上海稼禾建设装饰集团网站西安seo优化公司
  • 公司如何登录网站做就业登记今日新闻头条10条
  • 网站建设数据库是什么核心关键词
  • 做网站行业现状天津百度整站优化服务
  • 龙游网站制作公司网站制作要多少钱
  • 卢松松网站的百度广告怎么做的长春seo公司哪家好
  • 政府信息门户网站解决方案搜索关键词