JavaWeb实现学生信息管理系统

基于javaweb实现的学生信息管理系统。有兴趣的小伙伴一起来看看吧!



一、项目简介

该项目完全基于JavaWeb实现,没有使用任何的后端框架,对新手朋友来说也是比较友好。此项目前端使用layui编写,界面非常的漂亮美观。分为学生端和管理端,原本之前要加上教师端,后因时间有限便没有在继续编写。功能也比较全面,基本功能都有。

二、项目环境

  • 数据库:MySQL8.0版本
  • 版本:jdk1.8
  • 开发工具:idea2022
  • 所用技术
    ajax+jq+layui+mysql+c3p0

三、项目结构

由于电脑屏幕有限就不依次展开了。

  • 后端
    在这里插入图片描述
  • 前端
    在这里插入图片描述

四、项目展示

登录
在这里插入图片描述

学生信息
在这里插入图片描述
成绩信息
在这里插入图片描述
密码修改
在这里插入图片描述
添加信息
在这里插入图片描述
主页
在这里插入图片描述

五、快速开始

1.数据表结构

student表
在这里插入图片描述
score表
在这里插入图片描述
user表
在这里插入图片描述

2.新建项目

新建项目以及项目配置我上几篇已经详细讲过,需要的大家自行去看。这里我就不在多说!

3.代码实现

由于代码太多就不全部展示出来!只做部分展示。

1.studentbean

代码如下(示例):

public class StudentBean {

    private int sid; //ID
    private String sname; //姓名
    private String ssex; //性别
    private String sstudynum; //学号
    private String sidcard; 
    private String sschool; //学校
    private String sclass; //班级
    private String smajor; //专业
    private String sphone; //电话
    private String spassword; //密码
    private String suser; //用户名
    private String sdate; //日期

    public void setSuser(String suser) {
        this.suser = suser;
    }

    public void setSid(int sid) {
        this.sid = sid;
    }

    public void setSname(String sname) {
        this.sname = sname;
    }

    public void setSsex(String ssex) {
        this.ssex = ssex;
    }

    public void setSstudynum(String sstudynum) {
        this.sstudynum = sstudynum;
    }

    public void setSidcard(String sidcard) {
        this.sidcard = sidcard;
    }

    public void setSschool(String sschool) {
        this.sschool = sschool;
    }

    public void setSclass(String sclass) {
        this.sclass = sclass;
    }

    public void setSmajor(String smajor) {
        this.smajor = smajor;
    }

    public void setSphone(String phone) {
        this.sphone = phone;
    }

    public void setSpassword(String spassword) {
        this.spassword = spassword;
    }

    public void setSdate(String sdate) {
        this.sdate = sdate;
    }

    public int getSid() {
        return sid;
    }

    public String getSname() {
        return sname;
    }

    public String getSsex() {
        return ssex;
    }

    public String getSstudynum() {
        return sstudynum;
    }

    public String getSidcard() {
        return sidcard;
    }

    public String getSschool() {
        return sschool;
    }

    public String getSclass() {
        return sclass;
    }

    public String getSmajor() {
        return smajor;
    }

    public String getSphone() {
        return sphone;
    }

    public String getSpassword() {
        return spassword;
    }

    public String getSuser() {
        return suser;
    }

    public String getSdate() {
        return sdate;
    }

    public StudentBean() {

    }

    public StudentBean(int sid, String sname, String ssex, String sstudynum, String sidcard, String sschool, String sclass, String smajor, String sphone,String spassword,String suser,String sdate) {
        this.sid = sid;
        this.sname = sname;
        this.ssex = ssex;
        this.sstudynum = sstudynum;
        this.sidcard = sidcard;
        this.sschool = sschool;
        this.sclass = sclass;
        this.smajor = smajor;
        this.sphone = sphone;
        this.spassword = spassword;
        this.suser = suser;
        this.sdate = sdate;
    }

    @Override
    public String toString() {
        return "StudentBean{" +
                "sid=" + sid +
                ", sname='" + sname + '\'' +
                ", ssex='" + ssex + '\'' +
                ", sstudynum='" + sstudynum + '\'' +
                ", sidcard='" + sidcard + '\'' +
                ", sschool='" + sschool + '\'' +
                ", sclass='" + sclass + '\'' +
                ", smajor='" + smajor + '\'' +
                ", sphone='" + sphone + '\'' +
                ", spassword='" + spassword +'\''+
                ", suser='" + suser +'\''+
                ", sdate='" + sdate +'\''+
                '}';
    }
}

2.studentdaoimpl

代码如下(示例):

public class StudenDaoImpl implements StudentDaoInter {

    QueryRunner queryRunner = new QueryRunner(MySQLTools.getDataSource());

    /**
     * 添加学生信息
     * @param studentBean
     * @throws SQLException
     */
    @Override
    public void AddStudent(StudentBean studentBean) throws SQLException {
        queryRunner.update("INSERT INTO sstudent VALUES(?,?,?,?,?,?,?,?,?,?,?,?)",null,studentBean.getSuser(),studentBean.getSname(),
                studentBean.getSsex(),studentBean.getSstudynum(),studentBean.getSidcard(),studentBean.getSschool(),
                studentBean.getSclass(),studentBean.getSmajor(),studentBean.getSphone(),"666666",studentBean.getSdate());
    }

    /**
     * 验证学号信息是否重复
     * @param num
     * @return
     * @throws SQLException
     */
    @Override
    public StudentBean findStudyNum(String num) throws SQLException {
        return queryRunner.query("SELECT * FROM sstudent WHERE sstudynum = ?", new BeanHandler<StudentBean>(StudentBean.class),num);
    }

    /**
     * 验证身份证信息是否重复
     * @param id
     * @return
     * @throws SQLException
     */
    @Override
    public StudentBean findID(String id) throws SQLException {
        return queryRunner.query("SELECT * FROM sstudent WHERE sidcard = ?",new BeanHandler<StudentBean>(StudentBean.class),id);
    }

    /**
     * 验证手机号是否重复
     * @param phone
     * @return
     * @throws SQLException
     */
    @Override
    public StudentBean findPhone(String phone) throws SQLException {
        return queryRunner.query("SELECT * FROM sstudent WHERE sphone = ?",new BeanHandler<>(StudentBean.class),phone);
    }

    /**
     * 根据学号和身份证号删除学生
     * @param sid
     * @param num
     * @throws SQLException
     * @return
     */
    @Override
    public void deleteStudent(String sid, String num) throws SQLException {
        queryRunner.update("DELETE FROM sstudent WHERE sstudynum = ? AND sidcard = ?",num,sid);
    }

    /**
     * 根据姓名或者身份证查询
     * @param id
     * @return
     * @throws SQLException
     */
    @Override
    public List<StudentBean> findName_ID(String id,String num) throws SQLException {
        return queryRunner.query("SELECT * FROM sstudent WHERE sname= ? OR sidcard = ? OR sstudynum = ?",new BeanListHandler<StudentBean>(StudentBean.class),id,id,num);
    }

    /**
     * 根据身份证编辑学生信息
     * @param studentBean
     * @throws SQLException
     */
    @Override
    public void EditStudent(StudentBean studentBean) throws SQLException {
        queryRunner.update("UPDATE sstudent SET sname = ?,ssex = ?,sstudynum = ?,sschool = ?,sclass = ?,smajor = ?,sphone = ? WHERE sidcard = ?",studentBean.getSname(),
                studentBean.getSsex(),studentBean.getSstudynum(),studentBean.getSschool(),studentBean.getSclass(),studentBean.getSmajor(),studentBean.getSphone(),studentBean.getSidcard());
    }

    /**
     * 批量删除学生
     * @param sids
     * @throws SQLException
     */
    @Override
    public void deleteStudentes(String sids) throws SQLException {
        queryRunner.update("DELETE FROM sstudent WHERE sid = ?",sids);
    }

    /**
     * 查询性别
     * 根据性别显示学生信息
     * @param state
     * @return
     * @throws SQLException
     */
    @Override
    public List<StudentBean> findSex(String state) throws SQLException {
        return queryRunner.query("SELECT * FROM sstudent WHERE ssex = ?",new BeanListHandler<StudentBean>(StudentBean.class),state);
    }

    /**
     * 学生登录查询信息
     * 学生登录的时候根据用户输入参数查询所有信息
     * @param num
     * @return
     * @throws SQLException
     */
    @Override
    public StudentBean findStudentid_num(String num) throws SQLException {
        return queryRunner.query("SELECT * FROM sstudent WHERE sidcard = ? OR sstudynum = ? OR suser = ?",new BeanHandler<StudentBean>(StudentBean.class),num,num,num);
    }

    /**
     * 查询学生用户名
     * @param num
     * @return
     * @throws SQLException
     */
    @Override
    public StudentBean findStudentuser(String num) throws SQLException {
        return queryRunner.query("SELECT * FROM sstudent WHERE suser = ?",new BeanHandler<StudentBean>(StudentBean.class),num);
    }

    /**
     * 学生修改自己的密码
     * 学生登录学生页面可自行修改登录密码
     * @param studentBean
     * @throws SQLException
     */
    @Override
    public void EditStudentpassword(StudentBean studentBean) throws SQLException {
        queryRunner.update("UPDATE sstudent SET spassword = ?, sdate = ? WHERE sstudynum = ? OR sidcard = ?",
                studentBean.getSpassword(),studentBean.getSdate(),studentBean.getSstudynum(),studentBean.getSidcard());
    }

    /**
     * 查询总记录数
     * @return
     * @throws SQLException
     */
    @Override
    public int findcount() throws SQLException {
        Long resust = (Long) queryRunner.query("SELECT count(*) FROM sstudent", new ScalarHandler());
        return resust.intValue();
    }

    /**
     * 分页查询
     * @param sql 要执行的sql语句
     * @param param 参数
     * @return
     */
    public List<StudentBean> getStudentList(String sql, List<Object> param) {
        //数据集合
        List<StudentBean> list = new LinkedList<>();
        try {
            //获取数据库连接
            Connection conn = MySQLTools.getConnection();
            //预编译
            PreparedStatement ps = conn.prepareStatement(sql);
            //设置参数
            if(param != null && param.size() > 0){
                for(int i = 0;i < param.size();i++){
                    ps.setObject(i+1, param.get(i));
                }
            }
            //执行sql语句
            ResultSet rs = ps.executeQuery();
            //获取元数据
            ResultSetMetaData meta = rs.getMetaData();
            //遍历结果集
            while(rs.next()){
                //创建对象
                StudentBean stu = new StudentBean();
                //遍历每个字段
                for(int i=1;i <= meta.getColumnCount();i++){
                    String field = meta.getColumnName(i);
                    BeanUtils.setProperty(stu, field, rs.getObject(field));
                }

                //添加到集合
                list.add(stu);
            }
            //关闭连接
            MySQLTools.closeConnection();
            MySQLTools.close(ps);
            MySQLTools.close(rs);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

3.studentserviceimpl

代码如下(示例):

public class StudentServiceImpl implements StudentServiceInter {

    StudentDaoInter dao = new StudenDaoImpl();

    /**
     * 添加学生信息
     * @param studentBean
     * @throws SQLException
     */
    @Override
    public void AddStudent(StudentBean studentBean) throws SQLException {
         dao.AddStudent(studentBean);
    }

    /**
     * 查询总记录数
     * @return
     * @throws SQLException
     */
    @Override
    public int findcount() throws SQLException {
        return dao.findcount();
    }

    /**
     * 验证身份证信息是否重复
     * @param id
     * @return
     * @throws SQLException
     */
    @Override
    public StudentBean findID(String id) throws SQLException {
        return dao.findID(id);
    }

    /**
     * 验证手机号是否重复
     * @param phone
     * @return
     * @throws SQLException
     */
    @Override
    public StudentBean findPhone(String phone) throws SQLException {
        return dao.findPhone(phone);
    }

    /**
     * 根据学号和身份证号删除学生
     * @param sid
     * @param num
     * @return
     * @throws SQLException
     */
    @Override
    public void deleteStudent(String sid, String num) throws SQLException {
        dao.deleteStudent(sid,num);
    }

    /**
     * 根据学号或者姓名查询
     * @param id
     * @return
     * @throws SQLException
     */
    @Override
    public List<StudentBean> findName_ID(String id,String num) throws SQLException {
        return dao.findName_ID(id,num);
    }

    /**
     * 根据身份证修改学生信息
     * @param studentBean
     * @throws SQLException
     */
    @Override
    public void EditStudent(StudentBean studentBean) throws SQLException {
        dao.EditStudent(studentBean);
    }

    /**
     * 批量删除学生
     * @param sids
     * @throws SQLException
     */
    @Override
    public void deleteStudentes(String sids) throws SQLException {
        dao.deleteStudentes(sids);
    }

    /**
     * 查询性别
     * @param state
     * @return
     * @throws SQLException
     */
    @Override
    public List<StudentBean> findSex(String state) throws SQLException {
        return dao.findSex(state);
    }

    /**
     * 学生登录显示个人信息
     * @param num
     * @return
     * @throws SQLException
     */
    @Override
    public StudentBean findStudentid_num(String num) throws SQLException {
        return dao.findStudentid_num(num);
    }

    /**
     * 查询用户名
     * @param num
     * @return
     * @throws SQLException
     */
    @Override
    public StudentBean findStudentuser(String num) throws SQLException {
        return dao.findStudentuser(num);
    }

    /**
     * 学生修改自己的密码
     * 学生登录学生页面可自行修改登录密码
     * @param studentBean
     * @throws SQLException
     */
    @Override
    public void EditStudentpassword(StudentBean studentBean) throws SQLException {
        dao.EditStudentpassword(studentBean);
    }

    /**
     * 验证学号信息是否重复
     * @param num
     * @return
     * @throws SQLException
     */
    @Override
    public StudentBean findStudyNum(String num) throws SQLException {
        return dao.findStudyNum(num);
    }

    /**
     * 分页获取学生
     *
     * @param student 学生信息
     * @param page    分页
     * @return
     */
    public String getStudentList(StudentBean student, PageBean page) throws SQLException {
        //sql语句
        StringBuffer sb = new StringBuffer("SELECT * FROM sstudent ");
        //参数
        List<Object> param = new LinkedList<>();
        //判断条件
        //添加排序
        sb.append("ORDER BY sid DESC ");
        //分页
        if (page != null) {
            param.add(page.getStart());
            param.add(page.getSize());
            sb.append("limit ?,?");
        }
        String sql = sb.toString().replaceFirst("AND", "WHERE");
        //获取数据
        List<StudentBean> list = dao.getStudentList(sql, param);
        //获取总记录数
        long total = findcount();
        //定义Map
        Map<String, Object> jsonMap = new HashMap<String, Object>();
        //total键 存放总记录数,必须的
        //rows键 存放每页记录 list
        jsonMap.put("code", 0);
        jsonMap.put("msg", "");
        jsonMap.put("count", total);
        jsonMap.put("data", list);
        //格式化Map,以json格式返回数据
        String result = JSONObject.fromObject(jsonMap).toString();
        //返回
        return result;

    }

4.studentservlet

代码如下(示例):

data = pd.read_csv(
    @WebServlet("/StudentServlet.do")
public class StudentServlet extends HttpServlet {

    StudentServiceInter stuserivce = new StudentServiceImpl();
    ScoreServiceInter scoreservice = new ScoreServiceImpl();
    UserServiceInter imgservice = new UserServiceImpl();
    StuStatusServiceInter statusservice = new StuStatusServiceImpl();


    /**
     * doGET数据接收与转发
     *
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    /**
     * doPOST数据获取
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String method = request.getParameter("method");
        try {
            if ("StudentInfiList".equalsIgnoreCase(method)) {//管理员学生分页显示
                do_StudentList(request, response);
            } else if ("AddStudentSure".equalsIgnoreCase(method)) {//管理员添加学生提交
                do_AddStudent(request, response);
            } else if ("DelStudent".equalsIgnoreCase(method)) {//管理员删除单个学生提交
                do_DelStudent(request, response);
            } else if ("ReshStudent".equalsIgnoreCase(method)) {//管理员刷新
                do_ReshStudent(request, response);
            } else if ("EditStudent".equalsIgnoreCase(method)) {//管理员编辑学生信息按钮
                do_EditStudentForword(request, response);
            } else if ("EditStudentSure".equalsIgnoreCase(method)) {//管理员编辑学生信息提交按钮
                do_EditStudent(request, response);
            }else if("DelStudentes".equalsIgnoreCase(method)){//管理员批量删除学生信息
                do_DelStudentes(request,response);
            }else if("StudentSexList".equalsIgnoreCase(method)){//管理员查询学生状态信息(男女)
                do_InquireState(request,response);
            }else if("EditStudentPasswordSure".equalsIgnoreCase(method)){ //学生修改自己登录密码
                do_EditStudentPwd(request,response);
            }else if("StudentfindStatus".equalsIgnoreCase(method)){ //学生查询自己学籍信息
                do_StudentfindStatus(request,response);
            }
        } catch (SQLException | InvocationTargetException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    /**
     * 分页获取学生信息
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     * @throws SQLException
     */
    private void do_StudentList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
        int page = Integer.parseInt(request.getParameter("page"));
        int limit = Integer.parseInt(request.getParameter("limit"));
        System.out.println("用户查询当前页为:" + page + ";每页查询数量为:" + limit + ";");
        //封装参数
        StudentBean student = new StudentBean();
        //获取数据
        String result = stuserivce.getStudentList(student, new PageBean(page, limit));
        //返回数据
        System.out.println("查询到的数据为:\n" + result + ";\n");
        response.getWriter().write(result);
    }

    /**
     * 添加学生信息
     *
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     * @throws SQLException
     * @throws InvocationTargetException
     * @throws IllegalAccessException
     */
    private void do_AddStudent(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, InvocationTargetException, IllegalAccessException {
        String name = request.getParameter("sname");
        String Num = request.getParameter("sstudynum");
        String ID = request.getParameter("sidcard");
        String Phone = request.getParameter("sphone");
        System.out.println("用户输入学号为:" + Num + ";身份证号码为:" + ID + ";电话号码为:" + Phone + ";");
        StudentBean student = new StudentBean();
        //获取参数名
        Enumeration<String> pNames = request.getParameterNames();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String strCurrentTime = df.format(new Date());
        student.setSdate(strCurrentTime);
        while (pNames.hasMoreElements()) {
            String pName = pNames.nextElement();
            String value = request.getParameter(pName);
            BeanUtils.setProperty(student, pName, value);
        }

        String msg = null;

        //手机号正则验证
        if ((TextTools.checkPhoneNo(Phone)) && (Phone.length() == 11)) {
            System.out.println("手机号正确");
        } else {
            msg = "Add_PhonelensFalse";
            response.getWriter().write(msg);
            return;
        }
        if ((TextTools.checkIDNo(ID)) && (ID.length() == 18)) {
            System.out.println("身份证正确");
        } else {
            msg = "Add_IDlensFalse";
            response.getWriter().write(msg);
            return;
        }
        if (Num.length() != 10) {
            System.out.println("学号格式错误");
            msg = "Add_StudylensFalse";
            response.getWriter().write(msg);
            return;
        }
        String suser = TextTools.getRandomString(6);//随机生成用户名
        student.setSuser(suser);
        StudentBean user = stuserivce.findStudentuser(suser); //查询用户名
        if (user != null){
            System.out.println("用户名重复");
            msg = "Add_UserFalse";
            response.getWriter().write(msg);
            return;
        }
        StudentBean id = stuserivce.findID(ID); //查询身份证
        StudentBean num = stuserivce.findStudyNum(Num); //查询学号
        StudentBean phone = stuserivce.findPhone(Phone); //查询电话号码

        if (id != null) {
            System.out.println("查询到的身份证信息为:" + id + ";");
            msg = "Add_IDFalse";
        }
        if (num != null) {
            System.out.println("查询到的学号信息为:" + num + ";");
            msg = "Add_StudyFalse";
        }
        if (phone != null) {
            System.out.println("查询到的电话号码信息为:" + Phone + ";");
            msg = "Add_PhoneFalse";
        }

        if ((id == null) && (num == null)) {
            stuserivce.AddStudent(student); //添加学生
            scoreservice.ScooreAddStudent(Num,name); //添加成绩列表的学号
            imgservice.ImgAddStudent(ID); //添加头像的身份证
            msg = "Add_StudentTrue";
        }
        response.getWriter().write(msg);
    }

    /**
     * 删除学生信息
     *
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     * @throws SQLException
     */
    private void do_DelStudent(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
        String num = request.getParameter("num");
        String Id = request.getParameter("Id");
        System.out.println("管理员删除学号为:" + num + ",  身份证号码为:" + Id + " 的学生");
        stuserivce.deleteStudent(Id, num); //删除学生
        statusservice.EditStuStatus(Id); //编辑
        response.getWriter().write("Del_True");
    }

    /**
     * 根据条件查询
     * 身份证姓名学号
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     * @throws SQLException
     */
    private void do_ReshStudent(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
        String id = request.getParameter("inputVal");
        String num = request.getParameter("inputVal1");
        System.out.println("用户输入姓名或者身份证号为:" + id + ";");
        System.out.println("用户输入的学号为:" + num + ";");

        List<StudentBean> list = stuserivce.findName_ID(id, num); //根据学号身份证查询
        System.out.println("用户查询到的信息为:" + list + ";");
        int count = stuserivce.findcount(); //查询数量
        //定义Map
        Map<String, Object> jsonMap = new HashMap<String, Object>();
        jsonMap.put("code", 0);
        jsonMap.put("msg", "");
        jsonMap.put("count", count);
        jsonMap.put("data", list);
        //格式化Map,以json格式返回数据
        String result = JSONObject.fromObject(jsonMap).toString();
        //返回
        response.getWriter().write(result);
    }

    /**
     * 编辑学生信息页面跳转
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     * @throws SQLException
     */
    private void do_EditStudentForword(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, InvocationTargetException, IllegalAccessException {
        String Id = request.getParameter("Id");
        System.out.println("获取到学生身份证号码为:" + Id + ";");
        StudentBean list = stuserivce.findID(Id); //根据身份证查询
        System.out.println("身份证号获取的信息为:" + list + ";");
        request.getSession().setAttribute("stu", list);
        response.getWriter().write("Edit_True");
    }

    /**
     * 编辑学生信息数据提交
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     * @throws SQLException
     * @throws InvocationTargetException
     * @throws IllegalAccessException
     */
    private void do_EditStudent(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, InvocationTargetException, IllegalAccessException {
        //获取参数名
        Enumeration<String> pNames = request.getParameterNames();
        StudentBean student = new StudentBean();
        while (pNames.hasMoreElements()) {
            String pName = pNames.nextElement();
            String value = request.getParameter(pName);
            BeanUtils.setProperty(student, pName, value);

        }
        String Num = request.getParameter("sstudynum");
        System.out.println("用户输入学号为:" + Num + ";");
        String Phone = request.getParameter("sphone");
        System.out.println("用户输入手机号为:" + Phone + ";");
        String msg = null;

        //手机号正则验证
        if ((TextTools.checkPhoneNo(Phone)) && (Phone.length() == 11)) {
            System.out.println("手机号正确");
        } else {
            msg = "Add_PhonelensFalse";
            response.getWriter().write(msg);
            return;
        }
        if (Num.length() != 10) {
            System.out.println("学号格式错误");
            msg = "Add_StudylensFalse";
            response.getWriter().write(msg);
            return;
        }

        stuserivce.EditStudent(student); //修改学生信息
        msg = "Add_StudentTrue";

        response.getWriter().write(msg);
    }

    /**
     * 批量删除学生
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     * @throws SQLException
     * @throws InvocationTargetException
     * @throws IllegalAccessException
     */
    private void do_DelStudentes(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, InvocationTargetException, IllegalAccessException {
        String id = request.getParameter("ids");
        String a[]=id.split(",");
       for(int i = 0 ; i < a.length ; i++) {
           String ida = a[i];
           System.out.println("管理员删除ID为:"+ida+" 的学生");
           stuserivce.deleteStudentes(ida); //删除学生
           statusservice.EditStuStatus(ida); //删除学生时修改学籍状态
       }
        response.getWriter().write("DelStudents_True");
    }

    /**
     * 根据性别查询学生
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     * @throws SQLException
     * @throws InvocationTargetException
     * @throws IllegalAccessException
     */
    private void do_InquireState(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, InvocationTargetException, IllegalAccessException {
        String state = request.getParameter("state");
        System.out.println("用户选择状态为:"+state+";");
        List<StudentBean> list = stuserivce.findSex(state); //性别查询学生
        System.out.println("查询到的数据为:"+list+" ;");
        int count = stuserivce.findcount(); //查询数量
        //定义Map
        Map<String, Object> jsonMap = new HashMap<String, Object>();
        jsonMap.put("code", 0);
        jsonMap.put("msg", "");
        jsonMap.put("count", count);
        jsonMap.put("data", list);
        //格式化Map,以json格式返回数据
        String result = JSONObject.fromObject(jsonMap).toString();
        //返回
        response.getWriter().write(result);
    }

    /**
     * 学生修改自己账号密码
     * 学生登录学生页面可自行修改登录密码
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     * @throws SQLException
     * @throws InvocationTargetException
     * @throws IllegalAccessException
     */
    private void do_EditStudentPwd(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, InvocationTargetException, IllegalAccessException {
        String id_num = request.getParameter("id_num");
        String newpwd = request.getParameter("newpassword");
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String strCurrentTime = df.format(new Date());
        StudentBean student = new StudentBean();
        student.setSpassword(newpwd);
        student.setSstudynum(id_num);
        student.setSidcard(id_num);
        student.setSdate(strCurrentTime);
        stuserivce.EditStudentpassword(student);
        response.getWriter().write("stupassword");
    }

    /**
     * 学生查询学籍信息
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     * @throws SQLException
     * @throws InvocationTargetException
     * @throws IllegalAccessException
     */
    private void do_StudentfindStatus(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, InvocationTargetException, IllegalAccessException {
        String id = request.getParameter("id");
        System.out.println(id);
        StuStatusBean list = statusservice.findIDStuStatus(id);
        System.out.println(list);
        if(list == null){
            response.getWriter().write("NoStustatus");
        }else {
            response.getWriter().write("StuStatusTrue");
            request.getServletContext().setAttribute("stu_status", list);
        }
    }

总结

以上就是今天要讲的内容,最近由于各种原因,没时间写文章。公众浩 ”俊俊同学的笔记“ 感谢大家阅读。

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐