Skip to content

Simplify spring data JPA query,dynamic query,selecting specific columns.

License

Notifications You must be signed in to change notification settings

uxov/spring-data-jpa-simplify-query-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simplify Spring Data JPA Query Example

  • Dynamic query
  • Pagination and sorting
  • Selecting specific columns

Requirements

  • JDK version >= 8
  • Gradle

Code Examples

Select specific columns

SelectQuery query = entityQuery.SelectQuery(User.class);
Condition c = query.getCondition();

Page dataList = query.select("name", "age").where(
	c.greaterThanOrEqualTo("age", 25)
).getResult(pageable);

Select all columns

NormalQuery query = entityQuery.NormalQuery(User.class);
Condition c = query.getCondition();

Page dataList = query.select().where(
	c.equal("sex", "male"),
	c.greaterThan("age", 22)
).getResult(pageable);

Ignore null value condition(not need to check for null)

NormalQuery query = entityQuery.NormalQuery(User.class);
Condition c = query.getCondition();

String sex = null;

Page dataList = query.select().where(
	c.equal("sex", sex),
	c.greaterThan("age", 22)
).getResult(pageable);

Add condition

query.getWhere().add(c.greaterThan("age", 22));

In condition

Set ageSet = new HashSet<>();
ageSet.add(22);
ageSet.add(27);

Page dataList = query.select().where(
	c.in("age", ageSet)
).getResult(pageable);

Usage

See more detail in src/test/java/xyz/defe/springDataJpa/test/SimplifyQueryTest.java

About

Simplify spring data JPA query,dynamic query,selecting specific columns.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages