mirror of https://github.com/halo-dev/halo
Refactor pageable and sort
parent
9585f1553f
commit
dae2968269
|
@ -20,9 +20,9 @@ import cn.hutool.http.HtmlUtil;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -77,7 +77,6 @@ public class AdminController extends BaseController {
|
|||
* 请求后台页面
|
||||
*
|
||||
* @param model model
|
||||
* @param session session
|
||||
* @return 模板路径admin/admin_index
|
||||
*/
|
||||
@GetMapping(value = {"", "/index"})
|
||||
|
@ -201,16 +200,11 @@ public class AdminController extends BaseController {
|
|||
* 查看所有日志
|
||||
*
|
||||
* @param model model model
|
||||
* @param page page 当前页码
|
||||
* @param size size 每页条数
|
||||
* @return 模板路径admin/widget/_logs-all
|
||||
*/
|
||||
@GetMapping(value = "/logs")
|
||||
public String logs(Model model,
|
||||
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
||||
@RequestParam(value = "size", defaultValue = "10") Integer size) {
|
||||
public String logs(Model model, @PageableDefault Pageable pageable) {
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "logId");
|
||||
final Pageable pageable = PageRequest.of(page, size, sort);
|
||||
final Page<Logs> logs = logsService.findAll(pageable);
|
||||
model.addAttribute("logs", logs);
|
||||
return "admin/widget/_logs-all";
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.springframework.data.domain.Page;
|
|||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -55,15 +56,11 @@ public class AttachmentController {
|
|||
* 复印件列表
|
||||
*
|
||||
* @param model model
|
||||
*
|
||||
* @return 模板路径admin/admin_attachment
|
||||
*/
|
||||
@GetMapping
|
||||
public String attachments(Model model,
|
||||
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
||||
@RequestParam(value = "size", defaultValue = "18") Integer size) {
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "attachId");
|
||||
final Pageable pageable = PageRequest.of(page, size, sort);
|
||||
@PageableDefault(size = 18, sort = "attachId", direction = Sort.Direction.DESC) Pageable pageable) {
|
||||
final Page<Attachment> attachments = attachmentService.findAll(pageable);
|
||||
model.addAttribute("attachments", attachments);
|
||||
return "admin/admin_attachment";
|
||||
|
@ -73,17 +70,13 @@ public class AttachmentController {
|
|||
* 跳转选择附件页面
|
||||
*
|
||||
* @param model model
|
||||
* @param page page 当前页码
|
||||
*
|
||||
* @return 模板路径admin/widget/_attachment-select
|
||||
*/
|
||||
@GetMapping(value = "/select")
|
||||
public String selectAttachment(Model model,
|
||||
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
||||
@PageableDefault(size = 18, sort = "attachId", direction = Sort.Direction.DESC) Pageable pageable,
|
||||
@RequestParam(value = "id", defaultValue = "none") String id,
|
||||
@RequestParam(value = "type", defaultValue = "normal") String type) {
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "attachId");
|
||||
final Pageable pageable = PageRequest.of(page, 18, sort);
|
||||
final Page<Attachment> attachments = attachmentService.findAll(pageable);
|
||||
model.addAttribute("attachments", attachments);
|
||||
model.addAttribute("id", id);
|
||||
|
@ -109,7 +102,6 @@ public class AttachmentController {
|
|||
*
|
||||
* @param file file
|
||||
* @param request request
|
||||
*
|
||||
* @return Map
|
||||
*/
|
||||
@PostMapping(value = "/upload", produces = {"application/json;charset=UTF-8"})
|
||||
|
@ -159,7 +151,6 @@ public class AttachmentController {
|
|||
*
|
||||
* @param model model
|
||||
* @param attachId 附件编号
|
||||
*
|
||||
* @return 模板路径admin/widget/_attachment-detail
|
||||
*/
|
||||
@GetMapping(value = "/attachment")
|
||||
|
@ -174,7 +165,6 @@ public class AttachmentController {
|
|||
*
|
||||
* @param attachId 附件编号
|
||||
* @param request request
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/remove")
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.springframework.data.domain.Page;
|
|||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -60,18 +61,12 @@ public class CommentController extends BaseController {
|
|||
*
|
||||
* @param model model
|
||||
* @param status status 评论状态
|
||||
* @param page page 当前页码
|
||||
* @param size size 每页显示条数
|
||||
*
|
||||
* @return 模板路径admin/admin_comment
|
||||
*/
|
||||
@GetMapping
|
||||
public String comments(Model model,
|
||||
@RequestParam(value = "status", defaultValue = "0") Integer status,
|
||||
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
||||
@RequestParam(value = "size", defaultValue = "10") Integer size) {
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "commentDate");
|
||||
final Pageable pageable = PageRequest.of(page, size, sort);
|
||||
@PageableDefault(sort = "commentDate", direction = Sort.Direction.DESC) Pageable pageable,
|
||||
@RequestParam(value = "status", defaultValue = "0") Integer status) {
|
||||
final Page<Comment> comments = commentService.findAll(status, pageable);
|
||||
model.addAttribute("comments", comments);
|
||||
model.addAttribute("publicCount", commentService.getCountByStatus(CommentStatusEnum.PUBLISHED.getCode()));
|
||||
|
@ -86,19 +81,18 @@ public class CommentController extends BaseController {
|
|||
*
|
||||
* @param commentId 评论编号
|
||||
* @param status 评论状态
|
||||
*
|
||||
* @return 重定向到/admin/comments
|
||||
*/
|
||||
@GetMapping(value = "/throw")
|
||||
public String moveToTrash(@RequestParam("commentId") Long commentId,
|
||||
@RequestParam("status") String status,
|
||||
@RequestParam(value = "page", defaultValue = "0") Integer page) {
|
||||
@PageableDefault Pageable pageable) {
|
||||
try {
|
||||
commentService.updateCommentStatus(commentId, CommentStatusEnum.RECYCLE.getCode());
|
||||
} catch (Exception e) {
|
||||
log.error("Delete comment failed: {}", e.getMessage());
|
||||
}
|
||||
return "redirect:/admin/comments?status=" + status + "&page=" + page;
|
||||
return "redirect:/admin/comments?status=" + status + "&page=" + pageable.getPageNumber();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,7 +101,6 @@ public class CommentController extends BaseController {
|
|||
* @param commentId 评论编号
|
||||
* @param status 评论状态
|
||||
* @param session session
|
||||
*
|
||||
* @return 重定向到/admin/comments
|
||||
*/
|
||||
@GetMapping(value = "/revert")
|
||||
|
@ -128,20 +121,18 @@ public class CommentController extends BaseController {
|
|||
*
|
||||
* @param commentId commentId 评论编号
|
||||
* @param status status 评论状态
|
||||
* @param page 当前页码
|
||||
*
|
||||
* @return string 重定向到/admin/comments
|
||||
*/
|
||||
@GetMapping(value = "/remove")
|
||||
public String moveToAway(@RequestParam("commentId") Long commentId,
|
||||
@RequestParam("status") Integer status,
|
||||
@RequestParam(value = "page", defaultValue = "0") Integer page) {
|
||||
@PageableDefault Pageable pageable) {
|
||||
try {
|
||||
commentService.remove(commentId);
|
||||
} catch (Exception e) {
|
||||
log.error("Delete comment failed: {}", e.getMessage());
|
||||
}
|
||||
return "redirect:/admin/comments?status=" + status + "&page=" + page;
|
||||
return "redirect:/admin/comments?status=" + status + "&page=" + pageable.getPageNumber();
|
||||
}
|
||||
|
||||
|
||||
|
@ -150,7 +141,6 @@ public class CommentController extends BaseController {
|
|||
*
|
||||
* @param commentId 被回复的评论
|
||||
* @param commentContent 回复的内容
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/reply")
|
||||
|
|
|
@ -33,8 +33,6 @@ public class MenuController {
|
|||
/**
|
||||
* 渲染菜单设置页面
|
||||
*
|
||||
* @param model model
|
||||
*
|
||||
* @return 模板路径/admin/admin_menu
|
||||
*/
|
||||
@GetMapping
|
||||
|
@ -46,7 +44,6 @@ public class MenuController {
|
|||
* 新增/修改菜单
|
||||
*
|
||||
* @param menu menu
|
||||
*
|
||||
* @return 重定向到/admin/menus
|
||||
*/
|
||||
@PostMapping(value = "/save")
|
||||
|
@ -70,7 +67,6 @@ public class MenuController {
|
|||
*
|
||||
* @param menuId 菜单编号
|
||||
* @param model model
|
||||
*
|
||||
* @return 模板路径/admin/admin_menu
|
||||
*/
|
||||
@GetMapping(value = "/edit")
|
||||
|
@ -84,7 +80,6 @@ public class MenuController {
|
|||
* 删除菜单
|
||||
*
|
||||
* @param menuId 菜单编号
|
||||
*
|
||||
* @return 重定向到/admin/menus
|
||||
*/
|
||||
@GetMapping(value = "/remove")
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.springframework.data.domain.Page;
|
|||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
|
@ -77,7 +78,6 @@ public class PageController {
|
|||
* 页面管理页面
|
||||
*
|
||||
* @param model model
|
||||
*
|
||||
* @return 模板路径admin/admin_page
|
||||
*/
|
||||
@GetMapping
|
||||
|
@ -102,7 +102,6 @@ public class PageController {
|
|||
*
|
||||
* @param model model
|
||||
* @param linkId linkId 友情链接编号
|
||||
*
|
||||
* @return String 模板路径admin/admin_page_link
|
||||
*/
|
||||
@GetMapping(value = "/links/edit")
|
||||
|
@ -116,7 +115,6 @@ public class PageController {
|
|||
* 处理添加/修改友链的请求并渲染页面
|
||||
*
|
||||
* @param link Link实体
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/links/save")
|
||||
|
@ -138,7 +136,6 @@ public class PageController {
|
|||
* 处理删除友情链接的请求并重定向
|
||||
*
|
||||
* @param linkId 友情链接编号
|
||||
*
|
||||
* @return 重定向到/admin/page/links
|
||||
*/
|
||||
@GetMapping(value = "/links/remove")
|
||||
|
@ -155,17 +152,11 @@ public class PageController {
|
|||
* 图库管理
|
||||
*
|
||||
* @param model model
|
||||
* @param page 当前页码
|
||||
* @param size 每页显示的条数
|
||||
*
|
||||
* @return 模板路径admin/admin_page_gallery
|
||||
*/
|
||||
@GetMapping(value = "/galleries")
|
||||
public String gallery(Model model,
|
||||
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
||||
@RequestParam(value = "size", defaultValue = "18") Integer size) {
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "galleryId");
|
||||
final Pageable pageable = PageRequest.of(page, size, sort);
|
||||
@PageableDefault(size = 18, sort = "galleryId", direction = Sort.Direction.DESC) Pageable pageable) {
|
||||
final Page<Gallery> galleries = galleryService.findAll(pageable);
|
||||
model.addAttribute("galleries", galleries);
|
||||
return "admin/admin_page_gallery";
|
||||
|
@ -175,7 +166,6 @@ public class PageController {
|
|||
* 保存图片
|
||||
*
|
||||
* @param gallery gallery
|
||||
*
|
||||
* @return 重定向到/admin/page/gallery
|
||||
*/
|
||||
@PostMapping(value = "/gallery/save")
|
||||
|
@ -196,7 +186,6 @@ public class PageController {
|
|||
*
|
||||
* @param model model
|
||||
* @param galleryId 图片编号
|
||||
*
|
||||
* @return 模板路径admin/widget/_gallery-detail
|
||||
*/
|
||||
@GetMapping(value = "/gallery")
|
||||
|
@ -210,7 +199,6 @@ public class PageController {
|
|||
* 删除图库中的图片
|
||||
*
|
||||
* @param galleryId 图片编号
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/gallery/remove")
|
||||
|
@ -229,7 +217,6 @@ public class PageController {
|
|||
* 跳转到新建页面
|
||||
*
|
||||
* @param model model
|
||||
*
|
||||
* @return 模板路径admin/admin_page_md_editor
|
||||
*/
|
||||
@GetMapping(value = "/new")
|
||||
|
@ -281,7 +268,6 @@ public class PageController {
|
|||
*
|
||||
* @param pageId 页面编号
|
||||
* @param model model
|
||||
*
|
||||
* @return admin/admin_page_md_editor
|
||||
*/
|
||||
@GetMapping(value = "/edit")
|
||||
|
@ -297,7 +283,6 @@ public class PageController {
|
|||
* 检查该路径是否已经存在
|
||||
*
|
||||
* @param postUrl postUrl
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/checkUrl")
|
||||
|
|
|
@ -15,7 +15,6 @@ import cc.ryanc.halo.utils.HaloUtils;
|
|||
import cc.ryanc.halo.utils.LocaleMessageUtil;
|
||||
import cc.ryanc.halo.utils.MarkdownUtils;
|
||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
|
@ -23,9 +22,8 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.propertyeditors.CustomDateEditor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.ServletRequestDataBinder;
|
||||
|
@ -38,6 +36,8 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 后台文章管理控制器
|
||||
|
@ -83,17 +83,12 @@ public class PostController extends BaseController {
|
|||
* 处理后台获取文章列表的请求
|
||||
*
|
||||
* @param model model
|
||||
* @param page 当前页码
|
||||
* @param size 每页显示的条数
|
||||
* @return 模板路径admin/admin_post
|
||||
*/
|
||||
@GetMapping
|
||||
public String posts(Model model,
|
||||
@RequestParam(value = "status", defaultValue = "0") Integer status,
|
||||
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
||||
@RequestParam(value = "size", defaultValue = "10") Integer size) {
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
final Pageable pageable = PageRequest.of(page, size, sort);
|
||||
@PageableDefault(sort = "postDate", direction = DESC) Pageable pageable) {
|
||||
final Page<Post> posts = postService.findPostByStatus(status, PostTypeEnum.POST_TYPE_POST.getDesc(), pageable);
|
||||
model.addAttribute("posts", posts);
|
||||
model.addAttribute("publishCount", postService.getCountByStatus(PostStatusEnum.PUBLISHED.getCode()));
|
||||
|
@ -108,19 +103,13 @@ public class PostController extends BaseController {
|
|||
*
|
||||
* @param model Model
|
||||
* @param keyword keyword 关键字
|
||||
* @param page page 当前页码
|
||||
* @param size size 每页显示条数
|
||||
* @return 模板路径admin/admin_post
|
||||
*/
|
||||
@PostMapping(value = "/search")
|
||||
public String searchPost(Model model,
|
||||
@RequestParam(value = "keyword") String keyword,
|
||||
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
||||
@RequestParam(value = "size", defaultValue = "10") Integer size) {
|
||||
@PageableDefault(sort = "postId", direction = DESC) Pageable pageable) {
|
||||
try {
|
||||
//排序规则
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "postId");
|
||||
final Pageable pageable = PageRequest.of(page, size, sort);
|
||||
model.addAttribute("posts", postService.searchPosts(keyword, PostTypeEnum.POST_TYPE_POST.getDesc(), PostStatusEnum.PUBLISHED.getCode(), pageable));
|
||||
} catch (Exception e) {
|
||||
log.error("未知错误:{}", e.getMessage());
|
||||
|
|
|
@ -14,8 +14,12 @@ import org.springframework.data.domain.Page;
|
|||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.data.web.SortDefault;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 文章API
|
||||
|
@ -95,12 +99,10 @@ public class ApiPostController {
|
|||
* </p>
|
||||
*
|
||||
* @param page 页码
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/page/{page}")
|
||||
public JsonResult posts(@PathVariable(value = "page") Integer page) {
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
public JsonResult posts(@PathVariable(value = "page") Integer page, @SortDefault(sort = "postDate", direction = DESC) Sort sort) {
|
||||
int size = 10;
|
||||
if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) {
|
||||
size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()));
|
||||
|
@ -147,7 +149,6 @@ public class ApiPostController {
|
|||
* </p>
|
||||
*
|
||||
* @param postId 文章编号
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/{postId}")
|
||||
|
|
|
@ -41,7 +41,6 @@ public class CommonController implements ErrorController {
|
|||
/**
|
||||
* 渲染404页面
|
||||
*
|
||||
* @param model model
|
||||
* @return String
|
||||
*/
|
||||
@GetMapping(value = "/404")
|
||||
|
@ -52,7 +51,6 @@ public class CommonController implements ErrorController {
|
|||
/**
|
||||
* 渲染500页面
|
||||
*
|
||||
* @param model model
|
||||
* @return String
|
||||
*/
|
||||
@GetMapping(value = "/500")
|
||||
|
|
|
@ -85,8 +85,6 @@ public class InstallController {
|
|||
* 执行安装
|
||||
*
|
||||
* @param blogLocale 系统语言
|
||||
* @param siteTitle 博客标题
|
||||
* @param siteUrl 博客网址
|
||||
* @param userName 用户名
|
||||
* @param userDisplayName 用户名显示名
|
||||
* @param userEmail 用户邮箱
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.springframework.data.domain.Page;
|
|||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.SortDefault;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -33,6 +34,8 @@ import java.util.ArrayList;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 前台文章归档控制器
|
||||
|
@ -62,7 +65,7 @@ public class FrontArchiveController extends BaseController {
|
|||
*/
|
||||
@GetMapping
|
||||
public String archives(Model model) {
|
||||
return this.archives(model, 1);
|
||||
return this.archives(model, 1, Sort.by(DESC, "postDate"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,10 +77,9 @@ public class FrontArchiveController extends BaseController {
|
|||
*/
|
||||
@GetMapping(value = "page/{page}")
|
||||
public String archives(Model model,
|
||||
@PathVariable(value = "page") Integer page) {
|
||||
|
||||
@PathVariable(value = "page") Integer page,
|
||||
@SortDefault(sort = "postDate", direction = DESC) Sort sort) {
|
||||
//所有文章数据,分页,material主题适用
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
final Pageable pageable = PageRequest.of(page - 1, 5, sort);
|
||||
final Page<Post> posts = postService.findPostByStatus(PostStatusEnum.PUBLISHED.getCode(), PostTypeEnum.POST_TYPE_POST.getDesc(), pageable);
|
||||
if (null == posts) {
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.springframework.data.domain.Page;
|
|||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.SortDefault;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -22,6 +23,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 前台文章分类控制器
|
||||
|
@ -44,7 +47,6 @@ public class FrontCategoryController extends BaseController {
|
|||
* 分类列表页面
|
||||
*
|
||||
* @param model model
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
@GetMapping
|
||||
|
@ -59,13 +61,12 @@ public class FrontCategoryController extends BaseController {
|
|||
*
|
||||
* @param model model
|
||||
* @param cateUrl cateUrl
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@GetMapping(value = "{cateUrl}")
|
||||
public String categories(Model model,
|
||||
@PathVariable("cateUrl") String cateUrl) {
|
||||
return this.categories(model, cateUrl, 1);
|
||||
return this.categories(model, cateUrl, 1, Sort.by(DESC, "postDate"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,18 +75,17 @@ public class FrontCategoryController extends BaseController {
|
|||
* @param model model
|
||||
* @param cateUrl 分类目录路径
|
||||
* @param page 页码
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
@GetMapping("{cateUrl}/page/{page}")
|
||||
public String categories(Model model,
|
||||
@PathVariable("cateUrl") String cateUrl,
|
||||
@PathVariable("page") Integer page) {
|
||||
@PathVariable("page") Integer page,
|
||||
@SortDefault(sort = "postDate", direction = DESC) Sort sort) {
|
||||
final Category category = categoryService.findByCateUrl(cateUrl);
|
||||
if (null == category) {
|
||||
return this.renderNotFound();
|
||||
}
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
int size = 10;
|
||||
if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) {
|
||||
size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()));
|
||||
|
|
|
@ -13,12 +13,15 @@ import org.springframework.data.domain.Page;
|
|||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.SortDefault;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 前台首页控制器
|
||||
|
@ -44,7 +47,7 @@ public class FrontIndexController extends BaseController {
|
|||
*/
|
||||
@GetMapping
|
||||
public String index(Model model) {
|
||||
return this.index(model, 1);
|
||||
return this.index(model, 1, Sort.by(DESC, "postDate"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,13 +55,12 @@ public class FrontIndexController extends BaseController {
|
|||
*
|
||||
* @param model model
|
||||
* @param page 当前页码
|
||||
* @param size 每页数量
|
||||
* @return 模板路径/themes/{theme}/index
|
||||
*/
|
||||
@GetMapping(value = "page/{page}")
|
||||
public String index(Model model,
|
||||
@PathVariable(value = "page") Integer page) {
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
@PathVariable(value = "page") Integer page,
|
||||
@SortDefault(sort = "postDate", direction = DESC) Sort sort) {
|
||||
//默认显示10条
|
||||
int size = 10;
|
||||
if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) {
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.springframework.data.domain.Page;
|
|||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.SortDefault;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -23,6 +24,8 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 文章检索
|
||||
|
@ -49,7 +52,7 @@ public class FrontSearchController extends BaseController {
|
|||
@GetMapping
|
||||
public String search(Model model,
|
||||
@RequestParam(value = "keyword") String keyword) {
|
||||
return this.search(model, HtmlUtil.escape(keyword), 1);
|
||||
return this.search(model, HtmlUtil.escape(keyword), 1, Sort.by(DESC, "postDate"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,14 +66,14 @@ public class FrontSearchController extends BaseController {
|
|||
@GetMapping(value = "page/{page}")
|
||||
public String search(Model model,
|
||||
@RequestParam(value = "keyword") String keyword,
|
||||
@PathVariable(value = "page") Integer page) {
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
@PathVariable(value = "page") Integer page,
|
||||
@SortDefault(sort = "postDate", direction = DESC) Sort sort) {
|
||||
int size = 10;
|
||||
if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) {
|
||||
size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()));
|
||||
}
|
||||
final Pageable pageable = PageRequest.of(page - 1, size, sort);
|
||||
final Page<Post> posts = postService.searchPosts(HtmlUtil.escape(keyword),PostTypeEnum.POST_TYPE_POST.getDesc(),PostStatusEnum.PUBLISHED.getCode(),pageable);
|
||||
final Page<Post> posts = postService.searchPosts(HtmlUtil.escape(keyword), PostTypeEnum.POST_TYPE_POST.getDesc(), PostStatusEnum.PUBLISHED.getCode(), pageable);
|
||||
final int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
|
||||
model.addAttribute("is_search", true);
|
||||
model.addAttribute("keyword", keyword);
|
||||
|
|
|
@ -14,12 +14,15 @@ import org.springframework.data.domain.Page;
|
|||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.SortDefault;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 前台标签控制器
|
||||
|
@ -53,13 +56,12 @@ public class FrontTagController extends BaseController {
|
|||
*
|
||||
* @param tagUrl 标签路径
|
||||
* @param model model
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
@GetMapping(value = "{tagUrl}")
|
||||
public String tags(Model model,
|
||||
@PathVariable("tagUrl") String tagUrl) {
|
||||
return this.tags(model, tagUrl, 1);
|
||||
return this.tags(model, tagUrl, 1, Sort.by(DESC, "postDate"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,18 +70,17 @@ public class FrontTagController extends BaseController {
|
|||
* @param model model
|
||||
* @param tagUrl 标签路径
|
||||
* @param page 页码
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
@GetMapping(value = "{tagUrl}/page/{page}")
|
||||
public String tags(Model model,
|
||||
@PathVariable("tagUrl") String tagUrl,
|
||||
@PathVariable("page") Integer page) {
|
||||
@PathVariable("page") Integer page,
|
||||
@SortDefault(sort = "postDate", direction = DESC) Sort sort) {
|
||||
final Tag tag = tagService.findByTagUrl(tagUrl);
|
||||
if (null == tag) {
|
||||
return this.renderNotFound();
|
||||
}
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
int size = 10;
|
||||
if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) {
|
||||
size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()));
|
||||
|
|
Loading…
Reference in New Issue