@RequestMapping(value = "/article/settags/{id}", method = RequestMethod.POST) public int setTags(@RequestBody String tags, @PathVariable Long id) throws IOException { Article article = articleRepository.findOneById(id); Set<Tag> tagSet = new HashSet<>(Arrays.asList((new ObjectMapper()).readValue(tags, Tag[].class))); for (Tag tag : tagSet) { Tag tempTag; if ((tempTag = simpleTagRepository.findOneByName(tag.getName())) != null) tag.copyFrom(tempTag); else simpleTagRepository.save(tag); tag.addArticle(article); } article.updateTags(tagSet); accountService.update(article); checkForEmptyTags(); return 0; }
@RequestMapping(value = "/article/gettags/{id}", method = RequestMethod.GET) public Object[] getTags(@PathVariable Long id) { return articleRepository.findOneById(id).sendedTags().toArray(); }