示例#1
0
  @RequestMapping(value = "updateBlog.do")
  public @ResponseBody String updateBlog(String blogJson, HttpServletRequest request) {
    JSONObject blogObj = JSON.parseObject(blogJson);
    Blog blog = new Blog();
    blog.setId(blogObj.getString("id"));
    blog.setTitle(blogObj.getString("title"));
    blog.setContent(blogObj.getString("content"));

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date = new Date();

    blog.setLastUpdatedAt(sdf.format(date));

    //		blog.setCategories(blogObj.getString("categories"));
    return blogService.updateBlog(blog);
  }
示例#2
0
  @RequestMapping(value = "newBlog.do")
  public @ResponseBody String newBlog(String blogJson, HttpServletRequest request) {
    JSONObject blogObj = JSON.parseObject(blogJson);
    Blog blog = new Blog();
    blog.setTitle(blogObj.getString("title"));
    blog.setContent(blogObj.getString("content"));

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date = new Date();
    blog.setCreatedAt(sdf.format(date));
    blog.setLastUpdatedAt(sdf.format(date));

    User createdBy = (User) request.getSession().getAttribute("user");
    blog.setCreatedBy(createdBy);
    blog.setCategories(blogObj.getString("categories"));
    return blogService.newBlog(blog);
  }
示例#3
0
 @RequestMapping(value = "deleteBlog.do")
 public @ResponseBody String deleteBlog(String id) {
   return blogService.deleteBlog(id);
 }
示例#4
0
 @RequestMapping(value = "getOneBlog.do")
 public @ResponseBody String getOneBlog(String id) {
   String blogJson = JSON.toJSONString(blogService.getBlogById(id));
   return blogJson;
 }
示例#5
0
 @RequestMapping(value = "getBlogsByCategory.do")
 public @ResponseBody String getBlogsByCategory(String category) {
   String allBlogsJson = JSON.toJSONString(blogService.getBlogsByCategory(category));
   return allBlogsJson;
 }