当前位置:   article > 正文

JavaWeb学生信息管理系统

javaweb学生信息管理系统

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 +'\''+
                '}';
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148

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;
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197

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;

    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184

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);
        }
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375

总结

以上就是今天要讲的内容,最近由于各种原因,没时间写文章。扣 ”248
913 7315“ 感谢大家阅读。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/631513
推荐阅读
相关标签
  

闽ICP备14008679号