springbootjpa实现
jpa mybatis我们项⽬重构加上了很多数据权限的东西,项⽬中使⽤了mybatis 和 jpa。经⼿的⼈多了就是这样。 mybatis 我们使⽤的是给sql动态拼接,现在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.fig.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_, permission 0_.create_department_ids as create_d4_8_, permission0_.create_time as create_t5_8_, permission0_.del_flag as del_flag6_8_, permission0_.tenant_id a s 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_ponent as compone13_8_ , permission0_.description as descrip14_8_, permission0_.icon as icon15_8_, permission0_.level as level16_8_, permission0_.name as name17_8_, perm ission0_.parent_id as parent_18_8_, permission0_.path as path19_8_, permission0_.sort_order as sort_or20_8_, permission0_.status as status21_8_, per mission0_.title as title22_8_, permission0_.type as type23_8_, permission0_.url as url24_8_ from t_permission permission0_ where permission0_.type=? a nd 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_, permission 0_.create_department_ids as create_d4_8_, permission0_.create_time as create_t5_8_, permission0_.del_flag as del_flag6_8_, permission0_.tenant_id a s 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_ponent as compone13_8_ , permission0_.description as descrip14_8_, permission0_.icon as icon15_8_, permission0_.level as level16_8_, permission0_.name as name17_8_, perm ission0_.parent_id as parent_18_8_, permission0_.path as path19_8_, permission0_.sort_order as sort_or20_8_, permission0_.status as status21_8_, per mission0_.title as title22_8_, permission0_.type as type23_8_, permission0_.url as url24_8_ from t_permission permission0_ where permission0_.type=? a nd permission0_.status=? and permission0_.tenant_id=? order by permission0_.sort_order asc and 1=1

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。