首页>代码>基于jsp+servlet的idea版学生管理系统,前端框架layui>/studentManage/源码/studentManage/src/main/java/controller/StudentInfoServlet.java
package controller;

import domain.Student;
import service.StudentService;
import service.impl.StudentServiceImpl;
import utils.MyBeanUtils;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@WebServlet(name = "studentInfoServlet", urlPatterns = {"/student"})
public class StudentInfoServlet extends BaseServlet {

    private StudentService studentService = new StudentServiceImpl();

    public void home(HttpServletRequest request, HttpServletResponse response) throws Exception {
        List<Student> studentList = studentService.queryAllStudent();
        System.out.println(studentList);
        if (studentList != null) {
            request.setAttribute("studentList", studentList);
        } else {
            request.setAttribute("msg", "无数据");
        }
        request.getRequestDispatcher("/pages/studentInfo/allInfo.jsp").forward(request, response);

    }

    public void insertInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Student student = new Student();
        Map<String, String[]> map = request.getParameterMap();
        try {
            MyBeanUtils.populate(student, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        int row = studentService.insertStudentInfo(student);
        if (row == 1) {
            request.setAttribute("stuMsg","添加成功");
        } else {
            request.setAttribute("stuMsg","添加失败,id可能重复");
        }
        request.getRequestDispatcher("/pages/studentInfo/insertInfo.jsp").forward(request, response);
    }

    public void delInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String id=request.getParameter("id");
        int row = studentService.delStudentInfo(id);
        if (row == 1) {
            request.setAttribute("stuMsg","删除成功");
        } else {
            request.setAttribute("stuMsg","删除失败,可能无id");
        }
        request.getRequestDispatcher("/pages/studentInfo/delInfo.jsp").forward(request, response);
    }

    public void findStudentInfoById(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String id=request.getParameter("id");
        Student student = studentService.findStudentInfoById(id);
        if (student!=null) {
            request.setAttribute("student",student);
        } else {
            request.setAttribute("stuMsgError","查询失败,可能无id");
        }
        request.getRequestDispatcher("/pages/studentInfo/updateInfo.jsp").forward(request, response);
    }



    public void updateStudentInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Student student = new Student();
        Map<String, String[]> map = request.getParameterMap();
        try {
            MyBeanUtils.populate(student, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(student);
        int row = studentService.updateStudentInfo(student);
        if (row == 1) {
            request.setAttribute("stuMsg","修改成功");
        } else {
            request.setAttribute("stuMsg","修改失败,可能修改后的id重复或者不存在");
        }
        request.getRequestDispatcher("/pages/studentInfo/updateInfo.jsp").forward(request, response);
    }
}
最近下载更多
李清清  LV2 11月6日
xiao小果  LV13 8月19日
破剑茶寮  LV4 6月26日
15719908287  LV9 6月19日
TY0165  LV20 6月18日
慵懒的小橘猫  LV11 6月8日
zhangy2733  LV1 6月3日
最近浏览更多
haomc052829  LV2 11月18日
李清清  LV2 11月6日
yimaoermao  LV1 9月14日
xiao小果  LV13 8月19日
binzhuyou  LV2 7月4日
赵鑫cdsaljkdfsa  LV11 6月26日
破剑茶寮  LV4 6月26日
taoshen95  LV15 6月25日
www的行为  LV2 6月20日
zzk3085000785 6月20日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友