📄 goodsaction.java
字号:
package com.shunshi.ssh.action;
import java.util.Date;
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.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.actions.DispatchAction;
import org.extremecomponents.table.core.TableConstants;
import org.extremecomponents.table.limit.Limit;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.shunshi.ssh.actionform.GoodsForm;
import com.shunshi.ssh.entity.*;
import com.shunshi.ssh.exception.GoodsServiceException;
import com.shunshi.ssh.service.IGoodsService;
public class GoodsAction extends DispatchAction {
private IGoodsService goodsService;
//private static final int DEFAULT_PAGE_SIZE = 5;
public IGoodsService getGoodsService() {
return goodsService;
}
public void setGoodsService(IGoodsService goodsService) {
this.goodsService = goodsService;
}
public ActionForward addGoods(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
GoodsForm gf=(GoodsForm)form;
boolean tokenvalidate=isTokenValid(request,true);
if(tokenvalidate){
Goods goods=gf.getGoods();
String userName=request.getParameter("userName");
if(!("".equals(request.getParameter("userId").trim()))){
System.out.println("dddd");
Long userId=new Long(Long.parseLong(request.getParameter("userId")));
goods.setUserId(userId);
}
goods.setPublishTime(new Date());
goods.setUserName(userName);
goods.setState(1);
if(goods.getRemark().trim().length()==0 || goods.getRemark()==null){
goods.setRemark("It is so lazy!");
}
goodsService.addGoods(goods);
AllInfo allInfo=goodsService.getAllInfo();
goodsService.saveAllInfo(allInfo);
return mapping.findForward("goodsAdd");
}else{
ActionMessages messages=new ActionMessages();
messages.add("error.repeatsubmit",new ActionMessage("token.invalid"));
saveMessages(request,messages);
toAddGoodsInfo(mapping,form,request,response);
return mapping.findForward("goodsAdd");
}
}
public ActionForward toAddGoodsInfo(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception{
Goods goods=new Goods();
goods.setRemark("The man is lazy!");
GoodsForm gf=(GoodsForm)form;
gf.setGoods(goods);
saveToken(request);
return mapping.findForward("goodsAdd");
}
public ActionForward findGoodsById(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
Long id=new Long(Long.parseLong(request.getParameter("id")));
Goods goods=goodsService.findGoodsById(id);
GoodsForm gf=(GoodsForm)form;
gf.setGoods(goods);
request.setAttribute("id",id);
request.setAttribute("state", goods.getState());
request.setAttribute("userId", goods.getUserId());
return mapping.findForward("goodsInfo");
}
public ActionForward listGoods(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
GoodsForm gf=(GoodsForm)form;
String stateStr=request.getParameter("state");
byte state;
if(stateStr!=null){
state=Byte.parseByte(request.getParameter("state"));
}else{
state=1;
}
Limit limit = ExtremeTablePage.getLimit(request);
int totalRows = ExtremeTablePage.getTotalRowsFromRequest(request);
Page page=goodsService.findByState(state,limit,totalRows);
request.setAttribute(TableConstants.TOTAL_ROWS, (int)page.getTotalCount());
request.setAttribute("goods", page.getResult());
return mapping.findForward("goodsList");
}
public ActionForward deleteGoodsById(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
Long id=new Long(Long.parseLong(request.getParameter("id")));
goodsService.updateState(id, 3);
return mapping.findForward("toGoodsList");
}
public ActionForward deleteGoods(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
Long id=new Long(Long.parseLong(request.getParameter("id")));
Long[] ls=new Long[]{id};
goodsService.deleteGoods(ls);
goodsService.deleteAll(id, "goods");
return mapping.findForward("toGoodsGarbageList");
}
public ActionForward listGoodsGarbage(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
String stateStr=request.getParameter("state");
byte state;
if(stateStr!=null){
state=Byte.parseByte(request.getParameter("state"));
}else{
state=3;
}
Limit limit = ExtremeTablePage.getLimit(request);
int totalRows = ExtremeTablePage.getTotalRowsFromRequest(request);
Page page=goodsService.findByState(state,limit,totalRows);
request.setAttribute(TableConstants.TOTAL_ROWS, (int)page.getTotalCount());
request.setAttribute("goods", page.getResult());
return mapping.findForward("goodsGarbageList");
}
public ActionForward listGoodsChecked(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
String stateStr=request.getParameter("state");
byte state;
if(stateStr!=null){
state=Byte.parseByte(request.getParameter("state"));
}else{
state=2;
}
Limit limit = ExtremeTablePage.getLimit(request);
int totalRows = ExtremeTablePage.getTotalRowsFromRequest(request);
Page page=goodsService.findByState(state,limit,totalRows);
request.setAttribute(TableConstants.TOTAL_ROWS, (int)page.getTotalCount());
request.setAttribute("goods", page.getResult());
return mapping.findForward("goodsCheckedList");
}
public ActionForward recoverGoods(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
Long id=new Long(Long.parseLong(request.getParameter("id")));
goodsService.updateState(id, 1);
return mapping.findForward("toGoodsGarbageList");
}
public ActionForward checkGoodsById(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
Long id=new Long(Long.parseLong(request.getParameter("id")));
goodsService.updateState(id, 2);
return mapping.findForward("toGoodsList");
}
public ActionForward updateGoods(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
GoodsForm gf=(GoodsForm)form;
Goods goods=gf.getGoods();
if(request.getParameter("userId")!=null && !request.getParameter("userId").equals("")){
Long userId=new Long(Long.parseLong(request.getParameter("userId")));
goods.setUserId(userId);
}
Long id=new Long(Long.parseLong(request.getParameter("id")));
Integer state=new Integer(Integer.parseInt(request.getParameter("state")));
System.out.println(id);
goods.setId(id);
goods.setState(state);
goodsService.updateGoods(goods);
return mapping.findForward("toGoodsList");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -