Skip to content

Commit

Permalink
完成博客信息分页显示
Browse files Browse the repository at this point in the history
  • Loading branch information
YuKongEr committed Apr 17, 2017
1 parent 8f61438 commit 3465f72
Show file tree
Hide file tree
Showing 23 changed files with 833 additions and 61 deletions.
6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/sqldialects.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions src/main/java/ssm/blog/controller/admin/BlogController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package ssm.blog.controller.admin;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import ssm.blog.entity.Blog;
import ssm.blog.entity.PageBean;
import ssm.blog.service.BlogService;
import ssm.blog.util.ResponseUtil;

/**
* @Description 管理员博客Controller层
* @author xp
*
*/
@Controller
@RequestMapping("/admin/blog")
public class BlogController {

@Resource
private BlogService blogService;



//后台分页查询博客信息
@RequestMapping("/listBlog")
public String listBlog(
@RequestParam(value="page", required=false)String page,
@RequestParam(value="rows", required=false)String rows,
Blog s_blog,
HttpServletResponse response) throws Exception {

PageBean<Blog> pageBean = new PageBean<Blog>(Integer.parseInt(page), Integer.parseInt(rows));

pageBean = blogService.listBlog(s_blog.getTitle(),pageBean);


JSONObject result = new JSONObject();
JSON.DEFFAULT_DATE_FORMAT="yyyy-MM-dd";
String jsonStr = JSONObject.toJSONString(pageBean.getResult(),
SerializerFeature.DisableCircularReferenceDetect,
SerializerFeature.WriteDateUseDateFormat);
JSONArray array = JSON.parseArray(jsonStr);
result.put("rows", array);
result.put("total", pageBean.getTotal());
ResponseUtil.write(response, result);
return null;
}


}
45 changes: 45 additions & 0 deletions src/main/java/ssm/blog/controller/admin/BlogTypeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import ssm.blog.entity.BlogType;
import ssm.blog.entity.PageBean;
import ssm.blog.service.BlogService;
import ssm.blog.service.BlogTypeService;
import ssm.blog.util.ResponseUtil;

Expand All @@ -25,6 +26,8 @@ public class BlogTypeController {

@Resource
private BlogTypeService blogTypeService;
@Resource
private BlogService blogService;

// 分页查询博客类别
@RequestMapping("/listBlogType")
Expand All @@ -51,4 +54,46 @@ public String listBlogType(
return null;
}

// 添加和更新博客类别
@RequestMapping("/save")
public String save(BlogType blogType, HttpServletResponse response)
throws Exception {

int resultTotal = 0; // 接收返回结果记录数
if (blogType.getId() == null) { // 说明是第一次插入
resultTotal = blogTypeService.addBlogType(blogType);
} else { // 有id表示修改
resultTotal = blogTypeService.updateBlogType(blogType);
}

JSONObject result = new JSONObject();
if (resultTotal > 0) {
result.put("success", true);
} else {
result.put("success", false);
}
ResponseUtil.write(response, result);
return null;
}

// 博客类别信息删除
@RequestMapping("/delete")
public String deleteBlog(
@RequestParam(value = "ids", required = false) String ids,
HttpServletResponse response) throws Exception {

String[] idsStr = ids.split(",");
JSONObject result = new JSONObject();
for (int i = 0; i < idsStr.length; i++) {
int id = Integer.parseInt(idsStr[i]);
if(blogService.getBlogByTypeId(id) > 0) { //说明该类别中有博客
result.put("exist", "该类别下有博客,不能删除!");
} else {
blogTypeService.deleteBlogType(id);
}
}
result.put("success", true);
ResponseUtil.write(response, result);
return null;
}
}
24 changes: 24 additions & 0 deletions src/main/java/ssm/blog/dao/BlogDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ssm.blog.dao;

import java.util.List;
import java.util.Map;

import ssm.blog.entity.Blog;

/**
* @Description 博客Dao接口
* @author Ni Shengwu
*
*/
public interface BlogDao {


// 分页查询博客
public List<Blog> listBlog(Map<String, Object> map);

// 获取总记录数
public Long getTotal(String title);

// 根据博客类型的id查询该类型下的博客数量
public Integer getBlogByTypeId(Integer typeId);
}
11 changes: 11 additions & 0 deletions src/main/java/ssm/blog/dao/BlogTypeDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

/**
* Created by xp on 2017/4/14.
*
* @author xp
* @Description 博客类别dao
*/
Expand All @@ -17,34 +18,39 @@ public interface BlogTypeDao {

/**
* 添加博客类别信息
*
* @param blogType
* @return
*/
Integer addBlogType(BlogType blogType);

/**
* 删除博客类别信息
*
* @param id
* @return
*/
Integer deleteBlogType(Integer id);

/**
* 更新博客类别信息
*
* @param blogType
* @return
*/
Integer updateBlogType(BlogType blogType);

/**
* 根据id查询博客类别信息
*
* @param id
* @return
*/
BlogType getById(Integer id);

/**
* 分页查询博客类别信息
*
* @param start
* @param end
* @return
Expand All @@ -53,8 +59,13 @@ public interface BlogTypeDao {

/**
* 查询总记录数
*
* @return
*/
Long getTotal();

/**
* 获取博客类别信息
*/
public List<BlogType> getBlogTypeData();
}
134 changes: 134 additions & 0 deletions src/main/java/ssm/blog/entity/Blog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package ssm.blog.entity;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

/**
* @Description 博客实体
* @author Ni Shengwu
*
*/
public class Blog {

private Integer id;
private String title;
private String summary;
private Date releaseDate;
private Integer clickHit;
private Integer replyHit;
private String content;
private String contentNoTag; //不带标签的博客内容,用于Lucene索引中
private String keyWord; //关键字,用空格隔开

private BlogType blogType; //博客类型
private Integer blogCount; //博客数量,非博客实际属性,用于根据发布日期归档查询
private String releaseDateStr; //发布日期的字符串,只取年月

private List<String> imageList = new LinkedList<String>();//博客里存的图片,主要用于展示缩略图

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getSummary() {
return summary;
}

public void setSummary(String summary) {
this.summary = summary;
}

public Date getReleaseDate() {
return releaseDate;
}

public void setReleaseDate(Date releaseDate) {
this.releaseDate = releaseDate;
}

public Integer getClickHit() {
return clickHit;
}

public void setClickHit(Integer clickHit) {
this.clickHit = clickHit;
}

public Integer getReplyHit() {
return replyHit;
}

public void setReplyHit(Integer replyHit) {
this.replyHit = replyHit;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

public String getKeyWord() {
return keyWord;
}

public void setKeyWord(String keyWord) {
this.keyWord = keyWord;
}

public BlogType getBlogType() {
return blogType;
}

public void setBlogType(BlogType blogType) {
this.blogType = blogType;
}

public Integer getBlogCount() {
return blogCount;
}

public void setBlogCount(Integer blogCount) {
this.blogCount = blogCount;
}

public String getReleaseDateStr() {
return releaseDateStr;
}

public void setReleaseDateStr(String releaseDateStr) {
this.releaseDateStr = releaseDateStr;
}

public List<String> getImageList() {
return imageList;
}

public void setImageList(List<String> imageList) {
this.imageList = imageList;
}

public String getContentNoTag() {
return contentNoTag;
}

public void setContentNoTag(String contentNoTag) {
this.contentNoTag = contentNoTag;
}

}
Loading

0 comments on commit 3465f72

Please sign in to comment.