当前位置: 首页 > 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.rkmt.cn/news/60727.html

相关文章:

  • 日总结 31
  • 102302114_比山布努尔兰_作业3
  • 第四十八篇
  • Django 用户认证流程详解:从原理到搭建
  • i.MX 6ULL复位管脚
  • [豪の算法奇妙冒险] 代码随想录算法训练营第六天 | 242-有效的字母异位词、349-两个数组的交集、202-快乐数、1-两数之和
  • 棋盘 就是最简单的nim
  • 会不会是遗嘱呢……
  • [模拟赛]拆分(div)
  • 详细介绍:【微服务组件】Springboot结合Dubbo实现RPC调用
  • 怎么理解np.array([10, 20]).reshape(-1, 1)?
  • 深入解析:网络安全等级保护测评高风险判定实施指引(试行)--2020与2025版对比
  • AI学习机值不值?2025年实测最有用的AI学习机品牌推荐!
  • 2025年11月机器人油脂公司推荐榜:精选五家优质供应商对比分析
  • hikivision 考勤机数据提取
  • [python] Python数据类使用指北
  • 深入解析:iOS 26 App 开发阶段性能优化 从多工具协作到数据驱动的实战体系
  • 小程序开发使用vant ui 组件快速开发
  • 课后作业8
  • 2025年11月25日加班
  • 租房买房必看1为什么户型不方正,会让你越住越穷?
  • 实用指南:Stable Diffusion 短视频制作算力需求与优化策略研究
  • 如何高效地学习Java编程?
  • 实用指南:【底层机制】深入浅出地、系统地剖析 Appium 的原理
  • 容错量子电路大幅降低资源开销
  • 详细介绍:【C基本功】类型转换的奇幻漂流
  • 点灯笔记:CW32L010
  • 过山车
  • day07 spark sql - 详解
  • 深入解析:系统架构设计师备考第57天——云原生架构相关技术