Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SEplus
Backend
Commits
af32a45c
Commit
af32a45c
authored
4 years ago
by
eggle
Browse files
Options
Downloads
Patches
Plain Diff
+关键词count
parent
256490f9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
author-service/src/main/java/com/example/authorservice/blImpl/AuthorDisplay/AuthorDisplayServiceImpl.java
+33
-5
33 additions, 5 deletions
...ervice/blImpl/AuthorDisplay/AuthorDisplayServiceImpl.java
with
33 additions
and
5 deletions
author-service/src/main/java/com/example/authorservice/blImpl/AuthorDisplay/AuthorDisplayServiceImpl.java
+
33
−
5
View file @
af32a45c
...
...
@@ -6,9 +6,7 @@ import com.example.authorservice.vo.*;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.*
;
@Service
...
...
@@ -34,8 +32,38 @@ public class AuthorDisplayServiceImpl implements AuthorDisplayService{
public
ResponseVO
getAuthorTopicsById
(
String
id
)
{
try
{
String
str
=
authorDisplayMapper
.
selectAuthorTopicsById
(
id
);
List
<
String
>
res
=
Arrays
.
asList
(
str
.
split
(
"\n|;"
));
return
ResponseVO
.
buildSuccess
(
res
);
List
<
String
>
aff
=
Arrays
.
asList
(
str
.
split
(
"\n|;"
));
HashMap
<
String
,
Integer
>
res
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
aff
.
size
();
i
++){
Set
<
String
>
wordSet
=
res
.
keySet
();
String
topic
=
aff
.
get
(
i
);
//如果已经有这个单词了,
if
(
topic
.
equals
(
"\r"
)){
continue
;
}
if
(
wordSet
.
contains
(
topic
))
{
Integer
number
=
res
.
get
(
topic
);
number
++;
res
.
put
(
topic
,
number
);
}
else
{
res
.
put
(
topic
,
1
);
}
}
List
<
HashMap
.
Entry
<
String
,
Integer
>>
list
=
new
ArrayList
<
HashMap
.
Entry
<
String
,
Integer
>>(
res
.
entrySet
());
Collections
.
sort
(
list
,
new
Comparator
<
HashMap
.
Entry
<
String
,
Integer
>>()
{
//降序排序
@Override
public
int
compare
(
HashMap
.
Entry
<
String
,
Integer
>
o1
,
HashMap
.
Entry
<
String
,
Integer
>
o2
)
{
return
o2
.
getValue
().
compareTo
(
o1
.
getValue
());
}
});
// StringBuilder resStr=new StringBuilder("{");
// for (HashMap.Entry<String, Integer> mapping : list) {
// resStr.append(mapping.getKey()).append(",").append(mapping.getValue()).append(";");
// }
return
ResponseVO
.
buildSuccess
(
list
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
return
ResponseVO
.
buildFailure
(
"失败"
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment