📄 fishmodifyaction.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 FishModifyAction 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 {
// FormBean偺弶婜壔
FishForm fishForm = (FishForm) form;
// Fish偺弶婜壔
Fish fish = fishForm.getFish();
if (fish == null) {
fish = new Fish();
}
// categoryId偺抣傪庢摼偡傞
String categoryId = (String) request.getSession().getAttribute(
"categoryId");
// 乽曄峏乿儃僞儞傪墴壓偟側偄
if (!"fishModify".equals(categoryId)) {
// ProductId偺抣傪庢摼偡傞
String productId = request.getParameter("productId");
// Category偺抣傪僙僢僩偡傞
fish.setCategory(Fish.CATEGORY_ID);
// ProductId偺抣傪僙僢僩偡傞
fish.setProductId(productId);
// 徻嵶偺僨乕僞傪庢摼偡傞
fish = getPetStore().getFishDetail(fish);
// 僨乕僞偑懚嵼偟側偄応崌
if (fish == null) {
// 僄儔乕儊僙僢僕
request.setAttribute("message", "productID傕偆懚嵼偟側偄偱偡!");
// 僄儔乕夋柺傊挼傇
return mapping.findForward("error");
} else {
// Form偺抣傪僙僢僩偡傞
fishForm.setFish(fish);
}
// categoryId偺抣傪僙僢僩偡傞
request.getSession().setAttribute("categoryId", "fishModify");
}
// 乽曄峏乿儃僞儞傪墴壓偡傞
else {
// FISH偺抣傪僙僢僩偡傞
fish.setCategory(Fish.CATEGORY_ID);
// SQL暥傪峴偆
getPetStore().updateFish(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("modifyToBrowse");
}
// 峏怴夋柺傊挼傇
return mapping.findForward("success");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -