java多表查询返回数据_spring data jpa如何在多张数据库表中查询返回某些字段值?...
對于多表聯查需要使用springdata jpa的@Query標注實現,例如最代碼的我的私信列表的查詢:public static final String POSTREPOSITORY_FINDALLBYTYPEANDGROUPBYUSERID = "select id from (select id,target_id,case when user_id=?1 and type=?2 then 'sender' else 'receiver' end flag from javaniu_post where user_id=?1 and type=?2 union select id,user_id,case when user_id=?1then 'sender' else 'receiver' end flag from javaniu_post where target_id=?1 and type=?2 order by id desc) as ret group by target_id order by id desc";@Query(value = RepositoryQuery.POSTREPOSITORY_FINDALLBYTYPEANDGROUPBYUSERID, nativeQuery = true)
List findAllByTypeAndGroupByUserId(long userId, int type);
調用:List _ids = postRepository.findAllByTypeAndGroupByUserId(userId, type);
這樣就獲取到所有其他用戶和我的私信最新的列表
參考
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的java多表查询返回数据_spring data jpa如何在多张数据库表中查询返回某些字段值?...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怎么申请中文域名(怎么申请中文域名注册)
- 下一篇: mysql 密码hash算法_如何用ha