Java tutorial
/* * Copyright 2005-2013 shopxx.net. All rights reserved. * Support: http://www.shopxx.net * License: http://www.shopxx.net/license */ package net.groupbuy.controller.admin; import javax.annotation.Resource; import net.groupbuy.Message; import net.groupbuy.Pageable; import net.groupbuy.entity.Tag; import net.groupbuy.entity.BaseEntity.Save; import net.groupbuy.entity.Tag.Type; import net.groupbuy.service.TagService; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.mvc.support.RedirectAttributes; /** * Controller - * * @author SHOP++ Team * @version 3.0 */ @Controller("adminTagController") @RequestMapping("/admin/tag") public class TagController extends BaseController { @Resource(name = "tagServiceImpl") private TagService tagService; /** * */ @RequestMapping(value = "/add", method = RequestMethod.GET) public String add(ModelMap model) { model.addAttribute("types", Type.values()); return "/admin/tag/add"; } /** * ? */ @RequestMapping(value = "/save", method = RequestMethod.POST) public String save(Tag tag, RedirectAttributes redirectAttributes) { if (!isValid(tag, Save.class)) { return ERROR_VIEW; } tag.setArticles(null); tag.setProducts(null); tagService.save(tag); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:list.jhtml"; } /** * */ @RequestMapping(value = "/edit", method = RequestMethod.GET) public String edit(Long id, ModelMap model) { model.addAttribute("types", Type.values()); model.addAttribute("tag", tagService.find(id)); return "/admin/tag/edit"; } /** * */ @RequestMapping(value = "/update", method = RequestMethod.POST) public String update(Tag tag, RedirectAttributes redirectAttributes) { if (!isValid(tag)) { return ERROR_VIEW; } tagService.update(tag, "type", "articles", "products"); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:list.jhtml"; } /** * */ @RequestMapping(value = "/list", method = RequestMethod.GET) public String list(Pageable pageable, ModelMap model) { model.addAttribute("page", tagService.findPage(pageable)); return "/admin/tag/list"; } /** * */ @RequestMapping(value = "/delete", method = RequestMethod.POST) public @ResponseBody Message delete(Long[] ids) { tagService.delete(ids); return SUCCESS_MESSAGE; } }