尧图网站建设 尧图网络
  • 首页
  • 关于我们
  • 服务项目
  • 案例展示
  • 建站流程
  • 资讯中心
  • 联系我们
首页/资讯中心/详情

Day48(18)-F:\硕士阶段\Java\课程代码\后端\web-ai-code\web-ai-project02\tlias-web-management

Day48(18)-F:\硕士阶段\Java\课程代码\后端\web-ai-code\web-ai-project02\tlias-web-management
📅 发布时间:2026/6/19 21:02:52

异常管理

image-20251125124023856

image-20251125124254183

package com.itheima.exception;import com.itheima.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;/*** 全局异常处理器*/@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {@ExceptionHandlerpublic Result handleException(Exception e){log.error("程序出错啦:",e);return Result.error("出错啦,请联系管理员");}@ExceptionHandlerpublic Result handleDuplicateKeyException(DuplicateKeyException e){log.error("程序出错啦:",e);String message = e.getMessage();int i = message.indexOf("Duplicate entry");String errMsg = message.substring(i);//Duplicate entry '18809091212' for key 'emp.phone'String[] arr = errMsg.split(" ");return Result.error(arr[2]+"已存在");}
}

@ResponseBody将方法的返回值响应给前端,如果方法的返回值是集合或对象,那么会讲方法的返回值先转换为json再响应

image-20251125132103316

信息统计

图形报表插件echarts

image-20251125134506905

-- 统计每一种职位对应的人数
-- case函数:case表达式 when val1 then res1 when val2 then res2 ... else...end
select(case jobwhen 1 then '班主任'when 2 then '讲师'when 3 then '学工主管'when 4 then '教研主管'when 5 then '咨询师'else '其他' end) pos,count(*) num
from emp group by job order by num;select(case  when job=1 then '班主任'when job=2 then '讲师'when job=3 then '学工主管'when job=4 then '教研主管'when job=5 then '咨询师'else '其他' end) pos,count(*) num
from emp group by job order by num;9
package com.itheima.controller;import com.itheima.pojo.JobOption;
import com.itheima.pojo.Result;
import com.itheima.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@Slf4j
@RestController
@RequestMapping("/report")
public class ReportController {@Autowiredprivate ReportService reportService;@GetMapping("/empJobData")public Result getEmpJobData(){log.info("统计员工职位人数");com.itheima.pojo.JobOption jobOption = reportService.getEmpJobData();return Result.success(jobOption);}
}
package com.itheima.service.impl;import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.JobOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.List;
import java.util.Map;@Service
public class ReportServiceImpl implements ReportService {@Autowiredprivate EmpMapper empMapper;/*** 统计员工职位人数*/@Overridepublic JobOption getEmpJobData() {//1. 掉用mapper接口,获取统计数据List<Map<String, Object>> list = empMapper.countEmpJobData();//map: pos=教研主管,num=1//2.组装结果,并返回List<Object> jobList = list.stream().map(dataMap -> {return dataMap.get("pos");}).toList();List<Object> dataList = list.stream().map(dataMap -> dataMap.get("num")).toList();return new JobOption(jobList,dataList);}
}
/*** 统计员工职位人数* @return*/
List<Map<String, Object>> countEmpJobData();
<!--    统计员工职位人数--><select id="countEmpJobData" resultType="java.util.Map">select(case  when job=1 then '班主任'when job=2 then '讲师'when job=3 then '学工主管'when job=4 then '教研主管'when job=5 then '咨询师'else '其他' end) pos,count(*) numfrom emp group by job order by num;</select>

image-20251125152407378

image-20251125152448821

image-20251125152838457

package com.itheima.controller;import com.itheima.pojo.GenderOption;
import com.itheima.pojo.JobOption;
import com.itheima.pojo.Result;
import com.itheima.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.List;
import java.util.Map;@Slf4j
@RestController
@RequestMapping("/report")
public class ReportController {@Autowiredprivate ReportService reportService;@GetMapping("/empJobData")public Result getEmpJobData(){log.info("统计员工职位人数");com.itheima.pojo.JobOption jobOption = reportService.getEmpJobData();return Result.success(jobOption);}/*** 统计员工性别人数* @return*/@GetMapping("/empGenderData")public Result getEmpGenderData(){log.info("统计员工性别人数");//GenderOption genderOption = reportService.getEmpGenderData();List<Map<String,Object>> genderList = reportService.getEmpGenderData();//return Result.success(genderOption);return Result.success(genderList);}
}
package com.itheima.service.impl;import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.GenderOption;
import com.itheima.pojo.JobOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.List;
import java.util.Map;@Service
public class ReportServiceImpl implements ReportService {@Autowiredprivate EmpMapper empMapper;/*** 统计员工职位人数*/@Overridepublic JobOption getEmpJobData() {//1. 掉用mapper接口,获取统计数据List<Map<String, Object>> list = empMapper.countEmpJobData();//map: pos=教研主管,num=1//2.组装结果,并返回List<Object> jobList = list.stream().map(dataMap -> {return dataMap.get("pos");}).toList();List<Object> dataList = list.stream().map(dataMap -> dataMap.get("num")).toList();return new JobOption(jobList,dataList);}@Override//public GenderOption getEmpGenderData() {public List<Map<String,Object>> getEmpGenderData() {//List<Map<String, Object>> list = empMapper.countEmpGenderData();
//        List<Object> name = list.stream().map(dataMap -> dataMap.get("name")).toList();
//        List<Object> value = list.stream().map(dataMap -> dataMap.get("value")).toList();//return new GenderOption(name,value);//return list;//简化return empMapper.countEmpGenderData();}
}
<!--    统计员工性别人数--><select id="countEmpGenderData" resultType="java.util.Map">selectif(gender=1,'男性员工','女性员工') name,count(*) valuefrom emp group by gender;</select>

相关新闻

  • 日总结 31
  • 102302114_比山布努尔兰_作业3
  • 第四十八篇

最新新闻

  • 深入解析MCF5206嵌入式SoC:指令缓存与系统集成模块实战配置
  • 6/18
  • MPC555/556中断处理与代码压缩技术深度解析
  • 10分钟搞定黑苹果:OpCore-Simplify让OpenCore配置变得前所未有的简单
  • 显存不够用怎么办,vLLM 在 Instinct GPU 上的优化策略
  • 2026年全球高标准流体项目选型指南:主流自控阀门厂家技术盘点与多维工况实测 - 热点观察

日新闻

  • 5分钟掌握Python进化算法:Geatpy高性能优化工具完全指南
  • Microchip 24AA044 EEPROM选型与应用全指南:从参数解析到实战编程
  • 华为的鸿蒙到底有多牛?为什么称作遥遥领先?

周新闻

  • 3步解锁iOS设备:applera1n激活锁绕过完全指南
  • 39 2026 人工智能证书终极盘点,普通人选 AI 证书可以从这些方向入手
  • Redis 暴露公网有多危险?从端口检查到补救步骤

月新闻

  • 【总结】入门篇:50句话让你记住架构核心概念
  • WeChatMsg技术方案解析:实现Mac微信数据自主管理的完整解决方案
  • WeChatMsg:革新性微信数据备份方案,打造你的专属数字记忆库

关于尧图

  • 公司简介
  • 团队介绍
  • 企业文化
  • 荣誉资质

服务项目

  • 定制开发
  • 电商建站
  • UI 设计
  • 运维服务

快速链接

  • 案例展示
  • 建站流程
  • 常见问题
  • 资讯中心

联系方式

  • 📍北京市朝阳区互联网产业园 A 座 10 层
  • 📞400-888-8888
  • ✉️contact@rkmt.cn
  • 🕐周一至周日 9:00-21:00

© 2024 北京尧图网络科技有限公司 版权所有 | 京 ICP 备 XXXXXXXX 号