📄 catalogaction.java
字号:
package com.sdi0708.bdifn.bookstore.web.struts.action;import java.util.List;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.apache.struts.validator.BeanValidatorForm;import com.sdi0708.bdifn.bookstore.domain.Catalog;import com.sdi0708.bdifn.bookstore.service.ICatalogService;import com.sdi0708.bdifn.bookstore.service.util.StringUtils;/** * 类别管理模块的action * @author 吴承志 * */public class CatalogAction extends BaseAction { /** * 通过依spring注入一个userService,单例模式的,线程安全 */ private ICatalogService catalogService; public void setCatalogService(ICatalogService catalogService) { this.catalogService = catalogService; } /** * 找出所有的顶层类别 */ public ActionForward findParentCatalogs(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { List<Catalog> catalogs = catalogService.findParentCatalogs(); request.setAttribute("catalogs", catalogs); return mapping.findForward("success"); } /** * 增加一个类别 */ public ActionForward addCatalog(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { //在此使用 BeanValidatorForm 配置. BeanValidatorForm fForm = (BeanValidatorForm)form; Catalog catalog = (Catalog)fForm.getInstance(); String pid = request.getParameter("parentId"); Long parentId = null; if(!StringUtils.isEmpty(pid)) { parentId = Long.valueOf(pid); } catalogService.addCatalog(catalog, parentId); return mapping.findForward("success"); } /** * 准备进行修改 */ public ActionForward preparedModify(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { Long id = Long.valueOf(request.getParameter("id")); Catalog catalog = catalogService.findById(id); request.setAttribute("catalog", catalog); return mapping.findForward("success"); } /** * 执行修改 */ public ActionForward modifyCatalog(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { BeanValidatorForm fForm = (BeanValidatorForm)form; Catalog catalog = (Catalog)fForm.getInstance(); catalogService.modifyCatalod(catalog); return mapping.findForward("success"); } public ActionForward deleteCatalogById(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { Long id = Long.valueOf(request.getParameter("id")); catalogService.deleteById(id); return mapping.findForward("success"); } public ActionForward findLeafCatalogs(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { Long id = Long.valueOf(request.getParameter("id")); List<Catalog> catalogs = catalogService.findLeafCatalogs(id); Catalog pCatalog = catalogService.findById(id); request.setAttribute("catalogs", catalogs); request.setAttribute("pCatalog", pCatalog); return mapping.findForward("success"); } /** * 提供于ajax使用 */ public ActionForward ajaxFindLeaf(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { Long id = Long.valueOf(request.getParameter("id")); List<Catalog> catalogs = catalogService.findLeafCatalogs(id); request.setAttribute("catalogs", catalogs); return mapping.findForward("success"); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -