@Test @DataSet("XiaoChun.DataSet.xls") public void addTopic() throws Exception { Topic topic = XlsDataSetBeanFactory.createBean(ForumServiceTest.class, "XiaoChun.DataSet.xls", "t_topic", Topic.class); User user = XlsDataSetBeanFactory.createBean(ForumServiceTest.class, "XiaoChun.DataSet.xls", "t_user", User.class); topic.setUser(user); forumService.addTopic(topic); Board boardDb = forumService.getBoardById(1); User userDb = userService.getUserByUserName("tom"); assertEquals(boardDb.getTopicNum(), is(1)); assertEquals(userDb.getCredit(), is(110)); assertEquals(topic.getTopicId(), greaterThan(0)); }
public void addTopic(Topic topic) { Board board = (Board) boardDao.get(topic.getBoardId()); board.setTopicNum(board.getTopicNum() + 1); topicDao.save(topic); topic.getMainPost().setTopic(topic); MainPost post = topic.getMainPost(); post.setCreateTime(new Date()); post.setUser(topic.getUser()); post.setPostTitle(topic.getTopicTitle()); post.setBoardId(topic.getBoardId()); postDao.save(topic.getMainPost()); User user = topic.getUser(); user.setCredit(user.getCredit() + 10); userDao.update(user); }
ForumService { public void addTopic(Topic topic) { Board board = (Board) boardDao.get(topic.getBoardId()); board.setTopicNum(board.getTopicNum() + 1); topicDao.save(topic); topic.getMainPost().setTopic(topic); MainPost post = topic.getMainPost(); post.setCreateTime(new Date()); post.setUser(topic.getUser()); post.setPostTitle(topic.getTopicTitle()); post.setBoardId(topic.getBoardId()); postDao.save(topic.getMainPost()); User user = topic.getUser(); user.setCredit(user.getCredit() + 10); userDao.update(user); } }
ForumService { public void addTopic(Topic topic) { Board board = (Board) boardDao.get(topic.getBoardId()); board.setTopicNum(board.getTopicNum() + 1); topicDao.save(topic); topic.getMainPost().setTopic(topic); MainPost post = topic.getMainPost(); post.setCreateTime(new Date()); post.setUser(topic.getUser()); post.setPostTitle(topic.getTopicTitle()); post.setBoardId(topic.getBoardId()); postDao.save(topic.getMainPost()); User user = topic.getUser(); user.setCredit(user.getCredit() + 10); userDao.update(user); }  }
ForumService { public void addTopic(Topic topic) { Board board = (Board) boardDao.get(topic.getBoardId()); board.setTopicNum(board.getTopicNum() + 1); topicDao.save(topic); topic.getMainPost().setTopic(topic); MainPost post = topic.getMainPost(); post.setCreateTime(new Date()); post.setUser(topic.getUser()); post.setPostTitle(topic.getTopicTitle()); post.setBoardId(topic.getBoardId()); postDao.save(topic.getMainPost()); User user = topic.getUser(); user.setCredit(user.getCredit() + 10); userDao.update(user); }  @Autowired void setTopicDao(TopicDao topicDao); @Autowired void setUserDao(UserDao userDao); @Autowired void setBoardDao(BoardDao boardDao); @Autowired void setPostDao(PostDao postDao); void addTopic(Topic topic); void removeTopic(int topicId); void addPost(Post post); void removePost(int postId); void addBoard(Board board); void removeBoard(int boardId); void makeDigestTopic(int topicId); List<Board> getAllBoards(); Page getPagedTopics(int boardId,int pageNo,int pageSize); Page getPagedPosts(int topicId,int pageNo,int pageSize); Page queryTopicByTitle(String title,int pageNo,int pageSize); Board getBoardById(int boardId); Topic getTopicByTopicId(int topicId); Post getPostByPostId(int postId); void addBoardManager(int boardId,String userName); void updateTopic(Topic topic); void updatePost(Post post); }
ForumService { public void addTopic(Topic topic) { Board board = (Board) boardDao.get(topic.getBoardId()); board.setTopicNum(board.getTopicNum() + 1); topicDao.save(topic); topic.getMainPost().setTopic(topic); MainPost post = topic.getMainPost(); post.setCreateTime(new Date()); post.setUser(topic.getUser()); post.setPostTitle(topic.getTopicTitle()); post.setBoardId(topic.getBoardId()); postDao.save(topic.getMainPost()); User user = topic.getUser(); user.setCredit(user.getCredit() + 10); userDao.update(user); }  @Autowired void setTopicDao(TopicDao topicDao); @Autowired void setUserDao(UserDao userDao); @Autowired void setBoardDao(BoardDao boardDao); @Autowired void setPostDao(PostDao postDao); void addTopic(Topic topic); void removeTopic(int topicId); void addPost(Post post); void removePost(int postId); void addBoard(Board board); void removeBoard(int boardId); void makeDigestTopic(int topicId); List<Board> getAllBoards(); Page getPagedTopics(int boardId,int pageNo,int pageSize); Page getPagedPosts(int topicId,int pageNo,int pageSize); Page queryTopicByTitle(String title,int pageNo,int pageSize); Board getBoardById(int boardId); Topic getTopicByTopicId(int topicId); Post getPostByPostId(int postId); void addBoardManager(int boardId,String userName); void updateTopic(Topic topic); void updatePost(Post post);  }