use of com.myblog.model.Category in project newblog by Zephery.
the class BlogServiceImpl method getBlogDetail.
@Override
public Blog getBlogDetail(Integer blogid) {
Blog blog = blogMapper.selectByPrimaryKey(blogid);
if (blog == null) {
return null;
}
Category category = categoryService.selectByPrimaryKey(blog.getCategoryid());
blog.setCategory(category);
List<Tag> tags = tagMapper.getTagByBlogId(blog.getBlogid());
blog.setTags(tags.size() > 0 ? tags : null);
log.info("没有走缓存");
return blog;
}
use of com.myblog.model.Category in project newblog by Zephery.
the class BlogController method to_show_article.
@RequestMapping("/tech")
public ModelAndView to_show_article(HttpServletRequest request) {
// 博客主页
ModelAndView modelAndView = new ModelAndView();
String page = request.getParameter("pagenum");
String categoryid = request.getParameter("categoryid");
String t_id = request.getParameter("tid");
int pagenum;
if (StringUtils.isEmpty(page)) {
pagenum = 1;
} else {
pagenum = Integer.parseInt(page);
}
PageHelper.startPage(pagenum, 15);
List<Blog> lists;
if (StringUtils.isNotEmpty(categoryid)) {
lists = blogService.getByCategoryId(Integer.parseInt(categoryid));
Category category = categoryService.selectByPrimaryKey(Integer.parseInt(categoryid));
modelAndView.addObject("category", category);
} else if (StringUtils.isNotEmpty(t_id)) {
lists = blogService.getBlogByTagId(Integer.parseInt(t_id));
Tag tag = blogService.getTagByTid(Integer.parseInt(t_id));
modelAndView.addObject("tag", tag);
} else {
lists = blogService.getAllTechBlog();
}
for (Blog list : lists) {
try {
// bug fix 2017-11-13
int category_id = list.getCategoryid();
list.setCategory(categoryService.selectByPrimaryKey(category_id));
} catch (Exception e) {
log.error("分类设置" + e);
}
}
PageInfo<Blog> blogs = new PageInfo<>(lists);
Integer startpage, endpage;
if (blogs.getPages() < 6) {
startpage = 1;
endpage = blogs.getPages();
} else {
if (pagenum > 3) {
startpage = blogs.getPageNum() - 3;
endpage = blogs.getPageNum() + 3 > blogs.getPages() ? blogs.getPages() : pagenum + 3;
} else {
startpage = 1;
endpage = blogs.getPageNum() + 4 > blogs.getPages() ? blogs.getPages() : pagenum + 4;
}
}
modelAndView.addObject("startpage", startpage);
modelAndView.addObject("endpage", endpage);
modelAndView.addObject("blogs", blogs.getList());
modelAndView.addObject("totalpages", blogs.getPages());
modelAndView.addObject("pageNum", blogs.getPageNum());
modelAndView.setViewName("tech");
return modelAndView;
}
use of com.myblog.model.Category in project newblog by Zephery.
the class IndexController method getbycategoryid.
@GetMapping(value = "/getjsonbycategories", produces = "application/json;charset=UTF-8")
@ResponseBody
public String getbycategoryid() {
List<Category> categories = categoryService.getAllCatWithoutLife();
Gson gson = new Gson();
return gson.toJson(categories);
}
use of com.myblog.model.Category in project newblog by Zephery.
the class LifeController method toshowarticle.
@RequestMapping("/life")
public ModelAndView toshowarticle(HttpServletRequest request) {
// 生活笔记
String page = request.getParameter("pagenum");
String categoryid = request.getParameter("categoryid");
String t_id = request.getParameter("tid");
Integer pagenum;
if (StringUtils.isEmpty(page)) {
pagenum = 1;
} else {
pagenum = Integer.parseInt(page);
}
PageHelper.startPage(pagenum, 15);
List<Blog> lists;
if (StringUtils.isEmpty(categoryid)) {
lists = blogService.getLife();
} else if (!StringUtils.isEmpty(t_id)) {
lists = blogService.getBlogByTagId(Integer.parseInt(t_id));
} else {
lists = blogService.getByCategoryId(Integer.parseInt(categoryid));
}
ModelAndView modelAndView = new ModelAndView();
for (Blog list : lists) {
try {
int category_id = lists.get(0).getCategoryid();
list.setCategory(categoryService.selectByPrimaryKey(category_id));
} catch (Exception e) {
logger.error("datetimeparse error" + e);
}
}
if (categoryid != null && !categoryid.equals("")) {
Category category = categoryService.selectByPrimaryKey(Integer.parseInt(categoryid));
modelAndView.addObject("category", category);
} else {
if (t_id != null) {
Tag tag = blogService.getTagByTid(Integer.parseInt(t_id));
modelAndView.addObject("tag", tag);
}
}
PageInfo<Blog> blogs = new PageInfo<>(lists);
Integer startpage, endpage;
if (blogs.getPages() < 6) {
startpage = 1;
endpage = blogs.getPages();
} else {
if (pagenum > 3) {
startpage = blogs.getPageNum() - 3;
endpage = blogs.getPageNum() + 3 > blogs.getPages() ? blogs.getPages() : pagenum + 3;
} else {
startpage = 1;
endpage = blogs.getPageNum() + 4 > blogs.getPages() ? blogs.getPages() : pagenum + 4;
}
}
modelAndView.addObject("startpage", startpage);
modelAndView.addObject("endpage", endpage);
modelAndView.addObject("blogs", blogs.getList());
modelAndView.addObject("totalpages", blogs.getPages());
modelAndView.addObject("pageNum", blogs.getPageNum());
modelAndView.setViewName("life");
return modelAndView;
}
use of com.myblog.model.Category in project newblogback by Zephery.
the class BlogController method getpublish.
@GetMapping("/publish")
public ModelAndView getpublish() {
List<Category> categoryList = categoryService.getAllCategory();
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("categories", categoryList);
modelAndView.setViewName("/admin/article_edit");
return modelAndView;
}
Aggregations