当前位置:   article > 正文

一个日志数据展示页面的整体逻辑梳理记录_系统日志特别多页面怎么展示

系统日志特别多页面怎么展示

1.导航栏添加新的页面标题,添加一个新建页面

在这里插入图片描述
利用标签的href属性定位到后端controller层
在这里插入图片描述
controller返回一个ModelAndView类型的视图,就是返回的前端设计新页面“log_login.jsp”;
一个初步的简单页面添加成功!

2.对新建的空白页面进行初始的设置,添加自己要展示的内容

在这里插入图片描述
简单截取一部分,之后前端的知识用到另外详细记录!
在这里插入图片描述
初始化方法,将页面初始化,再对应另外的方法分别书写点击各个按钮所对应的功能。

3.后端对应数据库数据的填充!

@RequestMapping("/loginLog")
    public ModelAndView getLoginLog(Integer pageSize, Integer currentPage, String uname, String ip, Integer type, String loginDateBegin,String loginDateEnd){
        ModelAndView modelAndView = new ModelAndView("log_login");
        if (pageSize==null||pageSize<=0){
            pageSize = 10;
        }
        if (currentPage==null||currentPage<=0){
            currentPage = 1;
        }
        if(type!=null && type.equals(0)){
            //当code传过来是"0",则表示全部,则查询时不带如code的值
            type = null;
        }
        if (uname!=null && !uname.equals("")){
            uname = URLDecoder.decode(uname);
        }
        if (ip!=null && !ip.equals("")){
            ip = URLDecoder.decode(ip);
        }
        AdminLoginLogEntity loginLog = new AdminLoginLogEntity();
        loginLog.setUName(uname);
        loginLog.setLoginType(type);
        loginLog.setIp(ip);
        loginLog.setLoginDateBegin(loginDateBegin);
        loginLog.setLoginDateEnd(loginDateEnd);
        //查询数据库
        PageInfo<AdminLoginLogEntity> queryResult = adminLoginLogService.getRecordByPage(pageSize,currentPage,loginLog);
        modelAndView.addObject("dataList",queryResult.getList());
        modelAndView.addObject("dataTotal",queryResult.getTotal());
        modelAndView.addObject("currentPage",currentPage);
        modelAndView.addObject("pageSize",pageSize);
        modelAndView.addObject("type",type);
        modelAndView.addObject("uname",uname );
        modelAndView.addObject("ip",ip);
        modelAndView.addObject("loginDateBegin",loginDateBegin);
        modelAndView.addObject("loginDateEnd",loginDateEnd);
        modelAndView.addObject("barItem",6);
        return modelAndView;
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39

在controller的方法中直接传入前端需要输入查询的参数,在刚开始进入的初始化页面没有传参,对其进行未输入内容的判断通过URLDecoder.decode解码,这样可以保证得到原始数值,不会报错。在后续数据库查询时便没有条件限制,会得到全部的日志记录信息返回给下面定义的PageInfo集合queryResult。
接下来定义一个登录日志实体类的对象,用传入参数将其实例化,传入数据库查询方法;

PageInfo<AdminLoginLogEntity> queryResult = adminLoginLogService.getRecordByPage(pageSize,currentPage,loginLog);
  • 1
 @Override
    public PageInfo<AdminLoginLogEntity> getRecordByPage(Integer pageSize, Integer currentPage, AdminLoginLogEntity loginLog) {
        List<AdminLoginLogEntity> list = null;
        try {
            //利用PageHelper分页查询 注意:这个一定要放查询语句的前一行,否则无法进行分页,因为它对紧随其后第一个sql语句有效
            PageHelper.startPage(currentPage,pageSize);
            list = adminLoginLogDao.getRecordByPage(loginLog);
        }catch (Exception e){
            e.printStackTrace();
            logger.error("AdminLoginLogServiceImpl-getRecordByPage:数据库获取最新的测试连接性数据出错!"+e.getMessage());
        }
        PageInfo<AdminLoginLogEntity> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

自此,dao调用mapper.xml中数据库查询方法得到一个完整地带有分页的集合。

 <select id="getRecordByPage" parameterType="cn.****.****.entity.AdminLoginLogEntity" resultType="AdminLoginLogEntity">
        SELECT t1.uName,t1.loginType,t1.ip,t1.loginTime FROM login_log t1
        <where>
            <if test="uName!= null and uName!=''">
                and t1.uName like "%"#{uName}"%"
            </if>
            <!--模糊查询第二种书写方式 -->
            <if test="ip!=null and ip!=''">
                and t1.ip like "%"#{ip}"%"
            </if>
            <if test="loginType!=null and loginType!=0">
                and t1.loginType = #{loginType}
            </if>
            <if test="loginDateBegin!=null">
                and t1.loginTime >= #{loginDateBegin}
            </if>
            <if test="loginDateEnd!=null">
                and #{loginDateEnd} >= t1.loginTime
            </if>
        </where>
    </select>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

然后回到controller的最后,对要返回的modleAndView进行设置,将得到的集合一并返回展示给页面!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/587573
推荐阅读
相关标签
  

闽ICP备14008679号