Spring2.5+Struts1.3.8+Jpa(Hibernate实现)整合之七

转载请注明:来自http://changong.iteye.com/ 作者:张燕广

该篇主要编写FormBeanaction

src下创建包com.zyg.ssj.web.formbean,在该包下创建FormBean,名称为StudentForm,其代码如下:

package com.zyg.ssj.web.formbean; import org.apache.struts.action.ActionForm; public class StudentForm extends ActionForm { private Integer stuId; private String stuName; public Integer getStuId() { return stuId; } public void setStuId(Integer stuId) { this.stuId = stuId; } public String getStuName() { return stuName; } public void setStuName(String stuName) { this.stuName = stuName; } }

package com.zyg.ssj.web.action; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; 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.zyg.ssj.bean.Student; import com.zyg.ssj.service.StudentService; public class StudentAction extends Action { @Resource private StudentService studentService; @Override public ActionForward execute(ActionMapping mapping, ActionForm formBean, HttpServletRequest request, HttpServletResponse response) throws Exception { request.setAttribute("students", studentService.getStudents()); for(Student stu : studentService.getStudents()){ System.out.println(stu.getStuName()); } return mapping.findForward("list"); } }

 

 

StudentManageAction代码如下:

package com.zyg.ssj.web.action; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; 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.zyg.ssj.bean.Student; import com.zyg.ssj.service.StudentService; import com.zyg.ssj.web.formbean.StudentForm; public class StudentManageAction extends Action { @Resource private StudentService studentService; public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { StudentForm formBean = (StudentForm)form; if(formBean.getStuName()!=null && !formBean.getStuName().equals("")){ studentService.save(new Student(formBean.getStuName())); request.setAttribute("message", "学生【"+formBean.getStuName()+"】信息添加成功!"); }else{ request.setAttribute("message", "学生信息不能为空,添加失败!"); } return mapping.findForward("message"); } }

至此,FromBeanaction编写完毕。下一篇编写jsp展示页面。 

src下创建包com.zyg.ssj.web.action,在该包下创建StudentActionStudentManageAction

StudentAction代码如下:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值