zoukankan      html  css  js  c++  java
  • springboot 之拦截器

    1、建立拦截器

    2.实现拦截器(可实现权限拦截,操作日志)

    2.1 权限(当然接口权限关系表 要事先实现)

    2.2 日志

    附加部分代码:

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
    throws Exception {

      //获取项目动态绝对路径
      String path = request.getServletPath();

      if(!"/api/platform/location/insert".equalsIgnoreCase(path) && !path.contains("list")){
        //日志记录
        String param;
        //获得所有的参数名称
        Enumeration<String> em = request.getParameterNames();
        Map<String,Object> map = new HashMap<>();
        while (em.hasMoreElements()) {
        String name = em.nextElement();
        if(!"_".equals(name)){
          String value = request.getParameter(name);
          map.put(name, value);
        }

       }
      if(map.size() != 0){
        JSONObject json = JSONObject.fromObject(map);
        param = json.toString();
          }else{
        param= HttpHelper.getBodyString(request);
      }

      ManagerLoginLog log = new ManagerLoginLog();
      log.setCreateTime(utils.getNowTimeSecond());
      log.setManagerId(arr[0]);
      log.setIp(utils.getIPAddress(request));
      log.setMapper(path);
      log.setParam(param);
      managerLoginLogRepository.save(log);
    }

    }

  • 相关阅读:
    第三章-列表简介
    第二章—变量和简单数据类型
    CSS3转换
    maven项目报:An error occurred while filtering resources
    CSS基本知识和选择器
    Html
    算法(第四版)学习笔记(三)——归并排序
    算法学习笔记(二)——初级排序算法
    算法学习(一)——二分查找递归方法
    1003. 我要通过!(20)
  • 原文地址:https://www.cnblogs.com/haoxiu1004/p/11413494.html
Copyright © 2011-2022 走看看