spring Data JPA大大的简化了我们持久层的开发,但是实际应用中,我们还是需要动态查询的。
比如,前端有多个条件,这些条件很多都是可选的,那么后端的SQL,就应该是可以定制的,在使用hibernate的时候,可以通过判断条件来拼接SQL(HQL),当然,Spring Data JPA在简化我们开发的同时,也是提供了支持的。
通过实现Criteria二实现的动态查询,需要我们的Repo接口继承JpaSpecificationExecutor接口,这是个泛型接口。
然后查询的时候,传入动态查询参数,分页参数等即可。
使用起来很简单,不过为了知其所以然,先介绍一下Criteria API。
Criteria API
如果编译器能够对查询执行语法正确性检查,那么对于 Java 对象而言该查询就是类型安全的。Java™Persistence API (JPA) 的 2.0 版本引入了 Criteria API,这个 API 首次将类型安全查询引入到 Java 应用程序中,并为在运行时动态地构造查询提供一种机制。本文介绍如何使用 Criteria API 和与之密切相关的 Metamodel API 编写动态的类型安全查询。
在使用Spring Data JPA的时候,只要我们的Repo层继承JpaSpecificationExecutor接口就可以使用Specification进行动态查询了,我们先看下JpaSpecificationExecutor接口:
- public interface JpaSpecificationExecutor {
- T findOne(Specification spec);
- List findAll(Specification spec);
- Page findAll(Specification spec, Pageable pageable);
- List findAll(Specification spec, Sort sort);
- long count(Specification spec);
- }
可以看到提供了5个方法,方法的参数和返回值已经很明显的表达了其意图。其中的参数,Pageable和Sort应该是比较简单的,分别是分页参数和排序参数,而重点就是Specification参数,先看下这个接口的定义:
- public interface Specification {
- Predicate toPredicate(Root root, CriteriaQuery> query, CriteriaBuilder cb);
- }
其中就一个方法,返回的是动态查询的数据结构。
javax.persistence.criteria.Predicate toPredicate(javax.persistence.criteria.Root root,
javax.persistence.criteria.CriteriaQuery> query,
javax.persistence.criteria.CriteriaBuilder cb);
这里使用的都是Java EE中的规范,具体实现本人采用的是Hibernate,当然也可以选择其他实现了JPA规范的数据持久层框架。
这里需要再次回过头看看Criteria API中的一些东西:
Criteria 查询是以元模型的概念为基础的,元模型是为具体持久化单元的受管实体定义的,这些实体可以是实体类,嵌入类或者映射的父类。
CriteriaQuery接口:代表一个specific的顶层查询对象,它包含着查询的各个部分,比如:select 、from、where、group by、order by等注意:CriteriaQuery对象只对实体类型或嵌入式类型的Criteria查询起作用
Root接口:代表Criteria查询的根对象,Criteria查询的查询根定义了实体类型,能为将来导航获得想要的结果,它与SQL查询中的FROM子句类似
1:Root实例是类型化的,且定义了查询的FROM子句中能够出现的类型。
2:查询根实例能通过传入一个实体类型给 AbstractQuery.from方法获得。
3:Criteria查询,可以有多个查询根。
4:AbstractQuery是CriteriaQuery 接口的父类,它提供得到查询根的方法。CriteriaBuilder接口:用来构建CritiaQuery的构建器对象Predicate:一个简单或复杂的谓词类型,其实就相当于条件或者是条件组合
其中支持的方法非常之强大,下面给出一个示例,大家可以参考一下,同样的,可以根据示例,自己可以写出更为复杂的查询:
Repo接口:
- public interface DevHREmpConstrastDao
- extends JpaRepository,JpaSpecificationExecutor
查询实例1:
-
-
-
- private Specification where(
- final String corg,final String name,final String type,final String date,final String checker){
- return new Specification() {
- @Override
- public Predicate toPredicate(Root root, CriteriaQuery> query, CriteriaBuilder cb) {
- List predicates = new ArrayList();
-
- if(corg!=null&&!corg.equals("")){
- List orgIds = organizationDao.findByName("%"+corg+"%");
- if(orgIds.size()>0&&orgIds.size()<1000)
- predicates.add(root.get("confirmOrgNo").in(orgIds));
- }
-
- if(name!=null&&!name.equals("")){
- List userIds = userDao.findByName(name);
- if(userIds.size()>0&&userIds.size()<1000)
- predicates.add(root.get("hrUserName").in(userIds));
- }
-
- if(type!=null&&!type.equals(""))
- predicates.add(cb.equal(root.get("hrUpdateType"),type));
-
- if(date!=null&&!date.equals("")){
-
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
- Date startDate;
- Date endDate;
- try {
- startDate = format.parse(date);
- } catch (ParseException e) {
- startDate = new Date(946656000000L);
- }
- endDate = startDate;
- Calendar calendar = Calendar.getInstance() ;
- calendar.setTime(endDate);
- calendar.add(Calendar.DATE, 1);
- endDate = calendar.getTime();
- calendar = null;
- predicates.add(cb.between(root.get("insDate"),startDate,endDate));
- }
-
- if(checker!=null&&!checker.equals("")){
- List userIds = userDao.findByName(checker);
- if(userIds.size()>0&&userIds.size()<1000)
- predicates.add(root.get("confirmUserId").in(userIds));
- }
- return query.where(predicates.toArray(new Predicate[predicates.size()])).getRestriction();
- }
- };
- }
查询实例2:
-
-
-
- private Specification where(
- final String corg,final String name,final String type,final String date,final String checker){
- return new Specification() {
- @Override
- public Predicate toPredicate(Root root, CriteriaQuery> query, CriteriaBuilder cb) {
- List predicates = new ArrayList();
-
- if(corg!=null&&!corg.equals("")){
- List orgIds = organizationDao.findByName("%"+corg+"%");
- if(orgIds.size()>0&&orgIds.size()<1000)
- predicates.add(root.get("confirmOrgNo").in(orgIds));
- }
-
- if(name!=null&&!name.equals("")){
- List userIds = userDao.findByName(name);
- if(userIds.size()>0&&userIds.size()<1000)
- predicates.add(root.get("hrUserName").in(userIds));
- }
-
- if(type!=null&&!type.equals(""))
- predicates.add(cb.equal(root.get("hrUpdateType"),type));
-
- if(date!=null&&!date.equals("")){
-
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
- Date startDate;
- Date endDate;
- try {
- startDate = format.parse(date);
- } catch (ParseException e) {
- startDate = new Date(946656000000L);
- }
- endDate = startDate;
- Calendar calendar = Calendar.getInstance() ;
- calendar.setTime(endDate);
- calendar.add(Calendar.DATE, 1);
- endDate = calendar.getTime();
- calendar = null;
- predicates.add(cb.between(root.get("insDate"),startDate,endDate));
- }
-
- if(checker!=null&&!checker.equals("")){
- List userIds = userDao.findByName(checker);
- if(userIds.size()>0&&userIds.size()<1000)
- predicates.add(root.get("confirmUserId").in(userIds));
- }
- return query.where(predicates.toArray(new Predicate[predicates.size()])).getRestriction();
- }
- };
- }
然后调用dao层方法传入where()方法返回的参数即可。
项目结构如下:
pom.xml
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0modelVersion>
-
- <groupId>cn.dbgroupId>
- <artifactId>psqlartifactId>
- <packaging>warpackaging>
- <version>0.0.1-SNAPSHOTversion>
-
- <name>psql Maven Webappname>
- <url>http://maven.apache.orgurl>
-
- <dependencies>
-
- <dependency>
- <groupId>junitgroupId>
- <artifactId>junitartifactId>
- <version>4.10version>
- <scope>testscope>
- dependency>
-
- <dependency>
- <groupId>commons-dbcpgroupId>
- <artifactId>commons-dbcpartifactId>
- <version>1.4version>
- dependency>
-
- <dependency>
- <groupId>javax.servletgroupId>
- <artifactId>jsp-apiartifactId>
- <version>2.0version>
- dependency>
-
- <dependency>
- <groupId>mysqlgroupId>
- <artifactId>mysql-connector-javaartifactId>
- <version>5.1.5version>
- dependency>
-
- <dependency>
- <groupId>org.springframework.datagroupId>
- <artifactId>spring-data-jpaartifactId>
- <version>1.6.1.RELEASEversion>
- dependency>
-
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-data-jpaartifactId>
- <version>1.1.4.RELEASEversion>
- dependency>
-
- <dependency>
- <groupId>org.apache.maven.pluginsgroupId>
- <artifactId>maven-resources-pluginartifactId>
- <version>2.6version>
- dependency>
-
- dependencies>
-
- <repositories>
- <repository>
- <id>spring-milestonesid>
- <url>http://repo.spring.io/libs-milestoneurl>
- repository>
- repositories>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.pluginsgroupId>
- <artifactId>maven-compiler-pluginartifactId>
- <configuration>
- <source>1.8source>
- <target>1.8target>
- configuration>
- plugin>
- plugins>
- build>
-
- project>
persistence.xml
- xml version="1.0" encoding="UTF-8"?>
-
- <persistence xmlns="http://java.sun.com/xml/ns/persistence"
- version="2.0">
- <persistence-unit name="SimplePU" transaction-type="RESOURCE_LOCAL">
- <provider>org.hibernate.ejb.HibernatePersistenceprovider>
-
- <properties>
- <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
- <property name="hibernate.connection.url" value="jdbc:mysql://127.0.0.1:3306/db_cloud" />
- <property name="hibernate.connection.username" value="root" />
- <property name="hibernate.connection.password" value="root" />
- <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
- <property name="hibernate.show_sql" value="true" />
- <property name="hibernate.format_sql" value="true" />
- <property name="hibernate.use_sql_comments" value="false" />
- <property name="hibernate.hbm2ddl.auto" value="update" />
- properties>
- persistence-unit>
- persistence>
applicationContext.xml
- xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
- xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:jpa="http://www.springframework.org/schema/data/jpa"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx.xsd
- http://www.springframework.org/schema/data/jpa
- http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context.xsd">
-
- <bean name="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
- <property name="driverClassName">
- <value>com.mysql.jdbc.Drivervalue>
- property>
- <property name="url">
- <value>jdbc:mysql://127.0.0.1:3306/db_cloudvalue>
- property>
- <property name="username" value="root" />
- <property name="password" value="root" />
- bean>
-
- <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
- <property name="entityManagerFactory" ref="entityManagerFactory" />
- bean>
-
- <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
-
- <bean id="entityManagerFactory"
- class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
- bean>
-
- <jpa:repositories base-package="cn.db.psql"
- entity-manager-factory-ref="entityManagerFactory"
- transaction-manager-ref="transactionManager" />
-
- beans>
Person.Java
- package cn.db.psql;
-
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import javax.persistence.Table;
-
- @Entity
- @Table(name = "ts_person")
- public class Person {
-
- @Column
- @Id
- @GeneratedValue(strategy=GenerationType.IDENTITY)
- private Integer userid;
-
- @Column
- private String username;
-
- @Column
- private String stype;
-
- @Column
- private Integer city_id;
-
- public Integer getUserid() {
- return userid;
- }
-
- public void setUserid(Integer userid) {
- this.userid = userid;
- }
-
- public String getUsername() {
- return username;
- }
-
- public void setUsername(String username) {
- this.username = username;
- }
-
- public String getStype() {
- return stype;
- }
-
- public void setStype(String stype) {
- this.stype = stype;
- }
-
- public Integer getCity_id() {
- return city_id;
- }
-
- public void setCity_id(Integer city_id) {
- this.city_id = city_id;
- }
-
- public String toString()
- {
- return "[userid="+userid+",username="+username+",stype="+stype+",city_id="+city_id+"]";
- }
- }
PersonJpaSpecificationExecutor.java
- package cn.db.psql;
-
- import java.util.List;
-
- import org.springframework.data.domain.Page;
- import org.springframework.data.domain.Pageable;
- import org.springframework.data.jpa.domain.Specification;
- import org.springframework.data.jpa.repository.JpaRepository;
- import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
- import org.springframework.stereotype.Repository;
-
-
-
-
- @Repository("personJpaSpecificationExecutor")
- public interface PersonJpaSpecificationExecutor extends JpaRepository, JpaSpecificationExecutor
- {
- Page findAll(Specification spec, Pageable pageable);
-
- List findAll(Specification spec);
- }
PersonRepository.java
- package cn.db.psql;
-
- import org.springframework.data.jpa.repository.JpaRepository;
- import org.springframework.data.jpa.repository.Query;
- import org.springframework.data.repository.query.Param;
- import org.springframework.stereotype.Repository;
-
-
-
-
- @Repository("personRepository")
- public interface PersonRepository extends JpaRepository
- {
- @Query("select a from Person a where a.userid = :userid")
- public Person findByUserid(@Param("userid")Integer userid);
- }
PersonSpecification.java
- package cn.db.psql;
-
- import java.util.ArrayList;
- import java.util.List;
-
- import javax.persistence.criteria.CriteriaBuilder;
- import javax.persistence.criteria.CriteriaQuery;
- import javax.persistence.criteria.Path;
- import javax.persistence.criteria.Predicate;
- import javax.persistence.criteria.Root;
-
- import org.springframework.data.jpa.domain.Specification;
-
- public class PersonSpecification implements Specification
- {
- private String _username;
- private String _stype;
- private Integer _cityId;
-
- public PersonSpecification(String username, String stype, Integer cityId)
- {
- this._username = username;
- this._stype = stype;
- this._cityId = cityId;
- }
-
- public Predicate toPredicate(Root root, CriteriaQuery> query,CriteriaBuilder cb)
- {
-
- Path username = root.get("username");
-
- Path stype = root.get("stype");
- Path city_id = root.get("city_id");
-
- List list = new ArrayList();
-
- Predicate pa = cb.equal(username, _username);
- Predicate pb = cb.equal(stype, _stype);
- Predicate pc = cb.equal(city_id, _cityId);
-
- if(_username != null)
- {
- list.add(pa);
- }
- if(_stype != null)
- {
- list.add(pb);
- }
- if(_cityId != null)
- {
- list.add(pc);
- }
-
- Predicate[] parray = new Predicate[list.size()];
-
- return cb.and(list.toArray(parray));
- }
-
- public String get_username() {
- return _username;
- }
-
- public void set_username(String _username) {
- this._username = _username;
- }
-
- public String get_stype() {
- return _stype;
- }
-
- public void set_stype(String _stype) {
- this._stype = _stype;
- }
-
- public Integer get_cityId() {
- return _cityId;
- }
-
- public void set_cityId(Integer _cityId) {
- this._cityId = _cityId;
- }
- }
Client.java
- package cn.db.psql;
-
- import java.util.List;
-
- import org.springframework.context.support.ClassPathXmlApplicationContext;
-
- public class Client {
-
- public static void find() throws Exception
- {
- ClassPathXmlApplicationContext ctx =
- new ClassPathXmlApplicationContext("applicationContext.xml");
-
- try
- {
- PersonJpaSpecificationExecutor ur = (PersonJpaSpecificationExecutor)ctx.getBean("personJpaSpecificationExecutor");
-
- PersonSpecification us = new PersonSpecification(null,"1",1);
-
- List plist = ur.findAll(us);
-
- System.out.println("==============================================");
-
- for(Person p : plist)
- {
- System.out.println(p);
- }
-
- System.out.println("==============================================");
-
- }catch(Exception e)
- {
- e.printStackTrace();
- }
-
- ctx.close();
- }
-
- public static void main(String[] args) throws Exception
- {
- find();
- }
- }
FastQuery 快速操作数据层框架
FastQuery 基于Java语言.他的使命是:简化Java操作数据层.做为一个开发者, 仅仅只需要设计DAO接口即可,其内部采用ASM动态生成实现,执行快. 因此,代码简洁而优雅.从而,大幅度提升开发效率.
FastQuery 主要特性如下:
- 设计优雅,配置简单,极易上手.
- 采用ASM动态生成字节码,因此支持编译前预处理,可最大限度减少运行期的错误.显著提升程序的强壮性.
- 支持安全查询,防止SQL注入.
- 支持与主流数据库连接池框架集成,如集成c3p0,dbcp等等
- 支持
@Query
查询,使用 @Condition
,可实现动态 where
条件查询.
- 支持查询结果集以JSON类型返回
- 支持
AOP
,注入拦截器只需标识几个简单的注解,如: @Before
, @After
运行环境要求
jdk1.8+
配置文件
jdbc-config.xml
用来配置支持jdbc. 注意:如果采用连接池,该配置文件可以不要.
<jdbc-config>
<named-config name="xk_db">
<property name="driverClass">com.mysql.jdbc.Driverproperty>
<property name="url">jdbc:mysql://192.168.1.1:3306/xk?user=xk&password=abc123property>
named-config>
<named-config name="shtest_db">
<property name="driverClass">com.mysql.jdbc.Driverproperty>
<property name="databaseName">dbnameproperty>
<property name="user">usernameproperty>
<property name="password">userpasswdproperty>
<property name="portNumber">3306property>
<property name="serverName">192.168.1.1property>
named-config>
jdbc-config>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
c3p0-config.xml
支持c3p0配置,详情配置请参照c3p0官网的说明: http://www.mchange.com/projects/c3p0/.
<c3p0-config>
<named-config name="xk-c3p0">
<property name="driverClass">com.mysql.jdbc.Driverproperty>
<property name="jdbcUrl">jdbc:mysql://192.168.1.1:3306/xkproperty>
<property name="user">xkproperty>
<property name="password">abc123property>
<property name="acquireIncrement">50property>
<property name="initialPoolSize">100property>
<property name="minPoolSize">50property>
<property name="maxPoolSize">1000property>
<property name="maxStatements">0property>
<property name="maxStatementsPerConnection">5property>
named-config>
c3p0-config>
- 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
- 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
fastquery.json
配置数据源的作用范围
[
{
"config": "c3p0",
"dataSourceName": "xk-c3p0",
"basePackages": [
"org.fastquery.example.StudentDBService"
]
},
{
"config" : "jdbc",
"dataSourceName": "shtest_db",
"basePackages": [
"org.fastquery.example.DataAcquireDbService"
]
}
]
- 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
- 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
一个完整的入门例子
public class Student
{
private String no;
private String name;
private String sex;
private Integer age;
private String dept;
}
public interface StudentDBService extends QueryRepository {
@Query("select * from student")
JSONArray findAll();
@Query("select * from student")
Student[] find();
}
StudentDBService studentDBService = FQuery.getRepository(StudentDBService.class);
JSONArray jsonArray = studentDBService.findAll();
Student[] students = studentDBService.find();
带条件查询
@Query("select no as no,name,sex,age,dept from student s where s.sex=?2 and s.age > ?1")
Student[] find(Integer age,String sex);
@Query("select * from student s where s.sex=?1 and s.age > ?2")
JSONArray find(String sex,Integer age);
@Query("select * from student s where s.sex=?1 and s.age > ?2")
List
动态条件查询
@Query("select * from Student #{#where} order by age desc")
@Condition(l="no",o=Operator.LIKE,r="?1")
@Condition(c=COperator.AND,l="name",o=Operator.LIKE,r="?2")
@Condition(c=COperator.AND,l="age",o=Operator.GT,r="?3",ignoreNull=false)
@Condition(c=COperator.OR,l="dept",o=Operator.IN,r="(?4,?5,?6)")
@Condition(c=COperator.AND,l="name",o={Operator.NOT,Operator.LIKE},r="?7")
@Condition(c=COperator.OR,l="age",o=Operator.BETWEEN,r="?8 and ?9")
Student[] findAllStudent(... args ...);
count
统计查询行数
@Query("select count(no) from student")
long count();
exists
判断是否存在
@Query("select * from student s where s.no=?1")
boolean exists(String no);
改操作
@Query("update student s set s.age=?3,s.name=?2 where s.no=?1")
@Modifying
int update(String no,String name,int age);
@Modifying
@Query("DELETE FROM `userinfo` WHERE id=?1")
boolean deleteUserinfoById(int id);
@Query("update student s set s.age=?2 where s.no=?1")
@Modifying
int update(String no,int age);
@Query("insert into student (no, name, sex, age, dept) values (?1, ?2, ?3, ?4, ?5)")
@Modifying(table="student",id="no")
Student addStudent(@Id String no,String name,String sex,int age,String dept);
@Modifying(id="id",table="userinfo")
@Query("insert into #{#table} (name,age) values (?1, ?2)")
Map addUserInfo(String name,Integer age);
@Modifying(id="id",table="userinfo")
@Query("insert into #{#table} (name,age) values (?1, ?2)")
JSONObject saveUserInfo2(String name,Integer age);
@Modifying(id="id",table="userinfo")
@Query("insert into #{#table} (name,age) values (?1, ?2)")
Primarykey saveUserInfo(String name,Integer age);
- 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
- 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
@Before拦截器
/**
* @author xixifeng ([email protected])
*/
public class MyBeforeFilter1 extends BeforeFilter<Repository> {
@Override
public void doFilter(Repository repository, Method method, Object[] args) {
}
}
@Before(MyBeforeFilter1.class)
@Before(MyBeforeFilter2.class)
@Before(MyBeforeFilter3.class)
public interface StudentDBService extends QueryRepository {
}
@After拦截器
/**
* @author xixifeng ([email protected])
*/
public class MyAfterFilter extends AfterFilter<Repository> {
@Override
public Object doFilter(Repository repository, Method method, Object[] args, Object returnVal) {
return returnVal;
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
@After(MyAfterFilter.class)
@After(MyAfterFilter2.class)
public interface StudentDBService extends QueryRepository {
}
开源地址
http://www.oschina.net/p/fastquery