基于javaweb+mysql的ssm+maven个人博客管理系统(java+ssm+js+jsp+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM+Maven个人博客管理系统(java+ssm+js+jsp+mysql)
项目介绍
管理员角色包含以下功能: 发表文章,查看文章,类别管理,添加类别,个人信息管理,评论管理,评论审核等功能。
用户角色包含以下功能: 首页,博客详情,文章分类,评论等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本;
技术栈
- 后端:Spring+SpringMVC+Mybatis 2. 前端:HTML+CSS+JavaScript+jsp
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中application.yml配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/ 登录
param.append(isPass == null ? "" : "&isPass=" + isPass);
String pageCode = PageUtils.genPagination(request.getContextPath() + "/comment/list.do",
pageBean, param.toString());
model.addAttribute("pageCode", pageCode);
model.addAttribute("entry", params);
model.addAttribute("commentList", commentList);
return "comment/list";
}
@RequestMapping("/toAdd")
public String toAdd() {
return "comment/add";
}
@RequestMapping("/detail")
public String detail(Integer id,Model model){
model.addAttribute("comment", commentService.findById(id));
return "comment/detail";
}
//评论审核
@RequestMapping("/audit")
public void audit(Comment comment, HttpServletResponse response) {
comment.setReplyDate(new Date());
int result = commentService.audit(comment);
JSONObject jsonObj = new JSONObject();
jsonObj.put("success", result > 0);
ResponseUtils.writeJson(response, jsonObj.toString());
}
@RequestMapping("/delete")
public String delete(Integer id) throws IOException{
commentService.delete(id);
return "redirect:/comment/list.do";
}
@RequestMapping("/deletes")
public String deletes(String ids) {
String[] idArr = org.springframework.util.StringUtils.commaDelimitedListToStringArray(ids);
int len = idArr.length;
Integer[] commentIds = new Integer[len];
for (int i = 0; i < len; i++) {
}
}
@Controller
@RequestMapping("/blogger")
public @Slf4j class BloggerAdminController {
@Resource
private CommentService commentService;
@Resource
private BloggerService bloggerService;
@RequestMapping("/toModifyInfo")
public String toModifyInfo(Model model) {
model.addAttribute("blogger", bloggerService.find());
return "blogger/modifyInfo";
}
@RequestMapping("/toModifyPassword")
public String toModifyPassword() {
Model model, HttpServletRequest request) {
int totalCount = blogTypeService.getCount();
PageBean pageBean = new PageBean(totalCount, page, pageSize);
Map<String, Object> params = new HashMap<>(2);
params.put("start", pageBean.getStart());
params.put("size", pageSize);
List<BlogType> blogTypeList = blogTypeService.getTypeList(params);
blogTypeList.forEach(blogType -> {
Map<String, Object> types = new HashMap<>(1);
types.put("typeId", blogType.getTypeId());
Integer blogCount = blogService.getCount(types);
blogType.setBlogCount(blogCount);
});
model.addAttribute("pagination", pageBean);
String targetUrl = request.getContextPath() + "/blogType/list.do";
String pageCode = PageUtils.genPagination(targetUrl, pageBean, "");
model.addAttribute("pageCode", pageCode);
model.addAttribute("entry", params);
model.addAttribute("blogTypeList", blogTypeList);
return "blogType/list";
}
@RequestMapping("/toAdd")
public String toAdd() {
return "blogType/add";
}
@RequestMapping("/toUpdate")
public String toUpdate(Integer id,Model model) {
model.addAttribute("blogType", blogTypeService.findById(id));
return "blogType/update";
}
@RequestMapping("/add")
public void add(BlogType blogType,Model model) {
int result = blogTypeService.add(blogType);
model.addAttribute("msg", result > 0 ? "保存成功" : "保存失败");
}
@RequestMapping("/update")
public void update(BlogType blogType,Model model) {
int result = blogTypeService.update(blogType);
model.addAttribute("msg", result > 0 ? "保存成功" : "保存失败");
}
@RequestMapping("/search")
public void search(Integer id,HttpServletResponse response){
JSONObject jsonObj = new JSONObject();
Map<String, Object> map = new HashMap<>(1);
map.put("typeId", id);
jsonObj.put("count", blogService.getCount(map));
@Controller
@RequestMapping("/admin")
public @Slf4j class SysLoginOrOutController {
@Resource
private BloggerService bloggerService;
@RequestMapping("/{page}")
public String page(@PathVariable String page) {
return page;
}
@RequestMapping("/logout")
public String logout() {
ShiroUtils.logout();
return "login";
}
//登录
@RequestMapping("/userLogin")
public void login(String username, String password, HttpServletResponse response) {
try {
// shiro 登录
Subject subject = SecurityUtils.getSubject();
if (!subject.isAuthenticated()) {
if (log.isDebugEnabled()) {
log.debug("执行 shiro 登录操作...");
}
subject.login(new UsernamePasswordToken(username, ShiroUtils.encryptPassword(password)));
}
} catch (UnknownAccountException | IncorrectCredentialsException e) {
ResponseUtils.writeText(response, "用户名或密码错误");
} catch (Exception e) {
ResponseUtils.writeText(response, "登录失败");
}
model.addAttribute("blogTypeList", blogTypeService.getTypeList());
Blog blog = blogService.findById(id);
model.addAttribute("blog", blog);
BlogType blogType = blog.getBlogType();
if(blogType != null){
model.addAttribute("typeId", blogType.getTypeId());
}
return "blog/update";
}
@RequestMapping("/add")
public void add(Blog blog, @RequestParam(value = "img") MultipartFile file,
Model model) throws Exception {
// 获取原始文件名
String fileName = file.getOriginalFilename();
int index = fileName.indexOf(".");
String imageUrl = null;
String imagePath = DateUtils.getTimeStrForImage();
if (index != -1) {
//生成新文件名
imageUrl = imagePath + fileName.substring(index);
log.info("add {}", imagePath);
handleFileUpload(file, imageUrl);
blog.setImage(imageUrl);
}
// 添加博客及索引
int result = blogService.add(blog);
model.addAttribute("msg", result > 0 ? "保存成功" : "保存失败");
}
@RequestMapping("/update")
public void update(Blog blog, @RequestParam(value = "img", required=false) MultipartFile file,
Model model) throws Exception {
if (file != null) { //上传图片
// 获取原始文件名
String fileName = file.getOriginalFilename();
int index = fileName.indexOf(".");
String imageUrl = null;
StringBuilder pageCode = new StringBuilder();
if (lastBlog == null || lastBlog.getId() == null) {
pageCode.append("<p>上一篇:没有了</p>");
} else {
pageCode.append("<p>上一篇:<a href='" + projectContext + "/blog/articles/"
+ lastBlog.getId() + ".shtml'>" + lastBlog.getTitle() + "</a></p>");
}
if (nextBlog == null || nextBlog.getId() == null) {
pageCode.append("<p>下一篇:没有了</p>");
} else {
pageCode.append("<p>下一篇:<a href='" + projectContext + "/blog/articles/"
+ nextBlog.getId() + ".shtml'>" + nextBlog.getTitle() + "</a></p>");
}
return pageCode.toString();
}
}
private BlogService blogService;
@Resource
private CommentService commentService;
@Resource
private BlogTypeService blogTypeService;
/**
* 获取博客详细信息
* @param id
* @param model
* @param request
* @return
*/
@RequestMapping("/articles/{id}")
public String detail(@PathVariable Integer id, Model model, HttpServletRequest request){
Blog blog = blogService.findById(id);
if (Objects.isNull(blog)) {
return "blog/detail";
}
// 文章浏览数加一
blog = blogService.increaseReading(id);
String desc = StringUtils.escapeHtml(blog.getSummary());
model.addAttribute("blog", blog);
model.addAttribute("description", desc.length() > 100 ? desc.substring(0, 100) : desc);
String keyword = blog.getKeyword();
if(!StringUtils.isEmpty(keyword)){
String[] keywords = keyword.split("\\s+");
model.addAttribute("keywords", Arrays.asList(keywords));
model.addAttribute("pageKeywords", String.join(",", keywords));
}
Map<String,Object> map = new HashMap<String,Object>(2);
map.put("blogId", id);
map.put("isPass", 1);
//获取评论列表
model.addAttribute("commentList", commentService.getCommentList(map));
model.addAttribute("pageCode", this.genLastandNextBlogCode(blogService.getLastBlog(id),
blogService.getNextBlog(id),request.getContextPath()));
return "blog/detail";
@Resource
private BlogTypeService blogTypeService;
@Resource
private LinkService linkService;
@Resource
private BlogIndex blogIndex;
@RequestMapping("/index")
public String index(@RequestParam(defaultValue = "1") Integer page,
Model model, HttpServletRequest request) throws Exception {
Map<String, Object> map = new HashMap<String, Object>(2);
int totalCount = blogService.getCount(map);
int pageSize = Constants.FRONT_PAGE_SIZE;
PageBean pageBean = new PageBean(totalCount, page, pageSize);
map.put("start", pageBean.getStart());
map.put("size", pageSize);
List<Blog> blogList = blogService.getBlogList(map);
// 去除摘要中的html标签,防止浏览器解析
blogList.forEach(blog -> blog.setSummary(StringUtils.escapeHtml(blog.getSummary())));
model.addAttribute("blogList", blogList);
String pageCode = PageUtils.genPagination(request.getContextPath() + "/index.shtml", pageBean, "");
model.addAttribute("pageCode", pageCode);
model.addAttribute("totalCount", totalCount);
model.addAttribute("title", "我的文章");
ServletContext application = request.getServletContext();
List<BlogType> blogTypeList = blogTypeService.getTypeList();
blogTypeList.forEach(blogType -> {
Map<String, Object> paramMap = new HashMap<String, Object>(1);
paramMap.put("typeId", blogType.getTypeId());
blogType.setBlogCount(blogService.getCount(paramMap));
});
application.setAttribute("blogTypeList", blogTypeList);
application.setAttribute("dateRankList", blogService.getByDate());
application.setAttribute("readingRankList", blogService.getTopReading());
application.setAttribute("reviewRankList", blogService.getTopReview());
}
}
@Controller
@RequestMapping("/comment")
public class CommentController {
@Resource
private UserMapper userMapper;
@Resource
private CommentService commentService;
/**
* 用户评论
* @param comment
* @param user
* @param response
*/
@RequestMapping("/save")
public void save(String vCode, Integer blogId, Comment comment, User user,
HttpServletResponse response, HttpSession session) {
String validateCode = (String) session.getAttribute(Constants.VALIDATE_CODE);
JSONObject jsonObj = new JSONObject();
if (StringUtils.isEmpty(validateCode) || !validateCode.equalsIgnoreCase(vCode)) {
jsonObj.put("success", false);
jsonObj.put("errorInfo", "验证码错误");
ResponseUtils.writeJson(response, jsonObj.toString());
return;
}
@WebServlet(urlPatterns = "/vCode.jpg")
public class ValidateCodeServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final char[] CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int width = 70, height = 30;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
Random random = new Random();
g.setColor(getRandColor(200, 250));
g.fillRect(0, 0, width, height);
g.setFont(new Font("Times New Roman", Font.PLAIN, 22));
g.setColor(getRandColor(160, 200));
for (int i = 0; i < 155; i++) {
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt(12);
int yl = random.nextInt(20);
g.drawLine(x, y, x + xl, y + yl);
}
StringBuilder validateCode = new StringBuilder();
for (int i = 0; i < 4; i++) {
String rand = String.valueOf(CHARS[random.nextInt(CHARS.length)]);
validateCode.append(rand);
g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
g.drawString(rand, 15 * i + 6, 22);
}
g.dispose();
// 将验证码存入Session中
request.getSession(false).setAttribute(Constants.VALIDATE_CODE, validateCode.toString());
// 禁止图像缓存
response.setHeader(HttpHeaders.CACHE_CONTROL, "no-store, no-cache");
response.setContentType(MimeTypeUtils.IMAGE_JPEG_VALUE);
try (OutputStream os = response.getOutputStream()) {
// 以流的形式输出到页面
ImageIO.write(image, "JPEG", os);
return "blogger/modifyInfo";
}
@RequestMapping("/toModifyPassword")
public String toModifyPassword() {
return "blogger/modifyPassword";
}
@RequestMapping("/modifyInfo")
public void modifyInfo(Blogger blogger,
@RequestParam(value = "img", required = false) MultipartFile file,
Model model) throws Exception {
if (file != null) { //上传图片
// 获取原始文件名
String fileName = file.getOriginalFilename();
int index = fileName.indexOf(".");
String imageUrl = null;
if (index != -1) {
// 生成新文件名
imageUrl = DateUtils.getTimeStrForImage() + fileName.substring(index);
handleFileUpload(file, imageUrl);
blogger.setImageUrl(imageUrl);
}
}
int result = bloggerService.update(blogger);
model.addAttribute("msg", result > 0 ? "保存成功" : "保存失败");
}
@RequestMapping("/modifyPassword")
public void modifyPassword(String newpwd, String oldpwd, String repwd, HttpServletResponse response,
HttpServletRequest request) {
Blogger blogger = bloggerService.find();
if (!blogger.getPassword().equals(ShiroUtils.encryptPassword(oldpwd))) {
ResponseUtils.writeText(response, "原密码输入不正确");
return;
}
if (!newpwd.equals(repwd)) {
ResponseUtils.writeText(response, "两次密码输入不一致");
return;
}
blogger.setPassword(ShiroUtils.encryptPassword(newpwd));
bloggerService.update(blogger);
ResponseUtils.writeText(response, "修改成功");
}
private void handleFileUpload(MultipartFile file,String imageUrl) {
try (InputStream is = file.getInputStream()) {
// 获取输入流
String filePath = Thread.currentThread().getContextClassLoader().getResource("").getPath().substring(0,Thread.currentThread().getContextClassLoader().getResource("").getPath().length()-16)+Constants.AVATAR_DIR + imageUrl;
File dir = new File(filePath.substring(0, filePath.lastIndexOf("/")));
public String toAdd(Model model) {
model.addAttribute("blogTypeList", blogTypeService.getTypeList());
return "blog/add";
}
@RequestMapping("/toUpdate")
public String toUpdate(Integer id, Model model) {
model.addAttribute("blogTypeList", blogTypeService.getTypeList());
Blog blog = blogService.findById(id);
model.addAttribute("blog", blog);
BlogType blogType = blog.getBlogType();
if(blogType != null){
model.addAttribute("typeId", blogType.getTypeId());
}
return "blog/update";
}
@RequestMapping("/add")
public void add(Blog blog, @RequestParam(value = "img") MultipartFile file,
Model model) throws Exception {
// 获取原始文件名
String fileName = file.getOriginalFilename();
int index = fileName.indexOf(".");
String imageUrl = null;
String imagePath = DateUtils.getTimeStrForImage();
if (index != -1) {
//生成新文件名
imageUrl = imagePath + fileName.substring(index);
log.info("add {}", imagePath);
handleFileUpload(file, imageUrl);
blog.setImage(imageUrl);
}
// 添加博客及索引
int result = blogService.add(blog);
model.addAttribute("msg", result > 0 ? "保存成功" : "保存失败");
}
@RequestMapping("/update")
public void update(Blog blog, @RequestParam(value = "img", required=false) MultipartFile file,
Model model) throws Exception {
if (file != null) { //上传图片
try (InputStream is = file.getInputStream()) {
// 获取输入流
String filePath = Thread.currentThread().getContextClassLoader().getResource("").getPath().substring(0,Thread.currentThread().getContextClassLoader().getResource("").getPath().length()-16)+Constants.AVATAR_DIR + imageUrl;
File dir = new File(filePath.substring(0, filePath.lastIndexOf("/")));
//判断上传目录是否存在
if (!dir.exists()) {
dir.mkdirs();
}
try (FileOutputStream fos = new FileOutputStream(new File(filePath))) {
byte[] buffer = new byte[1024];
int len = 0;
// 读取输入流中的内容
while ((len = is.read(buffer)) != -1) {
fos.write(buffer, 0, len);
}
}
} catch (Exception e) {
log.error("图片上传失败", e);
}
}
}
/**
* 博客Controller
*/
@Controller
@RequestMapping("/blog")
public class BlogController {
@Resource
private BlogService blogService;
@Resource
private CommentService commentService;
@Resource
private BlogTypeService blogTypeService;
/**
* 获取博客详细信息
* @param id
* @param model
* @param request
* @return
*/
@RequestMapping("/articles/{id}")
public String detail(@PathVariable Integer id, Model model, HttpServletRequest request){
Blog blog = blogService.findById(id);
if (Objects.isNull(blog)) {
return "blog/detail";
}
// 文章浏览数加一
blog = blogService.increaseReading(id);
String desc = StringUtils.escapeHtml(blog.getSummary());
model.addAttribute("blog", blog);
model.addAttribute("description", desc.length() > 100 ? desc.substring(0, 100) : desc);
String keyword = blog.getKeyword();
if(!StringUtils.isEmpty(keyword)){
String[] keywords = keyword.split("\\s+");
model.addAttribute("keywords", Arrays.asList(keywords));
model.addAttribute("pageKeywords", String.join(",", keywords));
}
Map<String,Object> map = new HashMap<String,Object>(2);
map.put("blogId", id);
map.put("isPass", 1);
//获取评论列表
model.addAttribute("commentList", commentService.getCommentList(map));
model.addAttribute("pageCode", this.genLastandNextBlogCode(blogService.getLastBlog(id),
blogService.getNextBlog(id),request.getContextPath()));
return "blog/detail";
}
model.addAttribute("blogList", blogList);
// 分页参数
StringBuffer param = new StringBuffer();
param.append(typeId == null ? "" : "cat=" + typeId);
param.append(StringUtils.isEmpty(month) ? "" : "month=" + month);
String pageCode = PageUtils.genPagination(request.getContextPath() + "/blog.shtml",
pageBean, param.toString());
model.addAttribute("pageCode", pageCode);
model.addAttribute("totalCount", totalCount);
if (typeId != null) {
String typeName = blogTypeService.findById(typeId).getTypeName();
model.addAttribute("title", "文章分类 - " + typeName);
model.addAttribute("pageTitle", typeName + " - 文章分类 - Promising的博客" );
}
if (StringUtils.isNotEmpty(month)) {
month = String.format("%s年%s月", month.substring(0, 4), month.substring(4));
model.addAttribute("title", "文章存档 - " + month);
model.addAttribute("pageTitle", month + " - 文章存档 - Promising的博客" );
}
return "blog/list";
}
/**
* 获取下一篇博客和下一篇博客分页代码
* @param lastBlog
* @param nextBlog
* @return
*/
private String genLastandNextBlogCode(Blog lastBlog, Blog nextBlog, String projectContext) {
StringBuilder pageCode = new StringBuilder();
if (lastBlog == null || lastBlog.getId() == null) {
pageCode.append("<p>上一篇:没有了</p>");
} else {
pageCode.append("<p>上一篇:<a href='" + projectContext + "/blog/articles/"
+ lastBlog.getId() + ".shtml'>" + lastBlog.getTitle() + "</a></p>");
}
if (nextBlog == null || nextBlog.getId() == null) {
pageCode.append("<p>下一篇:没有了</p>");
} else {
pageCode.append("<p>下一篇:<a href='" + projectContext + "/blog/articles/"
+ nextBlog.getId() + ".shtml'>" + nextBlog.getTitle() + "</a></p>");
}
return pageCode.toString();
}
}
model.addAttribute("title", typeName);
return "blog/list";
}
/**
* 根据关键词查询博客
* @throws Exception
*/
@RequestMapping("/search")
public String search(@RequestParam(defaultValue = "1") Integer page, String q,
Model model, HttpServletRequest request) throws Exception {
if ("POST".equals(request.getMethod())) { // 判断是否是表单提交,post方式
// 解决表单提交中文乱码
q = new String(q);
}
if(q != null) {
// URL解码,防止特殊字符
q = URLDecoder.decode(q, StandardCharsets.UTF_8.name());
}
// 转义特殊字符,防止lucene报异常
String kwd = QueryParser.escape(q);
List<Blog> blogList = blogIndex.query(kwd);
// 分页显示
int totalCount = blogList.size();
int pageSize = Constants.DEFAULT_PAGE_SIZE;
PageBean pageBean = new PageBean(totalCount, page, pageSize);
int fromIndex = pageBean.getStart();
int toIndex = Math.min(totalCount, fromIndex + pageSize);
model.addAttribute("blogList", blogList.subList(fromIndex, toIndex));
model.addAttribute("resultCount", totalCount);
String pageCode = PageUtils.genPagination(request.getContextPath() + "/search.shtml",
pageBean, StringUtils.isEmpty(q) ? "" : "q=" + q);
model.addAttribute("pageCode", pageCode);
q = StringEscapeUtils.escapeHtml4(q);
model.addAttribute("q", q);
model.addAttribute("pageKeywords", q + "," + Constants.DEFAULT_KEYWORDS);
return "blog/result";
}
}
Blog blog = blogService.findById(id);
if (Objects.isNull(blog)) {
return "blog/detail";
}
// 文章浏览数加一
blog = blogService.increaseReading(id);
String desc = StringUtils.escapeHtml(blog.getSummary());
model.addAttribute("blog", blog);
model.addAttribute("description", desc.length() > 100 ? desc.substring(0, 100) : desc);
String keyword = blog.getKeyword();
if(!StringUtils.isEmpty(keyword)){
String[] keywords = keyword.split("\\s+");
model.addAttribute("keywords", Arrays.asList(keywords));
model.addAttribute("pageKeywords", String.join(",", keywords));
}
Map<String,Object> map = new HashMap<String,Object>(2);
map.put("blogId", id);
map.put("isPass", 1);
//获取评论列表
model.addAttribute("commentList", commentService.getCommentList(map));
model.addAttribute("pageCode", this.genLastandNextBlogCode(blogService.getLastBlog(id),
blogService.getNextBlog(id),request.getContextPath()));
return "blog/detail";
}
/**
* 获取分类博客列表
* @param id
* @param model
* @param request
* @return
*/
@RequestMapping
public String typeOrMonth(@RequestParam(value="cat",required=false) Integer typeId,
@RequestParam(required = false) String month,
@RequestParam(defaultValue = "1") Integer page, Model model,HttpServletRequest request){
Map<String, Object> map = new HashMap<String, Object>(4);
map.put("typeId", typeId);
map.put("releaseDate", month);
int totalCount = blogService.getCount(map);
int pageSize = Constants.FRONT_PAGE_SIZE;
PageBean pageBean = new PageBean(totalCount, page, pageSize);
map.put("start", pageBean.getStart());
map.put("size", pageSize);
List<Blog> blogList = blogService.getBlogList(map);
//去除摘要中的html标签,防止浏览器解析
blogList.forEach(blog -> blog.setSummary(StringUtils.escapeHtml(blog.getSummary())));
model.addAttribute("blogList", blogList);
/**
* 博客类别Controller
*/
@Controller
@RequestMapping("/blogType")
public class BlogTypeAdminController {
@Resource
private BlogTypeService blogTypeService;
@Resource
private BlogService blogService;
@RequestMapping("/list")
public String list(@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = Constants.BACK_PAGE_SIZE + 3 + "") Integer pageSize,
Model model, HttpServletRequest request) {
int totalCount = blogTypeService.getCount();
PageBean pageBean = new PageBean(totalCount, page, pageSize);
Map<String, Object> params = new HashMap<>(2);
params.put("start", pageBean.getStart());
params.put("size", pageSize);
List<BlogType> blogTypeList = blogTypeService.getTypeList(params);
blogTypeList.forEach(blogType -> {
Map<String, Object> types = new HashMap<>(1);
types.put("typeId", blogType.getTypeId());
Integer blogCount = blogService.getCount(types);
blogType.setBlogCount(blogCount);
});
model.addAttribute("pagination", pageBean);
String targetUrl = request.getContextPath() + "/blogType/list.do";
String pageCode = PageUtils.genPagination(targetUrl, pageBean, "");
model.addAttribute("pageCode", pageCode);
model.addAttribute("entry", params);
model.addAttribute("blogTypeList", blogTypeList);
return "blogType/list";
}
@RequestMapping("/toAdd")
public String toAdd() {
return "blogType/add";