📄 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 + -