?? sortaction.java
字號:
package com.action;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import com.actionForm.SortForm;
import org.apache.struts.actions.DispatchAction;
import com.dao.SortDao;
import com.tool.Chinese;
import java.util.List;
import java.io.UnsupportedEncodingException;
public class SortAction extends DispatchAction {
private Chinese chinese = new Chinese();
private SortDao sortDao = new SortDao();
//對新聞詳細類別插入操作
public ActionForward insertSortAction(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
UnsupportedEncodingException {
request.setCharacterEncoding("gb2312");
SortForm sortForm = (SortForm) form;
if (sortForm.getSmallSort() == null ||
sortForm.getSmallSort().equals("")) {
return mapping.findForward("forwardSortAction");
} else {
String smallSort = chinese.toChinese(sortForm.getSmallSort());
if (sortDao.selectOneSort(smallSort) == null) {
sortForm.setBigSort(chinese.toChinese(sortForm.getBigSort()));
sortForm.setCreateTime(sortForm.getCreateTime());
sortForm.setSmallSort(smallSort);
sortDao.insertSort(sortForm);
request.setAttribute("result", "添加新聞類型成功!??!");
} else {
request.setAttribute("result", "該名稱已經存在,添加新聞類型失敗?。?!");
}
return mapping.findForward("resultSortAction");
}
}
//=============================================================================
//對新聞大類別查詢
public ActionForward selectSortAction(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
UnsupportedEncodingException {
request.setCharacterEncoding("gb2312");
List list = sortDao.selectSort(chinese.toChinese(request.getParameter(
"bigSort").trim()));
request.setAttribute("list", list);
return mapping.findForward("selectSortAction");
}
//=====================================================================
//以新聞的詳細類別查詢
public ActionForward selectOneAction(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
UnsupportedEncodingException {
request.setCharacterEncoding("gb2312");
request.setAttribute("form",
sortDao.selectOneSort(chinese.toChinese(request.
getParameter("smallSort"))));
return mapping.findForward("selectOneAction");
}
//===============================================================================
//以自動流水號為條件修改
public ActionForward updateSortAction(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
UnsupportedEncodingException {
request.setCharacterEncoding("gb2312");
SortForm sortForm = (SortForm) form;
String smallSort = chinese.toChinese(sortForm.getSmallSort());
if(sortDao.selectOneSort(smallSort)==null){
sortForm.setBigSort(chinese.toChinese(sortForm.getBigSort()));
sortForm.setCreateTime(sortForm.getCreateTime());
sortForm.setSmallSort(smallSort);
sortForm.setId(sortForm.getId());
sortDao.updateSort(sortForm);
request.setAttribute("result", "修改類型成功?。?!");
}else{
request.setAttribute("result", "該名稱已經存在,修改新聞類型失?。。?!");
}
return mapping.findForward("resultSortAction");
}
//===============================================================================
//以自動流水號為條件刪除
public ActionForward deleteSortAction(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
UnsupportedEncodingException {
request.setCharacterEncoding("gb2312");
int id=Integer.parseInt(request.getParameter("id"));
if(sortDao.deleteSort(id)){
request.setAttribute("result", "刪除新聞類型成功?。。?quot;);
}else{
request.setAttribute("result", "新聞中仍然存在該類型,刪除新聞類型失?。。?!");
}
return mapping.findForward("resultSortAction");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -