欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java实战在线选课系统的实现流程

程序员文章站 2022-06-15 18:10:52
一、项目简述功能: 系统分为三个角色。最高权限管理员,学生,教师,包括 学生管理,教师管理,课程管理,选课,退课,成绩查 询。,教学课程,查看选课名单等等功能完全齐备。二、项目运行环境配置: jdk1...

一、项目简述

功能: 系统分为三个角色。最高权限管理员,学生,教师,包括 学生管理,教师管理,课程管理,选课,退课,成绩查 询。,教学课程,查看选课名单等等功能完全齐备。

二、项目运行

环境配置: jdk1.8 + tomcat8.5 + mysql + eclispe (intellij idea,eclispe,myeclispe,sts 都支持)

项目技术: jsp +spring + springmvc + mybatis + bootstrap4+ css + javascript + jquery + ajax + particles.js+ maven等等。

Java实战在线选课系统的实现流程

Java实战在线选课系统的实现流程

Java实战在线选课系统的实现流程

Java实战在线选课系统的实现流程

Java实战在线选课系统的实现流程

用户管理控制器:

/**
 * 用户管理控制器
 */
@requestmapping("/user/")
@controller
public class usercontroller {
    @autowired
    private iuserservice userservice;
    @autowired
    private iroleservice roleservice;
 
    @resource
    private processengineconfiguration configuration;
    @resource
    private processengine engine;
 
    @getmapping("/index")
    @apioperation("跳转用户页接口")
    @preauthorize("hasrole('管理员')")
    public string index(string menuid,model model){
        list<role> roles = queryallrole();
        model.addattribute("roles",roles);
        model.addattribute("menuid",menuid);
        //用户首页
        return "views/user/user_list";
    }
 
    @getmapping("/listpage")
    @apioperation("查询用户分页数据接口")
    @apiimplicitparams({
            @apiimplicitparam(name = "userquery", value = "用户查询对象", defaultvalue = "userquery对象")
    })
    @responsebody
    @preauthorize("hasrole('管理员')")
    public pagelist listpage(userquery userquery){
        return  userservice.listpage(userquery);
    }
 
    //添加用户
    @postmapping("/adduser")
    @apioperation("添加用户接口")
    @responsebody
    public map<string,object> adduser(user user){
        map<string, object> ret = new hashmap<>();
        ret.put("code",-1);
        if(stringutils.isempty(user.getusername())){
            ret.put("msg","请填写用户名");
            return ret;
        }
        if(stringutils.isempty(user.getpassword())){
            ret.put("msg","请填写密码");
            return ret;
        }
        if(stringutils.isempty(user.getemail())){
            ret.put("msg","请填写邮箱");
            return ret;
        }
        if(stringutils.isempty(user.gettel())){
            ret.put("msg","请填写手机号");
            return ret;
        }
        if(stringutils.isempty(user.getheadimg())){
            ret.put("msg","请上传头像");
            return ret;
        }
        if(userservice.adduser(user)<=0) {
            ret.put("msg", "添加用户失败");
            return ret;
        }
        ret.put("code",0);
        ret.put("msg","添加用户成功");
        return ret;
    }
 
    /**
     * 修改用户信息操作
     * @param user
     * @return
     */
    @postmapping("/editsaveuser")
    @apioperation("修改用户接口")
    @preauthorize("hasrole('管理员')")
    @responsebody
    public message editsaveuser(user user){
        if(stringutils.isempty(user.getusername())){
          return message.error("请填写用户名");
        }
        if(stringutils.isempty(user.getemail())){
            return message.error("请填写邮箱");
        }
        if(stringutils.isempty(user.gettel())){
            return message.error("请填写手机号");
        }
        try {
            userservice.editsaveuser(user);
            return message.success();
        } catch (exception e) {
            e.printstacktrace();
            return message.error("修改用户信息失败");
        }
 
    }
 
    //添加用户
    @getmapping("/deleteuser")
    @apioperation("删除用户接口")
    @apiimplicitparams({
            @apiimplicitparam(name = "id", value = "如:88",required = true)
    })
    @preauthorize("hasrole('管理员')")
    @responsebody
    public ajaxresult deleteuser(@requestparam(required = true) long id){
        ajaxresult ajaxresult = new ajaxresult();
        try {
            userservice.deleteuser(id);
        } catch (exception e) {
            e.printstacktrace();
            return new ajaxresult("删除失败");
        }
 
        return ajaxresult;
    }
 
    @postmapping(value="/deletebatchuser")
    @apioperation("批量删除用户接口")
    @preauthorize("hasrole('管理员')")
    @responsebody
    public ajaxresult deletebatchuser(string ids){
        string[] idsarr = ids.split(",");
        list list = new arraylist();
        for(int i=0;i<idsarr.length;i++){
            list.add(idsarr[i]);
        }
        try{
            userservice.batchremove(list);
            return new ajaxresult();
        }catch(exception e){
           return new ajaxresult("批量删除失败");
        }
    }
 
    //查询所有角色
    public list<role> queryallrole(){
        return roleservice.queryall();
    }
 
    //添加用户的角色
    @postmapping("/adduserrole")
    @apioperation("添加用户角色接口")
    @apiimplicitparams({
            @apiimplicitparam(name = "parammap", value = "如:{userid:1,[1,2,3,4]]}")
    })
    @responsebody
    public ajaxresult adduserrole(@requestbody map parammap){
        ajaxresult ajaxresult = new ajaxresult();
        string userid = (string)parammap.get("userid");
        list roleids = (list) parammap.get("roleids");
        try {
            //添加用户对应的角色
            roleservice.adduserrole(userid,roleids);
            return ajaxresult;
        }catch (exception e){
            e.printstacktrace();
            return new ajaxresult("保存角色失败");
        }
 
    }
 
 
 
 
    //添加用户
    @requestmapping("/regsaveuser")
    @responsebody
    public long addteacher(user user){
        system.out.println("保存用户...."+user);
        userservice.adduser(user);
 
        //保存工作流程操作
        identityservice is = engine.getidentityservice();
        // 添加用户组
        org.activiti.engine.identity.user userinfo = userservice.saveuser(is, user.getusername());
        // 添加用户对应的组关系
        group stugroup = new groupentityimpl();
        stugroup.setid("stugroup");
        group tgroup = new groupentityimpl();
        tgroup.setid("tgroup");
        if(user.gettype() == 2) {
            //保存老师组
            userservice.saverel(is, userinfo, tgroup);
        }
        if(user.gettype() == 3) {
            //保存学生组
            userservice.saverel(is, userinfo, stugroup);
        }
 
        long userid = user.getid();
        return userid;
    }
 
    /**
     * 修改密码页面
     * @return
     */
    @requestmapping(value="/update_pwd",method=requestmethod.get)
    public string updatepwd(){
        return "views/user/update_pwd";
    }
 
    /**
     * 修改密码操作
     * @param oldpwd
     * @param newpwd
     * @return
     */
    @responsebody
    @postmapping("/update_pwd")
    public message updatepassword(@requestparam(name="oldpwd",required=true)string oldpwd,
                                  @requestparam(name="newpwd",required=true)string newpwd){
        string username = commonutils.getloginuser().getusername();
        user userbyusername = userservice.finduserbyusername(username);
        if(userbyusername!=null){
            string password = userbyusername.getpassword();
            bcryptpasswordencoder bcryptpasswordencoder = new bcryptpasswordencoder();
            boolean matches = bcryptpasswordencoder.matches(oldpwd, password);
            if(!matches){
                return message.error("旧密码不正确");//true
            }
            userbyusername.setpassword(bcryptpasswordencoder.encode(newpwd));
 
            if(userservice.edituserpassword(userbyusername)<=0){
                return message.error("密码修改失败");
            }
        }
        return message.success();
    }
 
    /**
     * 清除缓存
     * @param request
     * @param response
     * @return
     */
    @responsebody
    @postmapping("/clear_cache")
    public message clearcache(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {
        response.setheader("cache-control","no-store");
        response.setheader("pragrma","no-cache");
        response.setdateheader("expires",0);
      return  message.success();
    }
}

角色控制器:

@controller
public class rolecontroller {
 
    @autowired
    private iroleservice roleservice;
 
    @autowired
    private ipermissionservice permissionservice;
 
 
 
 
    @preauthorize("hasrole('管理员')")
    @responsebody
    @requestmapping("/role/doadd")
    public string doadd(role role){
        //角色添加
        return "ok";
    }
    //添加角色
    @requestmapping("/role/addrole")
    @preauthorize("hasrole('管理员')")
    @responsebody
    public ajaxresult addrole(role role){
        system.out.println("保存角色...."+role);
        try {
            roleservice.saverole(role);
            return new ajaxresult();
        } catch (exception e) {
            e.printstacktrace();
            return new ajaxresult("操作失败");
        }
    }
 
    @preauthorize("hasrole('管理员')")
    @requestmapping("/role/index")
    public string index(model model){
        list<permission> permisisons = permissionservice.findallpermisisons();
        model.addattribute("permissions",permisisons);
        //返回角色
        return "views/role/role_list";
    }
 
    @requestmapping("/role/listpage")
    @responsebody
    public pagelist listpage(rolequery rolequery){
        system.out.println("传递参数:"+rolequery);
        return  roleservice.listpage(rolequery);
    }
 
 
    //修改用户editsaveuser
    @requestmapping("/role/editsaverole")
    @responsebody
    public ajaxresult editsaverole(role role){
        system.out.println("修改角色...."+role);
        try {
            roleservice.editsaverole(role);
            return new ajaxresult();
        } catch (exception e) {
            e.printstacktrace();
        }
        return new ajaxresult("修改失败");
    }
 
    //添加角色
    @requestmapping("/role/deleterole")
    @responsebody
    public ajaxresult deleterole(long id){
        system.out.println("删除角色...."+id);
        ajaxresult ajaxresult = new ajaxresult();
        try {
            roleservice.deleterole(id);
        } catch (exception e) {
            e.printstacktrace();
            return new ajaxresult("删除失败");
        }
        return ajaxresult;
    }
 
    //添加角色权限 addrolepermission
    @requestmapping("/role/addrolepermission")
    @responsebody
    public ajaxresult addrolepermission(@requestbody map parammap){
        ajaxresult ajaxresult = new ajaxresult();
        string roleid = (string)parammap.get("roleid");
        list permissionids = (list) parammap.get("permissionids");
        try {
            //添加角色对应的权限
            roleservice.addrolepermission(roleid,permissionids);
            return ajaxresult;
        }catch (exception e){
            e.printstacktrace();
            return new ajaxresult("保存权限失败");
        }
 
    }
 
}

学生控制器:

@requestmapping("/student")
@controller
@api(tags = "学生管理接口")
public class studentcontroller {
 
    @autowired
    private iuserservice userservice;
 
    @autowired
    private icourseservice courseservice;
 
    @autowired
    private iclassesservice classesservice;
    @resource
    private processengine engine;
 
    @autowired
    private ioperaterlogservice operaterlogservice;
 
    //老师列表
    //后台查询学生列表
    @requestmapping("/index")
    public string index(model model){
        //用户首页
        model.addattribute("courses",courseservice.queryall());
        model.addattribute("classes",classesservice.queryall());
        return "views/student/student_list";
    }
 
    @requestmapping("/listpage")
    @responsebody
    public pagelist listpage(userquery userquery){
        userquery.settype(3l);//2表示老学生
        return  userservice.listpage(userquery);
    }
 
    /**
     * 添加学生操作
     * @param user
     * @return
     */
    @postmapping("/addsavestu")
    @apioperation("添加学生接口")
    @preauthorize("hasrole('管理员')")
    @responsebody
    public message addsavestudent(user user){
        if(stringutils.isempty(user.getusername())){
            return message.error("请填写用户名");
        }
        if(stringutils.isempty(user.getpassword())){
            return message.error("请填写密码");
        }
        if(stringutils.isempty(user.getemail())){
            return message.error("请填写邮箱");
        }
        if(stringutils.isempty(user.gettel())){
            return message.error("请填写手机号");
        }
        if(stringutils.isempty(user.getstunum())){
            return message.error("请填写学号");
        }
        user userbyusername = userservice.finduserbyusername(user.getusername());
        if(userbyusername!=null){
            return message.error("用户名已存在");
        }
        if(userservice.findbystunum(user.getstunum())!=null){
            return message.error("该学号已存在");
        }
        user.settype(3);
        if(userservice.adduser(user)<=0){
            return message.error("学生添加失败");
        }
        //保存工作流程操作
        identityservice is = engine.getidentityservice();
        // 添加用户组
        org.activiti.engine.identity.user userinfo = userservice.saveuser(is, user.getusername());
        // 添加用户对应的组关系
        group stugroup = new groupentityimpl();
        stugroup.setid("stugroup");
        userservice.saverel(is, userinfo, stugroup);
        operaterlogservice.add("添加学生成功,学生名称:"+user.getusername());
        return message.success();
    }
 
 
 
    //修改用户editsaveuser
    @postmapping("/editsavestu")
    @apioperation("修改学生接口")
    @preauthorize("hasrole('管理员')")
    @responsebody
    public message editsavestu(user user){
        if(stringutils.isempty(user.getusername())){
            return message.error("请填写用户名");
        }
        if(stringutils.isempty(user.getemail())){
            return message.error("请填写邮箱");
        }
        if(stringutils.isempty(user.gettel())){
            return message.error("请填写手机号");
        }
        user userbyusername = userservice.finduserbyusername(user.getusername());
        if(userbyusername!=null){
            if(!userbyusername.getid().equals(user.getid())){
                return message.error("该用户名已存在");
            }
        }
        try {
            userservice.editsaveuser(user);
            operaterlogservice.add("编辑学生成功,学生名称:"+user.getusername());
            return message.success();
        } catch (exception e) {
            e.printstacktrace();
            return message.error("学生编辑失败");
        }
 
    }
 
    //editsavestuxk
    @postmapping("/editsavestuxk")
    @apioperation("修改用户接口")
    @apiimplicitparams({
            @apiimplicitparam(name = "user", value = "学生选课")
    })
    @responsebody
    public ajaxresult editsavestuxk(user user){
        try {
            userservice.editsavexk(user);
            operaterlogservice.add("修改学生选课成功,学生名称:"+user.getusername());
            return new ajaxresult();
        } catch (exception e) {
            e.printstacktrace();
        }
        return new ajaxresult("修改失败");
    }
 
 
 
}

教师管理控制器:

@requestmapping("/teacher")
@controller
@api(tags = "教师管理接口")
public class teachercontroller {
 
    @autowired
    private iuserservice userservice;
 
    @autowired
    private iclassesservice classesservice;
    @resource
    private processengine engine;
    @autowired
    private ioperaterlogservice operaterlogservice;
 
 
    //老师列表
    @requestmapping("/index")
    public string index(model model){
        //用户首页
        model.addattribute("classes",classesservice.queryall());
        return "views/teacher/teacher_list";
    }
 
    @requestmapping("/listpage")
    @responsebody
    public pagelist listpage(userquery userquery){
        userquery.settype(2l);//2表示老师
        return  userservice.listpage(userquery);
    }
 
    /**
     * 添加教师操作
     * @param user
     * @return
     */
    @postmapping("/addteacher")
    @apioperation("添加教师接口")
    @responsebody
    @preauthorize("hasrole('管理员')")
    public message addteacher(user user){
        if(stringutils.isempty(user.getusername())){
            return message.error("请填写用户名");
        }
        if(stringutils.isempty(user.getpassword())){
            return message.error("请填写密码");
        }
        if(stringutils.isempty(user.getemail())){
            return message.error("请填写邮箱");
        }
        if(stringutils.isempty(user.gettel())){
            return message.error("请填写手机号");
        }
        user userbyusername = userservice.finduserbyusername(user.getusername());
        if(userbyusername!=null){
            return message.error("用户名已存在");
        }
        user.settype(2);
        if(userservice.adduser(user)<=0){
            return message.error("教师添加失败");
        }
        //保存工作流程操作
        identityservice is = engine.getidentityservice();
        // 添加用户组
        org.activiti.engine.identity.user userinfo = userservice.saveuser(is, user.getusername());
        group tgroup = new groupentityimpl();
        tgroup.setid("tgroup");
        userservice.saverel(is, userinfo, tgroup);
        operaterlogservice.add("添加教师成功,教师名称:"+user.getusername());
        return message.success();
    }
 
 
    /**
     * 修改教师操作
     * @param user
     * @return
     */
    @postmapping("/editsavestu")
    @apioperation("修改教师接口")
    @preauthorize("hasrole('管理员')")
    @responsebody
    public message editsavestu(user user){
        if(stringutils.isempty(user.getusername())){
            return message.error("请填写用户名");
        }
        if(stringutils.isempty(user.getemail())){
            return message.error("请填写邮箱");
        }
        if(stringutils.isempty(user.gettel())){
            return message.error("请填写手机号");
        }
        user userbyusername = userservice.finduserbyusername(user.getusername());
        if(userbyusername!=null){
            if(!userbyusername.getid().equals(user.getid())){
                return message.error("该用户名已存在");
            }
        }
        try {
            userservice.editsaveuser(user);
            operaterlogservice.add("编辑教师成功,教师名称:"+user.getusername());
            return message.success();
        } catch (exception e) {
            e.printstacktrace();
            return message.error("教师信息编辑失败");
        }
 
    }
 
 
}

到此这篇关于java实战在线选课系统的实现流程的文章就介绍到这了,更多相关java 在线选课系统内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!