📄 catcontroller.java
字号:
package org.ggyy.web.ctrl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.ggyy.bo.Cat;
import org.ggyy.dao.ICatDao;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
import org.springframework.web.servlet.view.RedirectView;
/**
* Multi_Action Controller 的例子,每一个xxxAction都是如下声明:
* xxxActionHandler,它类似于一个servlet(因为有request,response嘛).
* @author jiangyubao
*
*/
/**
* @spring.bean id="catController"
* @spring.property name="catDao" ref="catDao"
* @spring.property name="methodNameResolver" ref="catControllerMethodNameResolver"
*/
public class CatController extends MultiActionController {
private ICatDao catDao;
public ModelAndView listCatHandler(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String parentCatId = request.getParameter("parentId");
List children=null;
Cat parent=null;
if (parentCatId != null && parentCatId.equals("") == false) {
children= this.getCatDao().findDirectChildren(parentCatId);
parent=(Cat) this.getCatDao().load(parentCatId);
} else{
children=this.getCatDao().findRootCats();
}
Map model=new HashMap();
model.put("children",children);
model.put("parent",parent);
return new ModelAndView("listCat.jsp", "model", model);
}
public ModelAndView deleteCatHandler(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String catId = request.getParameter("catId");
Cat cat=(Cat) this.getCatDao().load(catId);
this.getCatDao().delete(cat);
String parentId=cat.getParent()!=null?cat.getParent().getId()+"":"";
return new ModelAndView(new RedirectView("listCat.sf"),"parentId",parentId);
}
public ICatDao getCatDao() {
return catDao;
}
public void setCatDao(ICatDao catDao) {
this.catDao = catDao;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -