Custom SQL queries in CrudRepository

前端 未结 1 982
夕颜
夕颜 2021-01-16 00:49

I\'m trying to execute some SQL queries in my repository which extends CrudRepository. I have the following code in Controller:

@CrossOrigin(origins = \"*\"         


        
相关标签:
1条回答
  • 2021-01-16 01:22

    You can change the DAO to below and this should work.

    public interface UserRequestResponseRepository extends CrudRepository<UserRequestResponse, Integer> {
    public static final String FIND_QUERY = 
    "select new com.abc.datacollection.entity.UserRequestResponse(user.u_httpstatus ,user.u_queryparam, COUNT(user.u_type)) from UserRequestResponse user GROUP BY user.u_type";
    @Query(value = FIND_QUERY)
    //public List<UserProjection> getAllRequestResponseRecords();
     List<UserProjection> findAllProjectedBy();
    

    }

    Make sure the Bean class constructor should have the passing parameters.

    Verify that the query is valid JPA query(here).

    0 讨论(0)
提交回复
热议问题