单表查询 

《Spring Data JPA》jpa表关联查询,聚合查询,JPQL语句

需要保证类中有此构造方法 

 聚合查询

	 /**
	  * 以JPQL面向对象的方式 连接查询
	  * @return
	  */
	 @Query(value="SELECT new com.zzy.demo.utils.dto.PersonCount(p.name as name, COUNT(p.id) as totalNum)  FROM   Person p  GROUP BY  p.name" )
	 public List<PersonCount> personStatsOopSql();

关联查询 

    /**
     * 根据用户查找代理角色
     * @param userId
     * @return List<ProxyRole>
     */
    @Query(value="select new ProxyRole(p.id, p.userId, p.organId, o.name as organName,p.roleId,p.roleName,p.limitDate)   from ProxyRole as p , Organ as o   WHERE  p.organId=o.id and  p.userId = :userId")
    List<ProxyRole> findByUserId(@Param("userId")String userId);

 

相关文章:

  • 2021-05-10
  • 2021-08-17
  • 2021-07-15
  • 2022-12-23
  • 2022-12-23
  • 2022-01-21
猜你喜欢
  • 2022-12-23
  • 2021-11-06
  • 2022-12-23
  • 2021-09-08
  • 2022-12-23
  • 2021-08-31
  • 2021-10-21
相关资源
相似解决方案