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

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

异常管理

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>
http://www.jsqmd.com/news/50848/

相关文章:

  • 习题解析之:模拟生成微软序列号
  • 50046_基于微信小程序的电影票预订管理系统
  • Verilog位宽赋值规则
  • 云栖实录|驰骋在数据洪流上:Flink+Hologres驱动零跑科技实时计算的应用与实践 - 指南
  • 重练算法(代码随想录版) day21 - 二叉树part8
  • 第四十八篇
  • 2025年11月最新出炉!南京装修公司推荐首推欧阅恒装 TOP5权威榜单
  • 细微颗粒布满了整个房间 点燃通向毁灭实验的导线
  • 漏洞赏金猎人的深度侦察方法:内容发现进阶指南
  • 完整教程:【2025最全】国内AIPPT工具排行榜
  • i.MX 6ULL复位管脚
  • Django 用户认证流程详解:从原理到搭建
  • 棋盘 就是最简单的nim
  • [豪の算法奇妙冒险] 代码随想录算法训练营第六天 | 242-有效的字母异位词、349-两个数组的交集、202-快乐数、1-两数之和
  • 会不会是遗嘱呢……
  • 关于powershell中的-哈希表-Hashtable-类型-说明-类似于python中的字典
  • 2025 GEO优化公司排名权威榜单解读:浙江四家标杆企业凭何突围?
  • Mac Unity 2018.dmg游戏工具 安装步骤 简单易懂教程(附安装包)
  • [模拟赛]拆分(div)
  • 102302147傅乐宜作业3
  • 实用指南:苍穹外卖 —— 文件上传和菜品的CRUD
  • AI购物助手与编程新纪元:技术如何重塑生活与工作
  • 2025中小学生AI学习机选购核心:5大品牌实测,提分才是硬通货!
  • 深入解析:DNS解析原理及工作流程详解
  • 详细介绍:【微服务组件】Springboot结合Dubbo实现RPC调用
  • 6000 AI Program Topic 3~6
  • 伞兵天降 最小路径覆盖
  • Linux 通用软件包 AppImage 打包详解
  • 怎么理解np.array([10, 20]).reshape(-1, 1)?
  • 2025年11月机器人油脂公司推荐榜:五家优质企业深度对比与客观评价