selectstudentaction.java
来自「Struts+Spring+Hibernate 增删改查」· Java 代码 · 共 57 行
JAVA
57 行
package com.yumeng.ssidemo.action;
import java.util.HashMap;
import java.util.Map;
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.actions.LookupDispatchAction;
import com.yumeng.ssidemo.po.Student;
import com.yumeng.ssidemo.service.StudentService;
public class SelectStudentAction extends LookupDispatchAction {
private StudentService studentService;
public StudentService getStudentService() {
return studentService;
}
public void setStudentService(StudentService studentService) {
this.studentService = studentService;
}
public ActionForward selectById(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String parameter = request.getParameter("parameter");
int id = 0;
try{
id = Integer.parseInt(parameter);
Student stu = studentService.selectStudentById(id);
System.out.println(stu);
request.setAttribute("student", stu);
return mapping.findForward("select");
}catch(Exception e){
e.printStackTrace();
return mapping.findForward("select");
}
}
public ActionForward selectByName(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String name = request.getParameter("parameter");
Student stu = studentService.selectStudentByName(name);
request.setAttribute("student", stu);
return mapping.findForward("/select.jsp");
}
protected Map getKeyMethodMap() {
Map<String, String> map = new HashMap<String, String>();
map.put("student.message.id", "selectById");
map.put("student.message.name", "selectByName");
return map;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?