Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beyond-clouds
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
段启岩
beyond-clouds
Commits
d8563272
Commit
d8563272
authored
Feb 14, 2020
by
段启岩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
动态加html标签
parent
dbc0e054
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
0 deletions
+17
-0
src/main/java/cn/meteor/beyondclouds/modules/post/service/impl/PostServiceImpl.java
+1
-0
src/main/java/cn/meteor/beyondclouds/util/TopicUtils.java
+16
-0
No files found.
src/main/java/cn/meteor/beyondclouds/modules/post/service/impl/PostServiceImpl.java
View file @
d8563272
...
...
@@ -112,6 +112,7 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
User
user
=
userService
.
getById
(
post
.
getUserId
());
post
.
setUserNick
(
user
.
getNickName
());
post
.
setUserAvatar
(
user
.
getUserAvatar
());
post
.
setContent
(
TopicUtils
.
encodeTopic
(
post
.
getContent
()));
//2.保存动态
save
(
post
);
...
...
src/main/java/cn/meteor/beyondclouds/util/TopicUtils.java
View file @
d8563272
package
cn
.
meteor
.
beyondclouds
.
util
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.kafka.common.protocol.types.Field
;
import
org.springframework.util.Assert
;
import
java.util.ArrayList
;
...
...
@@ -19,6 +20,20 @@ public class TopicUtils {
private
static
final
Pattern
topicPattern
=
Pattern
.
compile
(
"(#([^#]+?)#)"
);
public
static
String
encodeTopic
(
String
str
)
{
Assert
.
hasText
(
str
,
"str must not be empty"
);
Matcher
matcher
=
topicPattern
.
matcher
(
str
);
StringBuffer
buffer
=
new
StringBuffer
();
while
(
matcher
.
find
())
{
String
tmp
=
"<a href='/topic/detail/"
+
matcher
.
group
(
2
)
+
"'>"
+
matcher
.
group
(
1
)
+
"</a>"
;
matcher
.
appendReplacement
(
buffer
,
tmp
);
}
matcher
.
appendTail
(
buffer
);
return
buffer
.
toString
();
}
public
static
List
<
String
>
parseTopics
(
String
str
)
{
Assert
.
hasText
(
str
,
"str must not be empty"
);
...
...
@@ -37,6 +52,7 @@ public class TopicUtils {
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
TopicUtils
.
parseTopics
(
"#哈哈哈#今#哈哈哈#天你吃饭了吗#吃了#######"
));
System
.
out
.
println
(
TopicUtils
.
encodeTopic
(
"#哈哈哈#今#哈哈哈#天你吃饭了吗#吃了#######哈哈#a#b"
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment