@GetMapping("/manage/tagDetail") public String detail(@RequestParam String name, Model model) { model.addAttribute("currentData", tagRepository.findOne(name)); return "_tagDetail.html"; }
@GetMapping("/manage/tagEdit") public String edit(@RequestParam String name, Model model) { model.addAttribute("currentData", tagRepository.findOne(name)); return "_tagOperator.html"; }
@GetMapping("/manage/tagList/check") @ResponseBody public String checkName(@RequestParam String name) { return (StringUtils.isEmpty(name) || tagRepository.findOne(name) != null) ? "false" : "true"; }
@Override public Tag save(String tagName) { Tag tag = tagRepository.findOne(tagName); if (tag == null) { tag = new Tag(); tag.setName(tagName); tag.setType(TagType.SEARCH); tagRepository.save(tag); } return tag; }
@PostMapping("/manage/tagList") @Transactional public String add(@RequestParam String name, Integer type , @RequestParam(required = false, defaultValue = "0") Integer weight, String icon) throws IOException { Tag tag = tagRepository.findOne(name); if (tag == null) { tag = new Tag(); tag.setName(name); tag.setType(TagType.values()[type]); } tag.setWeight(weight); tag = tagRepository.saveAndFlush(tag); //转存资源 if (!StringUtils.isEmpty(icon) && !icon.equalsIgnoreCase(tag.getIcon())) { String tagImgResource = "tag/" + tag.getName().hashCode() + "." + FileUtils.fileExtensionName(icon); resourceService.moveResource(tagImgResource, icon); tag.setIcon(tagImgResource); } return "redirect:/manageTag"; }