rulesaction.java
来自「实现图书的借阅和管理信息化」· Java 代码 · 共 222 行
JAVA
222 行
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.moonman.libraryManager.control.struts.action;
import java.util.ArrayList;
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.actions.MappingDispatchAction;
import org.apache.struts.validator.DynaValidatorActionForm;
import com.moonman.libraryManager.model.service.PlaceService;
import com.moonman.libraryManager.model.service.RulesService;
import com.moonman.libraryManager.model.vo.Place;
import com.moonman.libraryManager.model.vo.Rules;
/**
* MyEclipse Struts Creation date: 01-15-2008
*
* XDoclet definition:
*
* @struts.action parameter="getRules" validate="true"
*/
public class RulesAction extends MappingDispatchAction {
/*
* Generated Methods
*/
private RulesService rulesService;
private PlaceService placeService;
public void setPlaceService(PlaceService placeService) {
this.placeService = placeService;
}
public void setRulesService(RulesService rulesService) {
this.rulesService = rulesService;
}
/**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward getRules(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// 获得规则列表
List<Rules> lst = this.rulesService.getRules();
request.setAttribute("rules", lst);
return mapping.findForward("ruleShow");
}
/**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward rulesAddShow(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// 获得官舱地信息
List<Place> lst = this.rulesService.getPlaces();
request.setAttribute("stores", lst);
return mapping.findForward("ruleAddShow");
}
/**
* 添加规则信息
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward ruleAdd(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaValidatorActionForm dv = (DynaValidatorActionForm) form;
Rules rule = this.encaEntityRule(dv);
this.rulesService.addRule(rule);
return mapping.findForward("addSuccess");
}
/**
* 显示规则详细信息
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward showRuleDetail(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String ruleId = request.getParameter("id");
Rules rule = this.rulesService.getRuleById(Integer.parseInt(ruleId));
List<Place> lst = this.getAllPlaceByPlace(rule.getGcd());
request.setAttribute("places", lst);
request.setAttribute("rule", rule);
return mapping.findForward("showRule");
}
/**
* 根据编号集合获得所有的官藏信息
*
* @param str
* @return
*/
private List<Place> getAllPlaceByPlace(String str) {
String[] st = str.split(",");
List<Place> lst = new ArrayList<Place>();
for (String s : st) {
lst.add(this.placeService.getPlaceById(new Integer(s)));
}
return lst;
}
/**
* 显示规则详细信息
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward ruleModifyShow(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// 获得官舱地信息
String ruleId = request.getParameter("id");
List<Place> lst = this.rulesService.getPlaces();
request.setAttribute("stores", lst);
// 获得规则列表
Rules rule = this.rulesService.getRuleById(Integer.parseInt(ruleId));
request.setAttribute("rule", rule);
return mapping.findForward("ruleModifyShow");
}
/**
* 显示规则详细信息
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward ruleModify(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaValidatorActionForm dv = (DynaValidatorActionForm) form;
Rules rule = this.encaEntityRule(dv);
this.rulesService.modifyRule(rule);
return mapping.findForward("modifySuccess");
}
/**
* 删除一个规则信息
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward deleteRule(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String ruleId = request.getParameter("id");
this.rulesService.deleteRuleByRuleId(ruleId);
return mapping.findForward("deleteSuccess");
}
/**
* 封装rule实体
*
* @param dv
* @return
*/
private Rules encaEntityRule(DynaValidatorActionForm dv) {
String gzmc = dv.getString("gzmc");
String kjyts = dv.getString("kjyts");
StringBuffer gcd = new StringBuffer();
String xjts = dv.getString("xjts");
String jygs = "3";
String xjcs = dv.getString("xjcs");
String yygs = dv.getString("yygs");
String blts = dv.getString("blts");
String[] stores = dv.getStrings("stores");
for (String string : stores) {
gcd.append(string);
gcd.append(",");
}
Rules rule = new Rules();
String ruleId = dv.getString("ruleId");
if (ruleId != null && !"".equals(ruleId)) {
rule.setRuleId(new Integer(ruleId));
}
rule.setGzmc(gzmc);
rule.setKjyts(Integer.parseInt(kjyts));
rule.setGcd(gcd.toString().substring(0, gcd.length() - 1));
rule.setXjcs(Integer.parseInt(xjcs));
rule.setXjts(Integer.parseInt(xjts));
rule.setJygs(Integer.parseInt(jygs));
rule.setYygs(Integer.parseInt(yygs));
rule.setBlts(Integer.parseInt(blts));
return rule;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?