👽 修改某些应该查询不到数据而报500的情况

pull/18/head
RYAN0UP_ 2018-05-15 22:24:10 +08:00
parent 0f65c815fe
commit f920db4f59
6 changed files with 21 additions and 5 deletions

View File

@ -63,6 +63,9 @@ public class FrontArchiveController extends BaseController {
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
Pageable pageable = PageRequest.of(page - 1, 5, sort);
Page<Post> posts = postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable);
if(null==posts){
return "redirect:/404";
}
model.addAttribute("posts", posts);
return this.render("archives");
}
@ -80,6 +83,9 @@ public class FrontArchiveController extends BaseController {
@PathVariable(value = "year") String year,
@PathVariable(value = "month") String month) {
Page<Post> posts = postService.findPostByYearAndMonth(year, month, null);
if(null==posts){
return "redirect:/404";
}
model.addAttribute("posts", posts);
return this.render("archives");
}
@ -94,11 +100,13 @@ public class FrontArchiveController extends BaseController {
@GetMapping(value = "{postUrl}")
public String getPost(@PathVariable String postUrl, Model model) {
Post post = postService.findByPostUrl(postUrl, HaloConst.POST_TYPE_POST);
if(null==post){
return "redirect:/404";
}
//获得当前文章的发布日期
Date postDate = post.getPostDate();
//查询当前文章日期之前的所有文章
List<Post> beforePosts = postService.findByPostDateBefore(postDate);
//查询当前文章日期之后的所有文章
List<Post> afterPosts = postService.findByPostDateAfter(postDate);

View File

@ -67,6 +67,9 @@ public class FrontCategoryController extends BaseController {
@PathVariable("cateUrl") String cateUrl,
@PathVariable("page") Integer page){
Category category = categoryService.findByCateUrl(cateUrl);
if(null==category){
return "redirect:/404";
}
Sort sort = new Sort(Sort.Direction.DESC,"postDate");
Integer size = 10;
if(!StringUtils.isBlank(HaloConst.OPTIONS.get("index_posts"))){

View File

@ -8,7 +8,6 @@ import cc.ryanc.halo.service.MailService;
import cc.ryanc.halo.service.PostService;
import cc.ryanc.halo.service.UserService;
import cc.ryanc.halo.utils.HaloUtils;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -68,6 +68,9 @@ public class FrontIndexController extends BaseController {
//所有文章数据,分页
Pageable pageable = PageRequest.of(page - 1, size, sort);
Page<Post> posts = postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable);
if(null==posts){
return "redirect:/404";
}
model.addAttribute("posts", posts);
return this.render("index");
}

View File

@ -73,7 +73,9 @@ public class FrontPageController extends BaseController {
Sort sort = new Sort(Sort.Direction.DESC,"commentDate");
Pageable pageable = PageRequest.of(0,999,sort);
Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post,pageable,2);
if(null==post){
return "redirect:/404";
}
model.addAttribute("comments",comments);
model.addAttribute("post", post);
return this.render("page");

View File

@ -18,8 +18,6 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
/**
* @author : RYAN0UP
* @version : 1.0
@ -71,6 +69,9 @@ public class FrontTagController extends BaseController {
@PathVariable("tagUrl") String tagUrl,
@PathVariable("page") Integer page) {
Tag tag = tagService.findByTagUrl(tagUrl);
if(null==tag){
return "redirect:/404";
}
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
Integer size = 10;
if (!StringUtils.isBlank(HaloConst.OPTIONS.get("index_posts"))) {