SpringBoot+Shiro+LayUI权限管理系统项目-8.实现日志管理

1.说明

基于注解和AOP实现的日志管理。只讲解关键部分,详细看源码,文章下方捐赠或QQ联系捐赠获取。

2.功能展示

包括日志搜索、查看详情和批量删除。
在这里插入图片描述
在这里插入图片描述

3.业务模型

@Data
@TableName("sys_oper_log")
public class SysOperLog extends Model<SysOperLog> {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 操作模块
     */
    private String operModule;

    /**
     * 操作方法
     */
    private String operMethod;

    /**
     * 操作类型
     */
    private String operType;

    /**
     * 操作描述
     */
    private String operDesc;

    /**
     * 请求方法
     */
    private String reqMethod;

    /**
     * 请求参数
     */
    private String operParam;

    /**
     * 请求参数
     */
    private String operIp;

    /**
     * 请求uri
     */
    private String operUri;

    /**
     * 操作人
     */
    private String operUser;

    /**
     * 操作时间
     */
    private String createTime;


    @Override
    protected Serializable pkVal() {
        return this.id;
    }
}

4.控制器

@Controller
@RequestMapping("/operlog")
public class OperLogController {
    @Autowired
    private SysOperLogService logService;

    @GetMapping("listUI")
    public String listUI(){
        return "operlog/list";
    }

    /**
     *  分页查询
     * @param operDesc
     * @param pageNo
     * @param pageSize
     * @return
     */
    @PostMapping("/list")
    @ResponseBody
    public Result<IPage<SysOperLog>> list(@RequestParam(value = "operDesc", required = false) String operDesc,
                                          @RequestParam(defaultValue = "1") Integer pageNo,
                                          @RequestParam(defaultValue = "10") Integer pageSize){
        // 构造查询条件
        QueryWrapper<SysOperLog> queryWrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(operDesc)){
            queryWrapper.like("oper_desc",operDesc);
        }
        Page<SysOperLog> page = new Page<>(pageNo,pageSize);

        IPage<SysOperLog> result = logService.page(page, queryWrapper);
        // 设置总记录数
        result.setTotal(logService.count(queryWrapper));

        return ResultUtil.ok(result);
    }

    @PostMapping("/remove")
    @ResponseBody
    public Result<String> remove(@RequestParam Integer id){
        logService.removeById(id);

        return ResultUtil.ok("删除成功!");
    }

    @PostMapping("/removes")
    @ResponseBody
    public Result<String> removes(@RequestBody Integer[] ids){
        logService.removeByIds(Arrays.asList(ids));

        return ResultUtil.ok("删除成功!");
    }
}

5.前端页面

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<title>日志列表</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" th:href="@{/static/plugin/layui/css/layui.css}" media="all">
	<link rel="stylesheet" th:href="@{/static/css/app.css}" media="all">
</head>
<body>
<div class="searchTable">
	操作描述:
	<div class="layui-inline">
		<input class="layui-input" name="s_operDesc" id="s_operDesc" autocomplete="off">
	</div>
	<button id="searchBtn" class="layui-btn" data-type="reload">搜索</button>
</div>
<table class="layui-hide" id="tb_operlog" lay-filter="tb_operlog"></table>

<input type="text" id="ctx" hidden="hidden" th:value="${#request.getContextPath()}">

<!--详情页-->
<div class="layui-row" id="viewForm" style="display:none;">
	<div class="layui-col-md10">
		<form class="layui-form layui-from-pane" action="" style="margin-top:20px">
			<input type="text" id="id" name="id" hidden="hidden">
			<div class="layui-form-item">
				<label class="layui-form-label">操作模块</label>
				<div class="layui-input-block">
					<input type="text" id="operModule" name="operModule" required lay-verify="required" autocomplete="off"
						   placeholder="" class="layui-input" disabled>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">操作方法</label>
				<div class="layui-input-block">
					<textarea type="text" id="operMethod" name="operMethod" required lay-verify="required" autocomplete="off"
							  placeholder="" class="layui-textarea code-view" disabled></textarea>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">操作描述</label>
				<div class="layui-input-block">
					<input type="text" id="operDesc" name="operDesc" required lay-verify="required" autocomplete="off"
						   placeholder="" class="layui-input" disabled>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">操作类型</label>
				<div class="layui-input-block">
					<input type="text" id="operType" name="operType" required lay-verify="required" autocomplete="off"
						   placeholder="" class="layui-input" disabled>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">请求方式</label>
				<div class="layui-input-block">
					<input type="text" id="reqMethod" name="reqMethod" required lay-verify="required" autocomplete="off"
						   placeholder="" class="layui-input" disabled>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">请求参数</label>
				<div class="layui-input-block">
					<textarea type="text" id="operParam" name="operParam" required lay-verify="required" autocomplete="off"
							  placeholder="" class="layui-textarea code-view" disabled></textarea>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">请求IP</label>
				<div class="layui-input-block">
					<input type="text" id="operIp" name="operIp" required lay-verify="required" autocomplete="off"
						   placeholder="" class="layui-input" disabled>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">请求URI</label>
				<div class="layui-input-block">
					<input type="text" id="operUri" name="operUri" required lay-verify="required" autocomplete="off"
						   placeholder="" class="layui-input" disabled>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">操作人</label>
				<div class="layui-input-block">
					<input type="text" id="operUser" name="operUser" required lay-verify="required" autocomplete="off"
						   placeholder="" class="layui-input" disabled>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">操作时间</label>
				<div class="layui-input-block">
					<input type="text" id="createTime" name="createTime" required lay-verify="required" autocomplete="off"
						   placeholder="" class="layui-input" disabled>
				</div>
			</div>
			<!--<div class="layui-form-item" style="margin-top:40px">
				<div class="layui-input-block">
					<button type="button" class="layui-btn layui-btn-primary" id="back">关闭</button>
				</div>
			</div>-->
		</form>
	</div>
</div>

6 获取源码

捐赠任意金额,评论区留下邮箱发送 :)

在这里插入图片描述

posted @ 2021-04-21 09:43  一锤子技术员  阅读(13)  评论(0编辑  收藏  举报  来源