/** 跳转到博客详情页面 */ public void detail() { try { String blogCode = getPara(); if (QStringUtil.notEmpty(blogCode)) { BlogArticleModel blog = BlogArticleModel.dao.findByCode(blogCode); blog.set("blog_article_read_times", ((Integer) blog.get("blog_article_read_times") + 1)) .update(); setAttr("blog", blog); setAttr("prevBlog", getBlog("prev", blog)); setAttr("nextBlog", getBlog("next", blog)); render("/WEB-INF/view/fore/blog/blog-detail.html"); return; } } catch (Exception e) { e.printStackTrace(); } redirect("/blog/list"); }
private BlogArticleModel getBlog(String type, BlogArticleModel blog) { BlogArticleModel theBlog = null; try { String sql = null; if ("prev".equals(type)) sql = "select * from t_blog_article where id = (select max(id) from t_blog_article where id<? and blog_type_id=?)"; if ("next".equals(type)) sql = "select * from t_blog_article where id = (select min(id) from t_blog_article where id>? and blog_type_id=?)"; theBlog = BlogArticleModel.dao.findFirst(sql, blog.getInt("id"), blog.getInt("blog_type_id")); } catch (Exception e) { e.printStackTrace(); } return theBlog != null ? theBlog : new BlogArticleModel() .set("id", 0) .set("blog_article_title", "没有了~") .set("blog_article_code", "null"); }