有没有什么方法可以使用一些弹簧数据CrudRepository来获取mongodb查询的结果? 这是我的方法,它返回一个对象列表。
SELECT
i.Item_Category
, i.Total
, i.Quarter
, i.Year
, (i.Total * 100.0) / y.Total as Pct
FROM (
SELECT
Item_Category
, (SUM(Item_Amount) / 100000) AS Total
, quarter(Invoice_date) AS Quarter
, YEAR(Invoice_date) AS Year
FROM `cmpsldata`
WHERE Site = 'BDD1'
AND Item_code LIKE 'FG%'
AND Invoice_type = 'Excise'
GROUP BY Year
, Item_Category
, Quarter
) i
INNER JOIN (
SELECT
(SUM(Item_Amount) / 100000) AS Total
, quarter(Invoice_date) AS Quarter
, YEAR(Invoice_date) AS Year
FROM `cmpsldata`
WHERE Site = 'BDD1'
AND Item_code LIKE 'FG%'
AND Invoice_type = 'Excise'
GROUP BY Year
, Quarter
) y ON i.year = y.year
AND i.quarter = y.quarter
ORDER BY i.Total DESC
例如,它给了我这个结果。
Query(value = "db.tweet_replies.aggregate([ {$match: { 'in_reply_parent_tweet_ID' : {$exists : true}}}, {$group: { _id: '$in_reply_parent_tweet_ID', maxDate: {$max : { $cond: [ {$gt : ['authorization_date_time','$user_reply.authorization_date_time']},'$authorization_date_time','$user_reply.authorization_date_time']}}}}])")
List<fReply> findByInReplyParentPostID(final String inReplyParentPostID);
我想将此结果存储为类型化地图而不是对象列表。任何的想法 ? 。在此先感谢:)
答案 0 :(得分:0)
似乎没有简单的方法可以做到这一点,请看这个问题:Can JPA return results as a map?
也许你可以在你的CrudRepository之上创建一个服务,你可以从你所拥有的List转换到你想要的Map?