Spring Data JPA less than Example

In this tutorial, we will see Spring Data JPA less than and less than equal example using Spring Boot and oracle.

Let’s see how to define the Query method(Query creation from method names) using Spring Data JPA less than.

Consider we have an entity called Student.java as below.

 

Below Query method will return all record less than given rollnumber.

public List<Student> findByRollNumberLessThan(String rollnumber);

Generated Query.

Hibernate: select student0_.id as id1_0_, student0_.name as name2_0_, student0_.roll_number as roll_number3_0_, student0_.university as university4_0_ from student student0_ where student0_.roll_number<?

 

Below Query method will return all record less than or equal to given rollnumber.

public List<Student> findByRollNumberLessThanEqual(String rollnumber);

Generated Query.

Hibernate: select student0_.id as id1_0_, student0_.name as name2_0_, student0_.roll_number as roll_number3_0_, student0_.university as university4_0_ from student student0_ where student0_.roll_number<=?

 

 

Repository Example.

 

 Spring Data JPA less than and less than equal example using   Spring Boot and oracle.

Open eclipse and create maven project, Don’t forget to check ‘Create a simple project (skip)’ click on next.  Fill all details(GroupId – springdatalessthan, ArtifactId – springdatalessthan and name – springdatalessthan) and click on finish. Keep packaging as the jar.

Modify pom.xml

Note – In pom.xml we have defined javac.exe path in configuration tag. You need to change accordingly i.e where you have installed JDK.

If you see any error for oracle dependency then follow these steps.

Directory structure –

Spring Data JPA less than

 

 

Student.java

StudentController.java

Note – See more details about @Controller and RestController here.

StudentRepository.java – interface

StudentService.java – interface

Note – See here more about @Component, @Controller, @Service and @Repository annotations here.

StudentServiceImpl.java

SpringMain.java

Note – See more details about @ComponentScan here.

JpaConfig.java

Note – See more details about @Configuration annotations here.

application.properties

Let’s run the SpringMain class(run as java application).

Perform saveall operation first using below REST API.

http://localhost:9091/student/saveall

 

Response Data.

 

http://localhost:9091/student/lessthan/124

 

http://localhost:9091/student/lessthan/124

 

Spring Data JPA less than

 

That’s all about Spring Data JPA less than and less than equal example using Spring Boot and oracle

 

You may like.

Other Spring Data JPA and Hibernate tutorials.

 

Spring Data JPA Docs.

 

 

 

 

 

 

Top