📄 fishbrowseaction.java
字号:
package org.springframework.samples.jpetstore.web.struts;
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.springframework.beans.support.PagedListHolder;
import org.springframework.samples.jpetstore.domain.Fish;
/**
* 堦棗夋柺偺傾僋僔儑儞
*
* @author 焨寷曮
*/
public class FishBrowseAction extends BaseAction {
/**
* 弶婜壔張棟
*
* @param mapping
* 傾僋僔儑儞偺攝抲忣曬
* @param form
* Servlet忣曬
* @param request
* HTTP儕僋僄僗僩
* @param response
* HTTP儗僗億儞僗
* @throws Exception
* 堎忢張棟
* @return ActionForward 揮憲偟偨儁乕僕偺儘僕僢僋柤徧
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// productId傪庢摼偡傞
String productId = request.getParameter("productId");
// 怴婯夋柺偐傜偺敾掕梡
String categoryId;
// 乽嶍彍乿儃僞儞傪墴壓偡傞
if ("".equals(productId) || productId != null) {
// FormBean偺弶婜壔
FishForm fishForm = (FishForm) form;
// fish偺弶婜壔
Fish fish = fishForm.getFish();
// Category偺抣傪僙僢僩偡傞
fish.setCategory(Fish.CATEGORY_ID);
// ProductId偺抣傪僙僢僩偡傞
fish.setProductId(productId);
// SQL暥傪峴偆
getPetStore().deleteFish(fish);
// 堦棗偺僨乕僞傪庢摼偡傞
PagedListHolder productList = new PagedListHolder(getPetStore()
.getFish(Fish.CATEGORY_ID));
// 昞帵僨乕僞審悢傪僙僢僩偡傞
productList.setPageSize(4);
// request偵僨乕僞傪僙僢僩偡傞
request.getSession().setAttribute("searchFishList", productList);
request.setAttribute("productList", productList);
// categoryId抣傪僙僢僩偡傞
categoryId = "fishBrowse";
request.getSession().setAttribute("categoryId", categoryId);
// 堦棗夋柺偵挼傇
return mapping.findForward("success");
}
// 弶婜張棟偺敾掕
if ("notFishBrowse".equals(request.getParameter("categoryId"))) {
categoryId = request.getParameter("categoryId");
} else {
categoryId = (String) request.getSession().getAttribute(
"categoryId");
}
// 儁乕僕儕儞僋傪墴偡
if ("fishBrowse".equals(categoryId)) {
String page = request.getParameter("page");
// 堦棗偺僨乕僞傪庢摼偡傞
PagedListHolder productList = (PagedListHolder) request
.getSession().getAttribute("searchFishList");
// 慜暸傪墴壓偡傞帪
if ("next".equals(page)) {
productList.nextPage();
}
// 屻暸傪墴壓偡傞帪
else if ("previous".equals(page)) {
productList.previousPage();
}
// 堦棗僨乕僞傪僙僢僩偡傞
request.setAttribute("productList", productList);
} else {
// 堦棗偺僨乕僞傪庢摼偡傞
PagedListHolder productList = new PagedListHolder(getPetStore()
.getFish(Fish.CATEGORY_ID));
// 僨乕僞偺昞帵忦悢傪僙僢僩偡傞
productList.setPageSize(4);
// 堦棗僨乕僞傪僙僢僩偡傞
request.getSession().setAttribute("searchFishList", productList);
request.setAttribute("productList", productList);
// 堦棗夋柺偵擖偭偨偺偱丄抣傪曄峏偡傞
categoryId = "fishBrowse";
request.getSession().setAttribute("categoryId", categoryId);
}
// 堦棗夋柺傊挼傇
return mapping.findForward("success");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -