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

之梦做的网站后台修改栏目描述石家庄关键词排名提升

之梦做的网站后台修改栏目描述,石家庄关键词排名提升,网站建设用语,建站平台上建设的网站可以融资吗需求&#xff1a;&#xff1a; 有一个List<Map<String.Object>>,存储了某年某月的数据&#xff0c; 数据是根据用户查询条件进行显示的&#xff1b;所以查询的数据是动态的&#xff1b;需按月份统计每个年月数据出现的次数&#xff0c;并且按照月份排序&#xff1…

需求:

  1. 有一个List<Map<String.Object>>,存储了某年某月的数据,
    数据是根据用户查询条件进行显示的;所以查询的数据是动态的;
  2. 需按月份统计每个年月数据出现的次数,并且按照月份排序;
  3. 统计周期不超过一年(前端页面控制);

分析:
后端给前端返回值:不能用对象返回,因为数据是动态的,key是不固定的;
可以使用:List<Map<String,Object>>返回;Map中key为年月;value为统计次数;

Demo案例:


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;public class day06 {public static void main(String[] args) {List<Map<String,Object>> list = new ArrayList<>();Map<String,Object> map1 = new HashMap<>();map1.put("month","2023年02月");Map<String,Object> map2 = new HashMap<>();map2.put("month","2023年05月");Map<String,Object> map3 = new HashMap<>();map3.put("month","2023年04月");Map<String,Object> map4 = new HashMap<>();map4.put("month","2023年02月");Map<String,Object> map5 = new HashMap<>();map5.put("month","2023年01月");list.add(map1);list.add(map2);list.add(map3);list.add(map4);list.add(map5);String[] auditMonthArr = {"01","02","03","04","05","06","07","08","09","10","11","12"};int[] count = new int[auditMonthArr.length];String[] yearArr = new String[auditMonthArr.length];for (int i = 0; i < list.size(); i++) {String auditMonth = String.valueOf(list.get(i).get("month")).trim();String auditMonth2 = auditMonth.substring(auditMonth.indexOf("年")+1,auditMonth.indexOf("月"));for (int j = 0; j < auditMonthArr.length; j++) {if(auditMonth2.equals(auditMonthArr[j].trim())){count[j] = count[j] + 1;yearArr[j] = auditMonth;}}}List<Map<String,Object>> listResult = new ArrayList<>();// 按照1月到12月动态展示数据;for (int i = 0; i < auditMonthArr.length; i++) {Map<String,Object> map = new HashMap<>();String title = yearArr[i];int value = count[i];if(!String.valueOf(value).equals("0")){map.put("title",title);map.put("value",value);listResult.add(map);}}	for (int i = 0; i < listResult.size(); i++) {listResult.get(i).put("sortValue",i+1);}System.out.println("listResult:"+listResult);}
}

测试输出:

listResult:
listResult:[{sortValue=1, title=202301, value=1}, {sortValue=2, title=202302, value=2}, {sortValue=3, title=202304, value=1}, {sortValue=4, title=202305, value=1}]

案例二:
需求:前端根据后端的返回数据:画趋势图;

  1. X轴是动态的,有对应月份数据则展示;
  2. X轴 按照1-12月排序(没月份则跳过);
    在这里插入图片描述
// Controllerpublic Result getTrendData(HttpServletRequest request,@RequestBody String param) {try {Map<String, Object> paramMap = JsonUtils.readValue(param, Map.class);return Result.success().result(questionListService.getTrendData(request,paramMap));} catch (Exception e) {log.error("QuestionListController getTrendData is error===:" + e.getMessage(), e);return Result.failure("统计失败");}}// Service    List<Map<String,Object>> getTrendData(HttpServletRequest request,Map<String, Object> paramMap);// ServiceImpl  @Overridepublic List<Map<String,Object>> getTrendData(HttpServletRequest request, Map<String, Object> paramMap) {List<Map<String,Object>> list = getCountData(request,paramMap); // 封装统计查询的数据(与数据库交互)List<Map<String,Object>> listResult = new ArrayList<>();String[] auditMonthArr = {"01","02","03","04","05","06","07","08","09","10","11","12"};int[] monDataArr = new int[auditMonthArr.length];String[] yearArr = new String[auditMonthArr.length];for (int i = 0; i < list.size(); i++) {String auditMonth = String.valueOf(list.get(i).get("auditMonth"));String mon = auditMonth.substring(auditMonth.indexOf("年")+1,auditMonth.lastIndexOf("月"));for (int j = 0; j < auditMonthArr.length; j++) {if(mon.equals(auditMonthArr[j])){monDataArr[j] = monDataArr[j] + 1;yearArr[j] = auditMonth;}}}// 按照1月到12月动态展示数据;for (int i = 0; i < auditMonthArr.length; i++) {Map<String,Object> map = new HashMap<>();String title = yearArr[i];int value = monDataArr[i];// 该判断很重要(仔细品)if(!String.valueOf(value).equals("0")){map.put("title",title);map.put("value",value);listResult.add(map);}}return listResult;}

Postman接口测试:

在这里插入图片描述

http://www.hkea.cn/news/839587/

相关文章:

  • 新手制作网站工具bt磁力猪
  • 怎么做网站系统深圳头条新闻
  • 北京网站设计公司新鸿儒seo公司的选上海百首网络
  • 百姓网二手拖拉机百度seo优化排名客服电话
  • 北京南站是丰台站吗seo优化什么意思
  • 外贸营销型建站关键词全网搜索工具
  • 有什么网站可以做扣扣头像腾讯企点app下载安装
  • 网站设计怎么做链接拉新推广怎么快速拉人
  • 怎么自己做礼品网站补肾壮阳吃什么药效果好
  • 网站用户建设的设计与实现网站推广营销运营方式
  • html5韩国网站模板seo网站优化培训班
  • 网站被iframe信息推广的方式有哪些
  • 通信技术公司网站建设app推广代理
  • 做电影网站会违法吗营销说白了就是干什么的
  • 用外链技术做视频网站关键词在线听免费
  • 做网站常用的css最近三天的新闻热点
  • 全国人大常委会副委员长登封seo公司
  • 顶岗实践网站开发推广管理
  • 九号公司网站优化效果
  • 模板网站建设方案北京seo排名收费
  • 做箱包关注哪个网站泰州seo平台
  • 如何给网站做流量站长工具seo
  • 桂林网站开发建设推广任务接单平台
  • 化妆品 网站建设案例seo超级外链工具免费
  • 网站建设的广告语seo自动工具
  • 有专门做市场分析的网站么太原关键词优化报价
  • 网站文化建设搜索引擎推广的常见形式有
  • wordpress分类目录消失泸州网站seo
  • 易云巢做网站公司seo入门到精通
  • 新津网站建设百度ai助手入口