📄 merchantbulletinaction.java
字号:
/*
* 作者:茹振超
* 时间:2007年12月09日
* 功能:店铺管理 ->公告管理
*/
package com.mole.struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.mole.struts.bean.MerchantBulletinInfoBean;
import com.mole.struts.bean.Page;
import com.mole.struts.dao.MerchantBulletinDAO;
import com.mole.struts.form.MerchantBulletinForm;
/**
* MyEclipse Struts Creation date: 12-09-2007
*
* XDoclet definition:
*
* @struts.action path="/merchantBulletinManage"
* name="merchantBulletinManageForm"
* input="/merchantBulletinManage.jsp" scope="request"
* validate="true"
*/
public class MerchantBulletinAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String storeId = (String) request.getSession().getAttribute("store");
MerchantBulletinDAO dao = new MerchantBulletinDAO();
String action = request.getParameter("action");
if (action == null || action.equals("new")) {// 获取显示公告信息的页面
Page page = new Page();
int pageSize = (request.getParameter("pageSizeSelect") == null ? 10
: Integer.parseInt(request.getParameter("pageSizeSelect")));
int currentPage = (request.getParameter("page") == null ? 1
: Integer.parseInt(request.getParameter("page")));
int count = dao.getBulletinPageInfo(storeId, pageSize);
page.setPageSize(pageSize);
page.setRecordCount(count);
page.setPageCount((count + pageSize - 1) / pageSize);
page.setCurrentPage(currentPage);
MerchantBulletinInfoBean[] beanList = null;
try {
beanList = dao.getBulletinInfoinThePage(storeId, currentPage);
} catch (Exception e) {
e.printStackTrace();
HttpSession session = request.getSession();
session.setAttribute("title", "错误信息");
session.setAttribute("message", "公告信息获取失败!");
session.setAttribute("returnUrl", "show.do?action=goLogin");
return mapping.findForward("goMessage");
}
request.setAttribute("bulletinInfoList", beanList);
request.setAttribute("Page", page);
return mapping.findForward("goMerchantBulletin");
} else if (action.equals("delete")) {// 删除一条公告
try {
String sql = "DELETE FROM MerchantBulletin WHERE ID='"
+ request.getParameter("id") + "'";
dao.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
HttpSession session = request.getSession();
session.setAttribute("title", "错误信息");
session.setAttribute("message", "公告信息删除失败!");
session.setAttribute("returnUrl", "show.do?action=goLogin");
return mapping.findForward("goMessage");
}
return new ActionForward("/merchantBulletin.do?action=new");
} else if (action.equals("modify")) {// 获取修改公告信息的页面
MerchantBulletinInfoBean bean = null;
try {
bean = dao.getDetailInfo(request.getParameter("id"));
} catch (Exception e) {
e.printStackTrace();
HttpSession session = request.getSession();
session.setAttribute("title", "错误信息");
session.setAttribute("message", "公告信息获取失败!");
session.setAttribute("returnUrl", "show.do?action=goLogin");
return mapping.findForward("goMessage");
}
request.setAttribute("pageAction", "modify");
request.setAttribute("detailInfo", bean);
return mapping.findForward("goMerchantBulletinDetail");
} else if (action.equals("onModify")) {// 修改一条公告信息
MerchantBulletinForm mbdf = (MerchantBulletinForm) form;
try {
String sql = "update MerchantBulletin set name='"
+ mbdf.getName() + "',content='" + mbdf.getContent()
+ "' where id=" + mbdf.getId();
dao.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
HttpSession session = request.getSession();
session.setAttribute("title", "错误信息");
session.setAttribute("message", "公告信息更新失败!");
session.setAttribute("returnUrl", "show.do?action=goLogin");
return mapping.findForward("goMessage");
}
return new ActionForward("/merchantBulletin.do?action=new");
} else if (action.equals("add")) {// 获取添加一条公告信息的页面
MerchantBulletinInfoBean bean = new MerchantBulletinInfoBean();
request.setAttribute("pageAction", "add");
request.setAttribute("detailInfo", bean);
return mapping.findForward("goMerchantBulletinDetail");
} else if (action.equals("onAdd")) {// 添加一条公告信息
MerchantBulletinForm mbaf = (MerchantBulletinForm) form;
try {
String sql = "INSERT INTO [MerchantBulletin]([Name],[StoreID],[Content]) "
+ "VALUES('"
+ mbaf.getName()
+ "','"
+ storeId
+ "','"
+ mbaf.getContent() + "')";
dao.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
HttpSession session = request.getSession();
session.setAttribute("title", "错误信息");
session.setAttribute("message", "新公告生成失败!");
session.setAttribute("returnUrl", "show.do?action=goLogin");
return mapping.findForward("goMessage");
}
return new ActionForward("/merchantBulletin.do?action=new");
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -