@ResponseBody @RequestMapping(method = RequestMethod.POST) public Object insert(Post post, String tags) { MapContainer form = PostFormValidator.validatePublish(post); if (!form.isEmpty()) { return form.put("success", false); } post.setId(optionManager.getNextPostid()); post.setCreator(WebContextFactory.get().getUser().getId()); post.setCreateTime(new Date()); post.setLastUpdate(post.getCreateTime()); /* 由于加入xss的过滤,html内容都被转义了,这里需要unescape */ String content = HtmlUtils.htmlUnescape(post.getContent()); post.setContent(JsoupUtils.filter(content)); String cleanTxt = JsoupUtils.plainText(content); post.setExcerpt( cleanTxt.length() > PostConstants.EXCERPT_LENGTH ? cleanTxt.substring(0, PostConstants.EXCERPT_LENGTH) : cleanTxt); postManager.insertPost(post, PostTagHelper.from(post, tags, post.getCreator())); return new MapContainer("success", true); }
@RequestMapping(method = RequestMethod.GET) public String index(@RequestParam(value = "page", defaultValue = "1") int page, Model model) { PageModel<PostVO> pageModel = postManager.listPost(page, 15); model.addAttribute("page", pageModel); model.addAttribute("categorys", categoryService.list()); return "backend/post/list"; }
@RequestMapping(value = "/edit", method = RequestMethod.GET) public String edit(String pid, Model model) { if (!StringUtils.isBlank(pid)) { model.addAttribute("post", postManager.loadReadById(pid)); } model.addAttribute("categorys", categoryService.list()); return "backend/post/edit"; }
@ResponseBody @RequestMapping(value = "/fast", method = RequestMethod.PUT) public Object fast(Post post, String tags) { MapContainer form = PostFormValidator.validateFastUpdate(post); if (!form.isEmpty()) { return form.put("success", false); } Post old = postService.loadById(post.getId()); if (old == null) { return form.put("success", false).put("msg", "非法请求"); } post.setContent(old.getContent()); post.setExcerpt(old.getExcerpt()); post.setType(PostConstants.TYPE_POST); post.setLastUpdate(new Date()); postManager.updatePost( post, PostTagHelper.from(post, tags, WebContextFactory.get().getUser().getId()), true); return new MapContainer("success", true); }
@ResponseBody @RequestMapping(value = "/{postid}", method = RequestMethod.DELETE) public Object remove(@PathVariable("postid") String postid) { postManager.removePost(postid, PostConstants.TYPE_POST); return new MapContainer("success", true); }