mirror of https://github.com/halo-dev/halo
commit
9500ba6d55
|
@ -182,7 +182,7 @@ public class AdminController extends BaseController {
|
||||||
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
||||||
@RequestParam(value = "size", defaultValue = "10") Integer size) {
|
@RequestParam(value = "size", defaultValue = "10") Integer size) {
|
||||||
Sort sort = new Sort(Sort.Direction.DESC, "logId");
|
Sort sort = new Sort(Sort.Direction.DESC, "logId");
|
||||||
Pageable pageable = new PageRequest(page, size, sort);
|
Pageable pageable = PageRequest.of(page, size, sort);
|
||||||
Page<Logs> logs = logsService.findAllLogs(pageable);
|
Page<Logs> logs = logsService.findAllLogs(pageable);
|
||||||
model.addAttribute("logs", logs);
|
model.addAttribute("logs", logs);
|
||||||
return "admin/widget/_logs-all";
|
return "admin/widget/_logs-all";
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class AttachmentController {
|
||||||
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
||||||
@RequestParam(value = "size", defaultValue = "18") Integer size) {
|
@RequestParam(value = "size", defaultValue = "18") Integer size) {
|
||||||
Sort sort = new Sort(Sort.Direction.DESC, "attachId");
|
Sort sort = new Sort(Sort.Direction.DESC, "attachId");
|
||||||
Pageable pageable = new PageRequest(page, size, sort);
|
Pageable pageable = PageRequest.of(page, size, sort);
|
||||||
Page<Attachment> attachments = attachmentService.findAllAttachments(pageable);
|
Page<Attachment> attachments = attachmentService.findAllAttachments(pageable);
|
||||||
model.addAttribute("attachments", attachments);
|
model.addAttribute("attachments", attachments);
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ public class AttachmentController {
|
||||||
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
||||||
@RequestParam(value = "id") String id) {
|
@RequestParam(value = "id") String id) {
|
||||||
Sort sort = new Sort(Sort.Direction.DESC, "attachId");
|
Sort sort = new Sort(Sort.Direction.DESC, "attachId");
|
||||||
Pageable pageable = new PageRequest(page, 18, sort);
|
Pageable pageable = PageRequest.of(page, 18, sort);
|
||||||
Page<Attachment> attachments = attachmentService.findAllAttachments(pageable);
|
Page<Attachment> attachments = attachmentService.findAllAttachments(pageable);
|
||||||
model.addAttribute("attachments", attachments);
|
model.addAttribute("attachments", attachments);
|
||||||
model.addAttribute("id", id);
|
model.addAttribute("id", id);
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class CommentController extends BaseController{
|
||||||
@RequestParam(value = "page",defaultValue = "0") Integer page,
|
@RequestParam(value = "page",defaultValue = "0") Integer page,
|
||||||
@RequestParam(value = "size",defaultValue = "10") Integer size){
|
@RequestParam(value = "size",defaultValue = "10") Integer size){
|
||||||
Sort sort = new Sort(Sort.Direction.DESC,"commentDate");
|
Sort sort = new Sort(Sort.Direction.DESC,"commentDate");
|
||||||
Pageable pageable = new PageRequest(page,size,sort);
|
Pageable pageable = PageRequest.of(page,size,sort);
|
||||||
Page<Comment> comments = commentService.findAllComments(status,pageable);
|
Page<Comment> comments = commentService.findAllComments(status,pageable);
|
||||||
model.addAttribute("comments",comments);
|
model.addAttribute("comments",comments);
|
||||||
model.addAttribute("publicCount",commentService.findAllComments(0,pageable).getTotalElements());
|
model.addAttribute("publicCount",commentService.findAllComments(0,pageable).getTotalElements());
|
||||||
|
|
|
@ -142,7 +142,7 @@ public class PageController {
|
||||||
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
||||||
@RequestParam(value = "size", defaultValue = "18") Integer size) {
|
@RequestParam(value = "size", defaultValue = "18") Integer size) {
|
||||||
Sort sort = new Sort(Sort.Direction.DESC, "galleryId");
|
Sort sort = new Sort(Sort.Direction.DESC, "galleryId");
|
||||||
Pageable pageable = new PageRequest(page, size, sort);
|
Pageable pageable = PageRequest.of(page, size, sort);
|
||||||
Page<Gallery> galleries = galleryService.findAllGalleries(pageable);
|
Page<Gallery> galleries = galleryService.findAllGalleries(pageable);
|
||||||
model.addAttribute("galleries", galleries);
|
model.addAttribute("galleries", galleries);
|
||||||
return "admin/admin_page_gallery";
|
return "admin/admin_page_gallery";
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class PostController extends BaseController{
|
||||||
@RequestParam(value = "page",defaultValue = "0") Integer page,
|
@RequestParam(value = "page",defaultValue = "0") Integer page,
|
||||||
@RequestParam(value = "size",defaultValue = "10") Integer size){
|
@RequestParam(value = "size",defaultValue = "10") Integer size){
|
||||||
Sort sort = new Sort(Sort.Direction.DESC,"postDate");
|
Sort sort = new Sort(Sort.Direction.DESC,"postDate");
|
||||||
Pageable pageable = new PageRequest(page,size,sort);
|
Pageable pageable = PageRequest.of(page,size,sort);
|
||||||
Page<Post> posts = postService.findPostByStatus(status,HaloConst.POST_TYPE_POST,pageable);
|
Page<Post> posts = postService.findPostByStatus(status,HaloConst.POST_TYPE_POST,pageable);
|
||||||
model.addAttribute("posts",posts);
|
model.addAttribute("posts",posts);
|
||||||
model.addAttribute("publishCount",postService.findPostByStatus(0,HaloConst.POST_TYPE_POST,pageable).getTotalElements());
|
model.addAttribute("publishCount",postService.findPostByStatus(0,HaloConst.POST_TYPE_POST,pageable).getTotalElements());
|
||||||
|
@ -93,7 +93,7 @@ public class PostController extends BaseController{
|
||||||
try {
|
try {
|
||||||
//排序规则
|
//排序规则
|
||||||
Sort sort = new Sort(Sort.Direction.DESC,"postId");
|
Sort sort = new Sort(Sort.Direction.DESC,"postId");
|
||||||
Pageable pageable = new PageRequest(page,size,sort);
|
Pageable pageable = PageRequest.of(page,size,sort);
|
||||||
model.addAttribute("posts",postService.searchPosts(keyword,pageable));
|
model.addAttribute("posts",postService.searchPosts(keyword,pageable));
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
log.error("未知错误:{0}",e.getMessage());
|
log.error("未知错误:{0}",e.getMessage());
|
||||||
|
@ -176,6 +176,7 @@ public class PostController extends BaseController{
|
||||||
List<Tag> tags = tagService.strListToTagList(StringUtils.trim(tagList));
|
List<Tag> tags = tagService.strListToTagList(StringUtils.trim(tagList));
|
||||||
post.setTags(tags);
|
post.setTags(tags);
|
||||||
}
|
}
|
||||||
|
post.setPostUrl(urlFilter(post.getPostUrl()));
|
||||||
postService.saveByPost(post);
|
postService.saveByPost(post);
|
||||||
logsService.saveByLogs(new Logs(LogsRecord.PUSH_POST,post.getPostTitle(),HaloUtil.getIpAddr(request),HaloUtil.getDate()));
|
logsService.saveByLogs(new Logs(LogsRecord.PUSH_POST,post.getPostTitle(),HaloUtil.getIpAddr(request),HaloUtil.getDate()));
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
|
@ -183,6 +184,17 @@ public class PostController extends BaseController{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String urlFilter(String url) {
|
||||||
|
if (null != url) {
|
||||||
|
final boolean urlEndsWithHtmlPostFix = url.endsWith(".html") || url.endsWith(".htm");
|
||||||
|
if (urlEndsWithHtmlPostFix) {
|
||||||
|
return url.substring(0, url.lastIndexOf("."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理移至回收站的请求
|
* 处理移至回收站的请求
|
||||||
*
|
*
|
||||||
|
@ -282,6 +294,7 @@ public class PostController extends BaseController{
|
||||||
@GetMapping(value = "/checkUrl")
|
@GetMapping(value = "/checkUrl")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public boolean checkUrlExists(@PathParam("postUrl") String postUrl){
|
public boolean checkUrlExists(@PathParam("postUrl") String postUrl){
|
||||||
|
postUrl = urlFilter(postUrl);
|
||||||
Post post = postService.findByPostUrl(postUrl,HaloConst.POST_TYPE_POST);
|
Post post = postService.findByPostUrl(postUrl,HaloConst.POST_TYPE_POST);
|
||||||
return null!=post;
|
return null!=post;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class ArchivesController extends BaseController {
|
||||||
|
|
||||||
//所有文章数据,分页,material主题适用
|
//所有文章数据,分页,material主题适用
|
||||||
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||||
Pageable pageable = new PageRequest(page - 1, 5, sort);
|
Pageable pageable = PageRequest.of(page - 1, 5, sort);
|
||||||
Page<Post> posts = postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable);
|
Page<Post> posts = postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable);
|
||||||
model.addAttribute("posts", posts);
|
model.addAttribute("posts", posts);
|
||||||
return this.render("archives");
|
return this.render("archives");
|
||||||
|
@ -109,7 +109,7 @@ public class ArchivesController extends BaseController {
|
||||||
model.addAttribute("afterPost", afterPosts.get(afterPosts.size() - 1));
|
model.addAttribute("afterPost", afterPosts.get(afterPosts.size() - 1));
|
||||||
}
|
}
|
||||||
Sort sort = new Sort(Sort.Direction.DESC,"commentDate");
|
Sort sort = new Sort(Sort.Direction.DESC,"commentDate");
|
||||||
Pageable pageable = new PageRequest(0,999,sort);
|
Pageable pageable = PageRequest.of(0,999,sort);
|
||||||
Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post,pageable,2);
|
Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post,pageable,2);
|
||||||
|
|
||||||
model.addAttribute("post", post);
|
model.addAttribute("post", post);
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class CategoriesController extends BaseController {
|
||||||
if(!StringUtils.isBlank(HaloConst.OPTIONS.get("index_posts"))){
|
if(!StringUtils.isBlank(HaloConst.OPTIONS.get("index_posts"))){
|
||||||
size = Integer.parseInt(HaloConst.OPTIONS.get("index_posts"));
|
size = Integer.parseInt(HaloConst.OPTIONS.get("index_posts"));
|
||||||
}
|
}
|
||||||
Pageable pageable = new PageRequest(page-1,size,sort);
|
Pageable pageable = PageRequest.of(page-1,size,sort);
|
||||||
Page<Post> posts = postService.findPostByCategories(category,pageable);
|
Page<Post> posts = postService.findPostByCategories(category,pageable);
|
||||||
model.addAttribute("posts",posts);
|
model.addAttribute("posts",posts);
|
||||||
model.addAttribute("category",category);
|
model.addAttribute("category",category);
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class CommentsController {
|
||||||
public List<Comment> getComment(@PathVariable Long postId) {
|
public List<Comment> getComment(@PathVariable Long postId) {
|
||||||
Optional<Post> post = postService.findByPostId(postId);
|
Optional<Post> post = postService.findByPostId(postId);
|
||||||
Sort sort = new Sort(Sort.Direction.DESC, "commentDate");
|
Sort sort = new Sort(Sort.Direction.DESC, "commentDate");
|
||||||
Pageable pageable = new PageRequest(0, 10, sort);
|
Pageable pageable = PageRequest.of(0, 10, sort);
|
||||||
List<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post.get(), pageable, 2).getContent();
|
List<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post.get(), pageable, 2).getContent();
|
||||||
if (null == comments) {
|
if (null == comments) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class IndexController extends BaseController {
|
||||||
size = Integer.parseInt(HaloConst.OPTIONS.get("index_posts"));
|
size = Integer.parseInt(HaloConst.OPTIONS.get("index_posts"));
|
||||||
}
|
}
|
||||||
//所有文章数据,分页
|
//所有文章数据,分页
|
||||||
Pageable pageable = new PageRequest(page - 1, size, sort);
|
Pageable pageable = PageRequest.of(page - 1, size, sort);
|
||||||
Page<Post> posts = postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable);
|
Page<Post> posts = postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable);
|
||||||
model.addAttribute("posts", posts);
|
model.addAttribute("posts", posts);
|
||||||
return this.render("index");
|
return this.render("index");
|
||||||
|
@ -90,7 +90,7 @@ public class IndexController extends BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
//文章数据,只获取文章,没有分页
|
//文章数据,只获取文章,没有分页
|
||||||
Pageable pageable = new PageRequest(page - 1, size, sort);
|
Pageable pageable = PageRequest.of(page - 1, size, sort);
|
||||||
List<Post> posts = postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable).getContent();
|
List<Post> posts = postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable).getContent();
|
||||||
return posts;
|
return posts;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class OthersController {
|
||||||
}
|
}
|
||||||
//获取文章列表并根据时间排序
|
//获取文章列表并根据时间排序
|
||||||
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||||
Pageable pageable = new PageRequest(0, Integer.parseInt(rssPosts), sort);
|
Pageable pageable = PageRequest.of(0, Integer.parseInt(rssPosts), sort);
|
||||||
Page<Post> postsPage = postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable);
|
Page<Post> postsPage = postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable);
|
||||||
List<Post> posts = postsPage.getContent();
|
List<Post> posts = postsPage.getContent();
|
||||||
return postService.buildRss(posts);
|
return postService.buildRss(posts);
|
||||||
|
@ -56,7 +56,7 @@ public class OthersController {
|
||||||
public String siteMap() {
|
public String siteMap() {
|
||||||
//获取文章列表并根据时间排序
|
//获取文章列表并根据时间排序
|
||||||
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||||
Pageable pageable = new PageRequest(0, 999, sort);
|
Pageable pageable = PageRequest.of(0, 999, sort);
|
||||||
Page<Post> postsPage = postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable);
|
Page<Post> postsPage = postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable);
|
||||||
List<Post> posts = postsPage.getContent();
|
List<Post> posts = postsPage.getContent();
|
||||||
return postService.buildSiteMap(posts);
|
return postService.buildSiteMap(posts);
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class PagesController extends BaseController {
|
||||||
Post post = postService.findByPostUrl(postUrl, HaloConst.POST_TYPE_PAGE);
|
Post post = postService.findByPostUrl(postUrl, HaloConst.POST_TYPE_PAGE);
|
||||||
|
|
||||||
Sort sort = new Sort(Sort.Direction.DESC,"commentDate");
|
Sort sort = new Sort(Sort.Direction.DESC,"commentDate");
|
||||||
Pageable pageable = new PageRequest(0,999,sort);
|
Pageable pageable = PageRequest.of(0,999,sort);
|
||||||
Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post,pageable,2);
|
Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post,pageable,2);
|
||||||
|
|
||||||
model.addAttribute("comments",comments);
|
model.addAttribute("comments",comments);
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class TagsController extends BaseController {
|
||||||
if (!StringUtils.isBlank(HaloConst.OPTIONS.get("index_posts"))) {
|
if (!StringUtils.isBlank(HaloConst.OPTIONS.get("index_posts"))) {
|
||||||
size = Integer.parseInt(HaloConst.OPTIONS.get("index_posts"));
|
size = Integer.parseInt(HaloConst.OPTIONS.get("index_posts"));
|
||||||
}
|
}
|
||||||
Pageable pageable = new PageRequest(page - 1, size, sort);
|
Pageable pageable = PageRequest.of(page - 1, size, sort);
|
||||||
Page<Post> posts = postService.findPostsByTags(tag, pageable);
|
Page<Post> posts = postService.findPostsByTags(tag, pageable);
|
||||||
model.addAttribute("posts", posts);
|
model.addAttribute("posts", posts);
|
||||||
model.addAttribute("tag", tag);
|
model.addAttribute("tag", tag);
|
||||||
|
|
Loading…
Reference in New Issue