📄 fwxxaction.java
字号:
package com.accp.actions;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.accp.entity.TblFwlx;
import com.accp.entity.TblFwxx;
import com.accp.entity.TblJd;
import com.accp.entity.TblUser;
import com.accp.forms.FwxxForm;
import com.accp.service.FwxxServiceImpl;
import com.accp.service.IFwxxService;
public class FwxxAction extends DispatchAction
{
/**
* 查找所有的Action
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws Exception
*/
public ActionForward findAll(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
int pageNo = Integer.parseInt(request.getParameter("pageNo"));
int pageSize = Integer.parseInt(request.getParameter("pageSize"));
IFwxxService service = new FwxxServiceImpl();
List list = service.findAll(pageNo, pageSize);
int totalPage = service.getTotalPage(pageSize);
request.setAttribute("list", list);
request.setAttribute("currentPage", pageNo);
request.setAttribute("pageSize", pageSize);
request.setAttribute("totalPage", totalPage);
return mapping.findForward("findAll");
}
/**
* 查看详细信息的Action
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws Exception
*/
public ActionForward searchDetail(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
int id = Integer.parseInt(request.getParameter("fwid"));
IFwxxService service = new FwxxServiceImpl();
TblFwxx fwxx = service.findByPK(id);
request.setAttribute("fwxx",to2Form(fwxx) );
return mapping.findForward("searchDetail");
}
/**
* 发布房屋信息的Action
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws Exception
*/
public ActionForward addFwxxInfo(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
String forwardStr = "";
FwxxForm myform = (FwxxForm) form;
TblFwxx fwxx = toDTO(myform);
IFwxxService service = new FwxxServiceImpl();
boolean flag = service.saveFwxx(fwxx);
if (flag)
{
forwardStr = "success";
} else
{
forwardStr = "error";
}
return mapping.findForward(forwardStr);
}
/**
* 将 DTO 对象转化成 ActionForm 对象
*
* @param fwxx
* @return ActionForm
*/
public FwxxForm to2Form(TblFwxx fwxx)
{
FwxxForm myform = new FwxxForm();
myform.setFwid(fwxx.getFwid());
myform.setTblUser(fwxx.getTblUser());
myform.setTitle(fwxx.getTitle());
myform.setTelephone(fwxx.getTelephone());
myform.setLxr(fwxx.getLxr());
myform.setTblFwlx(fwxx.getTblFwlx());
myform.setShi(fwxx.getShi());
myform.setTing(fwxx.getTing());
myform.setZj(fwxx.getZj());
myform.setTblJd(fwxx.getTblJd());
myform.setDate(fwxx.getDate());
myform.setFwxx(fwxx.getFwxx());
return myform;
}
/**
* 将ActionForward对象转化成DTO对象
*
* @param myform
* @return TblFwxx
*/
public TblFwxx toDTO(FwxxForm myform)
{
TblFwxx fwxx = null;
String fwxx1 = myform.getFwxx();
TblUser user = myform.getTblUser();
TblFwlx fwlx = myform.getTblFwlx();
TblJd jd = myform.getTblJd();
String title = myform.getTitle();
String telephone = myform.getTelephone();
Integer shi = myform.getShi();
Integer ting = myform.getTing();
String lxr = myform.getLxr();
double zj = myform.getZj();
Date date = myform.getDate();
fwxx = new TblFwxx(user, jd, fwlx, shi, ting, fwxx1, zj, title, date,
telephone, lxr);
return fwxx;
}
/**
* 按标题查询的Action
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward findByTitle(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
String title=request.getParameter("titel");
IFwxxService service=new FwxxServiceImpl();
TblFwxx fwxx=service.findByTitle(title);
FwxxForm fwxxForm=to2Form(fwxx);
request.setAttribute("FwxxForm", fwxxForm);
return mapping.findForward("findByTitle");
}
/**
* 按标题查询的Action
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws Exception
*/
public ActionForward findByUser(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
HttpSession session=request.getSession();
TblUser user=(TblUser)session.getAttribute("user");
IFwxxService service=new FwxxServiceImpl();
List list=service.findByUser(user.getUid());
request.setAttribute("list", list);
return mapping.findForward("findByUser");
}
/**
* 删除信息 的 Action
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws Exception
*/
public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
String forwardStr="";
int id=Integer.parseInt(request.getParameter("fwid"));
IFwxxService service=new FwxxServiceImpl();
if(service.deleteFwxx(id))
{
forwardStr="success";
}
else
{
forwardStr="error";
}
return mapping.findForward(forwardStr);
}
/**
* 转向编辑页面的Action
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws Exception
*/
public ActionForward edit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
int id=Integer.parseInt(request.getParameter("fwid"));
IFwxxService service=new FwxxServiceImpl();
TblFwxx fwxx=service.findByPK(id);
FwxxForm fwxxForm=to2Form(fwxx);
request.setAttribute("FwxxForm", fwxxForm);
return mapping.findForward("edit");
}
/**
* 更新页面
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws Exception
*/
public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
String forwardStr="";
FwxxForm myform =(FwxxForm)form;
IFwxxService service=new FwxxServiceImpl();
boolean flag=service.updateFwxx(toDTO(myform));
if(flag)
{
forwardStr="success";
}
else
{
forwardStr="error";
}
return mapping.findForward(forwardStr);
}
/**
* 根据用户输入进行查询的Action
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws Exception
*/
public ActionForward search(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
FwxxForm myform =(FwxxForm)form;
IFwxxService service=new FwxxServiceImpl();
List list=service.search(myform);
request.setAttribute("list", list);
return mapping.findForward("search");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -