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

import domain.Score;
import service.StudentScoreService;
import service.impl.StudentScoreServiceImpl;
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 = "studentScoreServlet",urlPatterns = {"/studentScore"})
public class StudentScoreServlet extends BaseServlet{

    private StudentScoreService studentScoreService=new StudentScoreServiceImpl();

    public void allStudentScore(HttpServletRequest request, HttpServletResponse response) throws Exception {
        List<Score> scoreList = studentScoreService.allStudentScore();
        System.out.println(scoreList);
        if (scoreList != null) {
            request.setAttribute("scoreList", scoreList);
        } else {
            request.setAttribute("msg", "无数据");
        }
        request.getRequestDispatcher("/pages/studentScore/allScore.jsp").forward(request, response);

    }


    public void findStudentScoreById(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String id=request.getParameter("id");
        Score score = studentScoreService.findStudentScoreById(id);
        if (score!=null) {
            request.setAttribute("score",score);
        } else {
            request.setAttribute("scoreMsgError","查询失败,可能无id");
        }
        request.getRequestDispatcher("/pages/studentScore/updateScore.jsp").forward(request, response);
    }

    public void updateStudentScore(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Score score = new Score();
        Map<String, String[]> map = request.getParameterMap();
        try {
            MyBeanUtils.populate(score, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(score);
        int row = studentScoreService.updateStudentScore(score);
        if (row == 1) {
            request.setAttribute("scoreMsg","修改成功");
        } else {
            request.setAttribute("scoreMsg","修改失败,可能修改后的id重复或者不存在");
        }
        request.getRequestDispatcher("/pages/studentScore/updateScore.jsp").forward(request, response);
    }

    public void insertStudentScore(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Score score = new Score();
        Map<String, String[]> map = request.getParameterMap();
        try {
            MyBeanUtils.populate(score, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        int row = studentScoreService.insertStudentScore(score);
        if (row == 1) {
            request.setAttribute("scoreMsg","添加成功");
        } else {
            request.setAttribute("scoreMsg","添加失败,id可能重复");
        }
        request.getRequestDispatcher("/pages/studentScore/insertScore.jsp").forward(request, response);
    }

    public void delStudentScore(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String id=request.getParameter("id");
        int row = studentScoreService.delStudentScore(id);
        if (row == 1) {
            request.setAttribute("stuMsg","删除成功");
        } else {
            request.setAttribute("stuMsg","删除失败,可能无id");
        }
        request.getRequestDispatcher("/pages/studentScore/delScore.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日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友