• Springboot中spring-data-jpa实现拦截器


    以下是jpa 拦截器的配置。

    第一步: 实现 hibernate接口。重写方法

    public class JpaInterceptor implements  StatementInspector {
        @Override
        public String inspect(String sql) {
            System.out.println("进入拦截器" + sql);
            sql+= " and 1=1";
            return sql;
        }
    }
    

    第二步: 在yml中配置

    spring:
      jpa:
        properties:
          hibernate:
            session_factory:
              statement_inspector: com.bdyh.system.config.jpa.JpaInterceptor  

    第三步:结果

    2019-06-19 17:19:08,615 - HHH000397: Using ASTQueryTranslatorFactory
    进入拦截器select permission0_.id as id1_8_, permission0_.create_by as create_b2_8_, permission0_.create_department_id as create_d3_8_, permission0_.create_department_ids as create_d4_8_, permission0_.create_time as create_t5_8_, permission0_.del_flag as del_flag6_8_, permission0_.tenant_id as tenant_i7_8_, permission0_.update_by as update_b8_8_, permission0_.update_department_id as update_d9_8_, permission0_.update_department_ids as update_10_8_, permission0_.update_time as update_11_8_, permission0_.button_type as button_12_8_, permission0_.component as compone13_8_, permission0_.description as descrip14_8_, permission0_.icon as icon15_8_, permission0_.level as level16_8_, permission0_.name as name17_8_, permission0_.parent_id as parent_18_8_, permission0_.path as path19_8_, permission0_.sort_order as sort_or20_8_, permission0_.status as status21_8_, permission0_.title as title22_8_, permission0_.type as type23_8_, permission0_.url as url24_8_ from t_permission permission0_ where permission0_.type=? and permission0_.status=? and permission0_.tenant_id=? order by permission0_.sort_order asc
    Hibernate: select permission0_.id as id1_8_, permission0_.create_by as create_b2_8_, permission0_.create_department_id as create_d3_8_, permission0_.create_department_ids as create_d4_8_, permission0_.create_time as create_t5_8_, permission0_.del_flag as del_flag6_8_, permission0_.tenant_id as tenant_i7_8_, permission0_.update_by as update_b8_8_, permission0_.update_department_id as update_d9_8_, permission0_.update_department_ids as update_10_8_, permission0_.update_time as update_11_8_, permission0_.button_type as button_12_8_, permission0_.component as compone13_8_, permission0_.description as descrip14_8_, permission0_.icon as icon15_8_, permission0_.level as level16_8_, permission0_.name as name17_8_, permission0_.parent_id as parent_18_8_, permission0_.path as path19_8_, permission0_.sort_order as sort_or20_8_, permission0_.status as status21_8_, permission0_.title as title22_8_, permission0_.type as type23_8_, permission0_.url as url24_8_ from t_permission permission0_ where permission0_.type=? and permission0_.status=? and permission0_.tenant_id=? order by permission0_.sort_order asc and 1=1
    

      

  • 相关阅读:
    X oracle move lob 字段到另外的表空间
    X CentOS7使用firewalld打开关闭防火墙与端口
    X ftpd服务常见配置总结(/etc/vsftpd/vsftpd.conf) 【附参数文件】
    P1853 投资的最大效益
    P1466 [USACO2.2]集合 Subset Sums
    小A点菜
    NASA的食物计划
    动态规划入门笔记
    数字三角形 Number Triangles
    P1825 [USACO11OPEN]Corn Maze S
  • 原文地址:https://www.cnblogs.com/mr-wuxiansheng/p/14490900.html
Copyright © 2020-2023  润新知