A quick tutorial for middleware products

Monday, April 8, 2019

On April 08, 2019 by Kamlesh   No comments
There might be a situation where you need to use your own method based on the requirement of a application.

Spring Boot JPA provides not only CRUD Operations,if you extend JpaRepository, a whole lot of implementation will be available

Some of them are shown below

findByLastnameAndFirstname
findByLastnameOrFirstname
findByStartDateBetween
findByAgeLessThan
findByAgeLessThanEqual
findByAgeGreaterThan
findByAgeGreaterThanEqual
findByStartDateAfter
findByStartDateBefore
findByAgeIsNull
findByAge(Is)NotNull
findByFirstnameLike
findByFirstnameNotLike
findByFirstnameStartingWith

Before adding your own custom implementation,I would suggest you to look at all the implementations that are already available here.

Your own implementation can be added as shown below

public interface PersonDAO extends JpaRepository<Person, Long> {

    @Query("update User u set u.username = :username where u.userid=:userid")
    Integer updateUsernameByUserid(@Param("username") String username,@Param("userid") int userid);
}

0 comments:

Post a Comment