?? manageafficheaction.java
字號:
package mrgf.action;
import java.util.List;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import mrgf.hibernate.Affiche;
import mrgf.form.ManageAfficheForm;
import mrgf.other.*;
public class ManageAfficheAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
ManageAfficheForm manageAfficheForm = (ManageAfficheForm) form;
String parameter = mapping.getParameter();
String forward = "";
HttpSession session = request.getSession();
Hibernate hn = new Hibernate();
//進入公告管理
if (parameter.equals("manageAd")) {
String hql = "from Affiche";
List affiches = hn.query(hql);
request.setAttribute("affiches", affiches);
forward = "manage_ad";
}
//修改公告
if (parameter.equals("updateAd")) {
String afficheId = request.getParameter("afficheId");
int id = Integer.parseInt(afficheId);
String hql = "from Affiche where id=" + id;
Affiche affiche = (Affiche) hn.queryOne(hql);
request.setAttribute("affiche", affiche);
//
hql = "from Affiche";
List affiches = hn.query(hql);
request.setAttribute("affiches", affiches);
forward = "manage_ad";
}
//刪除公告
if (parameter.equals("deleteAd")) {
String afficheId = request.getParameter("afficheId");
int id = Integer.parseInt(afficheId);
String hql = "from Affiche where id=" + id;
hn.delete(hql);
//
hql = "from Affiche";
List affiches = hn.query(hql);
request.setAttribute("affiches", affiches);
forward = "manage_ad";
}
//提交公告內容
if (parameter.equals("referAd")) {
SpecialMethod sm = new SpecialMethod();
if (manageAfficheForm.getId() == 0) { // 添加新公告
Affiche affiche = new Affiche();
affiche.setTitle(sm.toChinese(manageAfficheForm.getTitle()));
affiche.setDates(manageAfficheForm.getDates());
affiche.setContent(sm.toChinese(manageAfficheForm.getContent()));
hn.save(affiche);
} else { // 修改現有公告
String hql = "from Affiche where id=" + manageAfficheForm.getId();
Affiche affiche = (Affiche) hn.queryOne(hql);
affiche.setTitle(sm.toChinese(manageAfficheForm.getTitle()));
affiche.setContent(sm.toChinese(manageAfficheForm.getContent()));
hn.update(affiche);
}
//
String hql = "from Affiche";
List affiches = hn.query(hql);
request.setAttribute("affiches", affiches);
forward = "manage_ad";
}
return mapping.findForward(forward);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -