In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-10-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article shows you how to achieve a Group function in Java, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
The API method is as follows:
/ * keyColumn: new String [] {"xxxName", "xxxType"}
* condition: query condition, which can be empty
* initial: group statistics of initial variables, and automatically provide initial variables for each column for empty time.
* reduce: record processing function
* finalize: finalize function, which can be empty
* / public BasicDBList group (String [] keyColumn, DBObject condition, DBObject initial, String reduce, String finalize) {DBCollection coll = getCollection (); DBObject key = new BasicDBObject (); for (int I = 0; I < keyColumn.length; iTunes +) {key.put (keyColumn [I], true);} condition = (condition = null)? New BasicDBObject (): condition; if (StringUtils.isEmpty (finalize)) {finalize = null;} if (initial = = null) {/ / define some initial variables initial = new BasicDBObject (); for (int I = 0; I < keyColumn.length; iTunes +) {DBObject index = new BasicDBObject () Index.put ("count", 0); index.put ("sum", 0); index.put ("max", 0); index.put ("min", 0); index.put ("avg", 0); index.put ("self", "") Initial.put (keyColumn [I], index);} BasicDBList resultList = (BasicDBList) coll.group (key, condition, initial, reduce, finalize); return resultList;}
Implementation case:
/ / Task Statistics @ Action (value = "getTaskStatistic", results = {@ Result (name = "success", type = "json", params = {"includeProperties", "jsonResult"}) public String getTaskStatistic () {DBObject initial = new BasicDBObject (); DBObject index = new BasicDBObject (); index.put ("count", 0); index.put ("taskStatus", "") Initial.put ("taskStatus", index); String reduce = "function (doc, out) {" + "out.taskStatus.count = out.taskStatus.count+=1;" + "out.taskStatus.inspectStatus = doc.taskStatus;" + "}" BasicDBList group = (BasicDBList) taskStatusService.group (new String [] {"taskStatus"}, null, initial, reduce, null); this.jsonResult = group.toString (); return SUCCESS;}
Return data:
[{"taskStatus": {"count": 4.0," taskStatus ":" Finished "}, {" taskStatus ": {" count ": 3.0," taskStatus": "Received"}, {"taskStatus": {"count": 2.0, "taskStatus": "UnReceive"}}] the above is how to implement a Group function in Java. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.