From af65bfedf6f756811b14a08e350e2be1c7f4a32c Mon Sep 17 00:00:00 2001 From: xzy <2737577908@qq.com> Date: Sat, 21 Dec 2024 17:36:30 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=8E=A7=E5=88=B6=E5=99=A8?= =?UTF-8?q?=E5=8F=8A=E5=85=B6=E7=99=BB=E5=BD=95=E6=95=B0=E6=8D=AE=E4=BC=A0?= =?UTF-8?q?=E8=BE=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/api/controller/LogController.java | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 IDEA/src/main/java/com/example/api/controller/LogController.java diff --git a/IDEA/src/main/java/com/example/api/controller/LogController.java b/IDEA/src/main/java/com/example/api/controller/LogController.java new file mode 100644 index 00000000..7ce6c242 --- /dev/null +++ b/IDEA/src/main/java/com/example/api/controller/LogController.java @@ -0,0 +1,77 @@ +package com.example.api.controller; + +// 导入登录日志实体类 +import com.example.api.model.entity.LoginLog; +// 导入系统日志实体类 +import com.example.api.model.entity.SystemLog; +// 导入响应结果类,用于统一返回格式 +import com.example.api.model.support.ResponseResult; +// 导入系统日志视图对象,用于查询系统日志 +import com.example.api.model.vo.SystemLogVo; +// 导入登录日志服务接口 +import com.example.api.service.LoginLogService; +// 导入系统日志服务接口 +import com.example.api.service.SystemLogService; +// 导入Spring框架的注解支持 +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +// 导入Java的util包,用于操作集合 +import java.util.List; +// 导入Java的Map接口,用于操作键值对集合 +import java.util.Map; + +// 使用RestController注解声明这是一个REST控制器 +@RestController +// 使用RequestMapping注解指定这个控制器的基础URL路径 +@RequestMapping("/api") +public class LogController { + // 使用@Autowired注解注入LoginLogService + @Autowired + private LoginLogService loginLogService; + + // 使用@Autowired注解注入SystemLogService + @Autowired + private SystemLogService systemLogService; + + // 使用GetMapping注解定义一个GET请求的处理器,用于获取所有登录日志 + @GetMapping("/loginlog") + public List getLoginLog(){ + // 调用loginLogService的getAll方法获取所有登录日志 + List all = loginLogService.getAll(); + return all; + } + + // 使用DeleteMapping注解定义一个DELETE请求的处理器,用于删除指定ID的登录日志 + @DeleteMapping("/loginlog") + public void delLoginLog(String id){ + // 调用loginLogService的delLoginLog方法删除指定ID的登录日志 + loginLogService.delLoginLog(id); + } + + // 使用GetMapping注解定义一个GET请求的处理器,用于获取所有系统日志 + @GetMapping("/systemlog") + public List getSystemLog(){ + // 直接返回systemLogService的getAll方法获取的所有系统日志 + return systemLogService.getAll(); + } + + // 使用DeleteMapping注解定义一个DELETE请求的处理器,用于删除指定ID的系统日志 + @DeleteMapping("/systemlog") + public void deleteSystemLogById(String id){ + // 调用systemLogService的delete方法删除指定ID的系统日志 + systemLogService.delete(id); + } + + // 使用GetMapping注解定义一个GET请求的处理器,用于根据条件查询系统日志 + @GetMapping("/querySystemlog") + public List querySystemlog(SystemLogVo systemLogVo){ + // 打印传入的系统日志视图对象 + System.out.println(systemLogVo); + // 调用systemLogService的query方法根据条件查询系统日志 + return systemLogService.query(systemLogVo); + } +} \ No newline at end of file