@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); }
@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); }