@Test public void save_savesCategoryIdIntoDB_true() { Category myCategory = new Category("Household chores"); myCategory.save(); Task myTask = new Task("Mow the lawn", myCategory.getId()); myTask.save(); Task savedTask = Task.find(myTask.getId()); assertEquals(savedTask.getCategoryId(), myCategory.getId()); }
// 事务声明 @Transactional @RequestMapping(params = "method=save") public ModelAndView save(HttpServletRequest request) { Category category = new Category(RequestUtil.getMap(request)); return new ModelAndView("jsonView", category.save()); }