Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ryanxhl
SpringBlog
提交
90fd3753
S
SpringBlog
项目概览
Ryanxhl
/
SpringBlog
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SpringBlog
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
90fd3753
编写于
10月 02, 2015
作者:
R
Raysmond
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Enable and display post tags
上级
18e6266c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
39 addition
and
7 deletion
+39
-7
src/main/java/com/raysmond/blog/admin/controllers/PostController.java
...a/com/raysmond/blog/admin/controllers/PostController.java
+1
-1
src/main/java/com/raysmond/blog/controllers/PostController.java
...in/java/com/raysmond/blog/controllers/PostController.java
+1
-3
src/main/java/com/raysmond/blog/services/PostService.java
src/main/java/com/raysmond/blog/services/PostService.java
+18
-0
src/main/resources/resources/css/theme.css
src/main/resources/resources/css/theme.css
+11
-0
src/main/resources/templates/posts/show.jade
src/main/resources/templates/posts/show.jade
+8
-3
未找到文件。
src/main/java/com/raysmond/blog/admin/controllers/PostController.java
浏览文件 @
90fd3753
...
...
@@ -121,7 +121,7 @@ public class PostController {
return
"admin/posts_edit"
;
}
else
{
Post
post
=
post
Service
.
getPost
(
postId
);
Post
post
=
post
Repository
.
findOne
(
postId
);
DTOUtil
.
mapTo
(
postForm
,
post
);
post
.
setTags
(
postService
.
parseTagNames
(
postForm
.
getPostTags
()));
...
...
src/main/java/com/raysmond/blog/controllers/PostController.java
浏览文件 @
90fd3753
...
...
@@ -25,9 +25,6 @@ public class PostController {
@Autowired
private
PostService
postService
;
@Autowired
private
TagService
tagService
;
@RequestMapping
(
value
=
"archive"
,
method
=
GET
)
public
String
archive
(
Model
model
){
model
.
addAttribute
(
"posts"
,
postService
.
getArchivePosts
());
...
...
@@ -50,6 +47,7 @@ public class PostController {
throw
new
NotFoundException
(
"Post with permalink "
+
permalink
+
" is not found"
);
model
.
addAttribute
(
"post"
,
post
);
model
.
addAttribute
(
"tags"
,
postService
.
getPostTags
(
post
));
return
"posts/show"
;
}
...
...
src/main/java/com/raysmond/blog/services/PostService.java
浏览文件 @
90fd3753
...
...
@@ -42,6 +42,7 @@ public class PostService {
public
static
final
String
CACHE_NAME
=
"cache.post"
;
public
static
final
String
CACHE_NAME_ARCHIVE
=
CACHE_NAME
+
".archive"
;
public
static
final
String
CACHE_NAME_PAGE
=
CACHE_NAME
+
".page"
;
public
static
final
String
CACHE_NAME_TAGS
=
CACHE_NAME
+
".tag"
;
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
PostService
.
class
);
...
...
@@ -61,6 +62,7 @@ public class PostService {
@Cacheable
(
CACHE_NAME
)
public
Post
getPublishedPostByPermalink
(
String
permalink
){
logger
.
debug
(
"Get post with permalink "
+
permalink
);
Post
post
=
postRepository
.
findByPermalinkAndPostStatus
(
permalink
,
PostStatus
.
PUBLISHED
);
if
(
post
==
null
){
...
...
@@ -85,6 +87,7 @@ public class PostService {
@Caching
(
evict
=
{
@CacheEvict
(
value
=
CACHE_NAME
,
key
=
"#post.id"
),
@CacheEvict
(
value
=
CACHE_NAME
,
key
=
"#post.permalink"
,
condition
=
"#post.permalink != null"
),
@CacheEvict
(
value
=
CACHE_NAME_TAGS
,
key
=
"#post.id"
),
@CacheEvict
(
value
=
CACHE_NAME_ARCHIVE
,
allEntries
=
true
),
@CacheEvict
(
value
=
CACHE_NAME_PAGE
,
allEntries
=
true
)
})
...
...
@@ -99,6 +102,7 @@ public class PostService {
@Caching
(
evict
=
{
@CacheEvict
(
value
=
CACHE_NAME
,
key
=
"#post.id"
),
@CacheEvict
(
value
=
CACHE_NAME
,
key
=
"#post.permalink"
,
condition
=
"#post.permalink != null"
),
@CacheEvict
(
value
=
CACHE_NAME_TAGS
,
key
=
"#post.id"
),
@CacheEvict
(
value
=
CACHE_NAME_ARCHIVE
,
allEntries
=
true
),
@CacheEvict
(
value
=
CACHE_NAME_PAGE
,
allEntries
=
true
)
})
...
...
@@ -121,6 +125,20 @@ public class PostService {
return
cachedPosts
;
}
@Cacheable
(
value
=
CACHE_NAME_TAGS
,
key
=
"#post.id"
)
public
List
<
Tag
>
getPostTags
(
Post
post
){
logger
.
debug
(
"Get tags of post "
+
post
.
getId
());
List
<
Tag
>
tags
=
new
ArrayList
<>();
// Load the post first. If not, when the post is cached before while the tags not,
// then the LAZY loading of post tags will cause an initialization error because
// of not hibernate connection session
postRepository
.
findOne
(
post
.
getId
()).
getTags
().
forEach
(
tags:
:
add
);
return
tags
;
}
private
Post
extractPostMeta
(
Post
post
){
Post
archivePost
=
new
Post
();
archivePost
.
setId
(
post
.
getId
());
...
...
src/main/resources/resources/css/theme.css
浏览文件 @
90fd3753
...
...
@@ -124,6 +124,17 @@ form input, form button{
border-top
:
1px
#eee
solid
;
}
.post
ul
.tags
{
margin-left
:
0
;
padding-left
:
0
;
}
.post
ul
.tags
li
{
display
:
inline-block
;
list-style
:
none
;
margin-left
:
10px
;
}
.footer
{
text-align
:
center
;
margin-bottom
:
50px
;
...
...
src/main/resources/templates/posts/show.jade
浏览文件 @
90fd3753
...
...
@@ -13,13 +13,18 @@ block content
!{post.getRenderedContent()}
.info
if !tags.isEmpty()
ul.tags
li Tags:
for tag in tags
//- li: a(href="#") #{tag.getName()}
li #{tag.getName()}
.author
#{post.getCreatedAt() == post.getUpdatedAt() ? "Created" : "Updated"}
| at #{viewHelper.getFormattedDate(post.getCreatedAt())}
//- ul.tags
//- for tag in tags
//- li: a(href="#") #{tag.getName()}
.comments
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录