Search in sources :

Example 1 with Category

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;
}
Also used : Category(com.myblog.model.Category) Tag(com.myblog.model.Tag) Blog(com.myblog.model.Blog)

Example 2 with Category

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;
}
Also used : PageInfo(com.github.pagehelper.PageInfo) Category(com.myblog.model.Category) ModelAndView(org.springframework.web.servlet.ModelAndView) Tag(com.myblog.model.Tag) Blog(com.myblog.model.Blog) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Category

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);
}
Also used : Category(com.myblog.model.Category) Gson(com.google.gson.Gson) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with Category

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;
}
Also used : PageInfo(com.github.pagehelper.PageInfo) Category(com.myblog.model.Category) ModelAndView(org.springframework.web.servlet.ModelAndView) Tag(com.myblog.model.Tag) Blog(com.myblog.model.Blog) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Category

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;
}
Also used : Category(com.myblog.model.Category) ModelAndView(org.springframework.web.servlet.ModelAndView)

Aggregations

Category (com.myblog.model.Category)8 Blog (com.myblog.model.Blog)5 Tag (com.myblog.model.Tag)5 ModelAndView (org.springframework.web.servlet.ModelAndView)5 PageInfo (com.github.pagehelper.PageInfo)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Gson (com.google.gson.Gson)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1