Search code examples
springspring-bootspring-data-jpajpql

A Jpa query annotation to return results as key value pairs


I have a users table and I am trying to use annotated Queries in spring boot to get a result set. I am able to get result set as a list, but that does not have field names. How do I get the result set with field name as key and value pairs? Current response [[1,"Jay"]] , what I want to do is {"id":1,"Name":"Jay"}

-----Here is my repository class-----

 @Repository
 public interface UsersauthRepository2 extends JpaRepository<Users2,Long> {
 @Query("select id,name,email from Users u where LOWER(email) = LOWER(:email) and LOWER(u.password) = LOWER(:password)")
 List<Users2> querybyemail(@Param("email") String email,@Param("password") String password);
  }

Solution

  • The request doesn't return fields names. If you need to get them :

    1. You have them already as method argument
    2. You need to use reflection.

    Good luck