Java|Java 实战项目之教材管理系统的实现流程
一、项目简述
功能包括: 管理员可以增删改查教材、教材商、入库教材、用户(用 户包括学生和教师)可以对教材商、教材进行。Excel的导入 导出操作。教师以领取入库的教材,可以退还教材。学生只能在对应的教师那里领取教材,并且可以退还教材、 查询自己已经领取的教材。并且对已领教材付款等等。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
【Java|Java 实战项目之教材管理系统的实现流程】项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。
文章图片
文章图片
文章图片
文章图片
文章图片
查看班级选报信息:
@Servicepublic class TopicsServiceImpl implements TopicsService { @Autowiredprivate MyClassMapper classMapper; @Autowiredprivate StudentMapper studentMapper; @Autowiredprivate SubjectselectedMapper subjectselectedMapper; @Autowiredprivate SubjectMapper subjectMapper; @Autowiredprivate HttpServletRequest request; /*** 查看班级选报信息*/@Overridepublic Listclassinfo(Long id) {MyClass className = classMapper.selectById(id); //查到班级名字List students = studentMapper.selectByListAll(id); //根据student表里班级id查到用户所在班级的所有人List projectselectedlist = new ArrayList<>(); List projectlist = new ArrayList<>(); Subjectselected projectselected = null; Subject project = null; for (int i = 0; i < students.size(); i++) {List tprojectselecteds = subjectselectedMapper.selectBystudentid(students.get(i).getId()); if (tprojectselecteds != null && tprojectselecteds.size() > 0)projectselected = tprojectselecteds.get(0); if (projectselected != null) {projectselectedlist.add(projectselected); } else {projectselected = new Subjectselected(); projectselected.setId(0L); projectselected.setIdProject(0L); projectselected.setIdStudent(0L); projectselected.setStuselectFlag(0L); projectselectedlist.add(projectselected); }}for (int i = 0; i < projectselectedlist.size(); i++) {if (projectselectedlist.get(i).getId() != 0) {projectlist.add(subjectMapper.selectById(projectselectedlist.get(i).getIdProject())); } else {project = new Subject(); project.setProjectname("无"); project.setTeachernames("无"); projectlist.add(project); }}List infolist = new ArrayList<>(); classinfo info = null; for (int i = 0; i < projectlist.size(); i++) {info = new classinfo(); info.setId(students.get(i).getId()); info.setClassName(className.getClassName()); info.setName(students.get(i).getName()); info.setStuNum(students.get(i).getStunum()); info.setProjectName(projectlist.get(i).getProjectname()); info.setTeacherNames(projectlist.get(i).getTeachernames()); info.setStuSelectFlag(projectselectedlist.get(i).getStuselectFlag()); infolist.add(info); }return infolist; } /*** 查看课题信息* 通过classid*/@Overridepublic List topics(Long id) {String specialty = classMapper.selectByspecialty(id); List projectlist = subjectMapper.selectByAll("%" + specialty + "%"); List topicsinfolist = new ArrayList<>(); topicsinfo info = null; for (int i = 0; i < projectlist.size(); i++) {info = new topicsinfo(); info.setProject_id(projectlist.get(i).getId()); info.setProjectType(subjectMapper.selectByprojectType(projectlist.get(i).getIdProjecttype().intValue())); info.setProjectSource(subjectMapper.selectByprojectSource(projectlist.get(i).getIdProjectsource().intValue())); info.setProjectName(projectlist.get(i).getProjectname()); info.setSelectFlag(projectlist.get(i).getSelectFlag()); info.setMarchSpecialty(projectlist.get(i).getMarchspecialty()); info.setTeacherNames(projectlist.get(i).getTeachernames()); topicsinfolist.add(info); }return topicsinfolist; } /*** 课题具体信息*/@Overridepublic List topicsinfo(Long project_id) {List listed = subjectselectedMapper.selectByprojectid(project_id); //中间表request.getSession().setAttribute("listsize",listed.size()); List tolist = new ArrayList<>(); topicsto to = null; Student student = null; for (int i = 0; i < listed.size(); i++) {to = new topicsto(); student = studentMapper.selectByid(listed.get(i).getIdStudent()); if(student == null)continue; to.setStuNum(student.getStunum()); to.setName(student.getName()); to.setStuSelectFlag(listed.get(i).getStuselectFlag()); to.setClassName(classMapper.selectById(student.getIdClass()).getClassName()); tolist.add(to); }return tolist; } /*** 获取该用户是否选报了课题*/ public Long state(Student student) {Subjectselected project = null; List tprojectselecteds = subjectselectedMapper.selectBystudentid(student.getId()); if (tprojectselecteds != null && tprojectselecteds.size() > 0)project = tprojectselecteds.get(0); if (project == null) {return 0L; } elsereturn project.getStuselectFlag(); } /*** 添加选题*/@Overridepublic void insertproject(String project, Long studentid) {Long projectid = subjectMapper.selectByprojectid(project); int flagid = subjectselectedMapper.insertenroll(projectid, studentid); } /*** 删除选题*/@Overridepublic int deleteprojectselectedid(Long id) {int flag = subjectselectedMapper.deleteBystudentId(id); return flag; } /*** 查询课题名**/public String selectprojectname(Long id){String project_Name = subjectMapper.selectById(id).getProjectname(); return project_Name; } /*** 获取该题是否可选*/@Overridepublic Long flag(Long project_id) {return subjectMapper.selectByselectFlag(project_id); }}
班级信息查询业务:
@Servicepublic class ClassServiceImpl implements ClassService { @AutowiredMyClassMapper myClassMapper; @AutowiredSpecialtyService specialtyService; @AutowiredStudentService studentService; @Overridepublic List getClasses(Integer offset, String getName, Long specialtyid, Long id_institute) { // 设置分页查询条件MyClassExample myClassExample = new MyClassExample(); //添加查询条件myClassExample = addCondition(myClassExample,offset,id_institute,getName,specialtyid); if(myClassExample==null)return null; //如果 offset 为 -1 则只查询 id 和 name 列if(offset==-1){return myClassMapper.selectByExampleSelective(myClassExample,MyClass.Column.id,MyClass.Column.className); }else{return myClassMapper.selectByExampleSelective(myClassExample); } } @Overridepublic long getClassesCount(Integer offset, String getName, Long specialtyid, Long id_institute) {// 设置分页查询条件MyClassExample myClassExample = new MyClassExample(); //添加查询条件myClassExample = addCondition(myClassExample,offset,id_institute,getName,specialtyid); if(myClassExample==null)return 0; return myClassMapper.countByExample(myClassExample); } @Overridepublic long delClass(MyClass myClass, Long id_institute) throws MyException {checkSpecialtyId(myClass,id_institute); return myClassMapper.deleteByPrimaryKey(myClass.getId()); } @Overridepublic long putClass(MyClass myClass, Long id_institute) throws MyException {checkSpecialtyId(myClass,id_institute); return myClassMapper.updateByPrimaryKey(myClass); } @Overridepublic long postClass(MyClass myClass, Long id_institute) throws MyException {checkSpecialtyId(myClass,id_institute); long count = getClassesCount(1,myClass.getClassName(),null, id_institute); if(count!=0)throw new MyException("该班级已存在"); return myClassMapper.insert(myClass); } @Overridepublic long delClassBySpecialty(Long specialtyid) {return myClassMapper.deleteByExample(new MyClassExample().createCriteria().andIdSpecialtyEqualTo(specialtyid).example()); } public MyClassExample addCondition(MyClassExample myClassExample,Integer offset , Long id_institute , String keyWord , Long id_specialty){ //代表为超管,则可以查询所有;if(id_institute==-1){return myClassExample.newAndCreateCriteria().when(StringUtil.stringIsNotNull(keyWord), criteria -> criteria.andClassNameEqualTo(keyWord)) //根据关键字查询.when(id_specialty!=null,criteria -> criteria.andIdSpecialtyEqualTo(id_specialty)) //根据指定教研室查询.example().when(offset!=-1 && offset != 0,criteria -> criteria.page(offset-1, 10)); } //查询出来当前学院的所有专业List specialties = specialtyService.getSpecialtys(-1,null,null,id_institute); //提取 id列 列表ListspecialtiesIDs = specialties.stream().map(Specialty::getId).collect(Collectors.toList()); if(specialtiesIDs.size()==0||specialtiesIDs==null)return null; return myClassExample.newAndCreateCriteria().when(StringUtil.stringIsNotNull(keyWord),criteria -> criteria.andClassNameEqualTo(keyWord)) //根据关键字查询.when(id_specialty!=null,criteria -> criteria.andIdSpecialtyEqualTo(id_specialty)) //根据指定教研室查询// 查询的专业只能在当前的学院的教研室下.andIdSpecialtyIn(specialtiesIDs).example().when(offset!=-1 && offset != 0,criteria -> criteria.page(offset-1, 10)); // 查询第offest-1页数据(每页10条) } public void checkSpecialtyId(MyClass myClass ,Long id_institute) throws MyException {//如果为超管则不需要检查有没有权力if(id_institute==-1){return ; } long id_specialty = myClass.getIdSpecialty(); List specialtyes = specialtyService.getSpecialtys(1,null,null,id_institute); //如果被删除的专业是不属于本系教研室则提示没有权限for(Specialty specialty :specialtyes){if(specialty.getId()==id_specialty)return; }throw new MyException("没有权限操作"); } }
管理员业务操作:
@Servicepublic class AdminServiceImpl implements AdminService { @AutowiredAdminMapper adminMapper; @AutowiredSadminMapper sadminMapper; @AutowiredGeneralPurposeMapper mapper; @AutowiredPublicService publicService; //Session 保存时间(秒)private final Integer SAVE_TIME = 60*60*24; //超管 和 子管用一个登录@AutowiredStudentMapper studentMapper; @AutowiredSubjectselectedMapper subjectselectedMapper; @AutowiredSubjectMapper subjectMapper; @AutowiredProjectMapper projectMapper; @AutowiredClassMapper classMapper; @AutowiredSpecialtyMapper specialtyMapper; @AutowiredInstituteMapper instituteMapper; @AutowiredHttpServletRequest request; @AutowiredHttpServletResponse response; @Overridepublic Msg login(String name, String pwd , HttpSession httpSession) { Sadmin sadmin = selectSadminByName(name); if(sadmin!=null){//验证密码是否与数据库中的相同if(sadmin.getPwd().equals(pwd)){User user = new User(); //-1表示为超管user.setId(-1L); user.setRole("sadmin"); user.setUserName(sadmin.getName()); //生成Token 存到 CookieCookie cookie = new Cookie("token",TokenUtil.createToken(user)); //该Cookie无法被js读取cookie.setHttpOnly(true); cookie.setPath("/"); response.addCookie(cookie); return Msg.success(); }return Msg.error("密码错误"); }else {Admin admin = selectByName(name); if(admin == null){return Msg.error("账号不存在"); }else {if(admin != null && admin.getPwd().equals(pwd)){User user = new User(); user.setId(admin.getId()); user.setRole("admin"); user.setUserName(admin.getName()); Cookie cookie = new Cookie("token",TokenUtil.createToken(user)); cookie.setPath("/"); cookie.setHttpOnly(true); response.addCookie(cookie); return Msg.success(); //账号密码正确}return Msg.error("密码错误"); } } } @Overridepublic Admin selectByName(String name) {//创建一个 Admin 实例 ,添加条件 为 Name == nameAdminExample adminExample = new AdminExample(); adminExample.createCriteria().andNameEqualTo(name); //根据实例 来查询List admin = adminMapper.selectByExample(adminExample); if( admin==null || admin.size()==0 ) {return null; }return admin.get(0); } @Overridepublic Sadmin selectSadminByName(String name) {SadminExample sadminExample = new SadminExample(); sadminExample.createCriteria().andNameEqualTo(name); List sadmin = sadminMapper.selectByExample(sadminExample); if( sadmin==null|| sadmin.size()==0 )return null; return sadmin.get(0); } @Overridepublic int updatePwdByUserName(String name, String pwd) {AdminExample adminExample = new AdminExample(); adminExample.createCriteria().andNameEqualTo(name); Admin admin = new Admin(); admin.setPwd(pwd); adminMapper.updateByExampleSelective(admin,adminExample); return 0; } @Overridepublic int updateSadminPwdByUserName(String name, String pwd) {SadminExample sadminExample = new SadminExample(); sadminExample.createCriteria().andNameEqualTo(name); Sadmin sadmin = new Sadmin(); sadmin.setPwd(pwd); return sadminMapper.updateByExampleSelective(sadmin, sadminExample); } // 班级的增加@Overridepublic int add_class(Long specialty_id, String class_name) {Listclasses = select_class(null, null, null, null, class_name); if (classes == null || classes.size() == 0) {Class class1 = new Class(); class1.setClassName(class_name); class1.setIdSpecialty(specialty_id); return classMapper.insert(class1); }return 0; } @Overridepublic int addAdmin(Admin admin) {//添加的时候检测又没用户名重复的publicService.CheckIfTheUsernameIsDuplicated(admin.getName()); return adminMapper.insert(admin); } @Overridepublic int delAdmin(Admin admin) {return adminMapper.deleteByPrimaryKey(admin.getId()); } @Overridepublic int updateAdmin(Admin admin) {//不更新usernameadmin.setName(null); return adminMapper.updateByPrimaryKeySelective(admin); } @Overridepublic List selectAdmins(Long offset) { if(offset!=null && offset==-1){return adminMapper.selectByExampleSelective(new AdminExample(),Admin.Column.id); } return adminMapper.selectByExample(new AdminExample()); } // 学生的增删改查@Overridepublic int add_student(String userName, String stuNum, Long id_class, String name, String gender, String pwd){Student ss = studentMapper.select_studentbyName(userName, stuNum); if (ss == null) {StudentWithBLOBs student = new StudentWithBLOBs(); student.setUsername(userName); student.setStunum(stuNum); student.setIdClass(id_class); student.setName(name); student.setGender(gender); student.setPwd(pwd); return studentMapper.insert(student); }return 0; }public int delete_class(Long class_id) {return classMapper.deleteByPrimaryKey(class_id); } @Overridepublic int update_class(Long class_id, Long specialty_id, String class_name) {Class class1 = new Class(); class1.setId(class_id); class1.setIdSpecialty(specialty_id); class1.setClassName(class_name); return classMapper.updateByPrimaryKeySelective(class1); } @Overridepublic List select_project(Long institute_id, Long section_id, String section_name) {return projectMapper.select_project(institute_id, null, null); } @Overridepublic List select_studentXT_all(Long section_id, String section_name, Long specialty_id, String specialty_name, Long class_id, String class_name) {List static_students = studentMapper.select_studentXT_all(section_id, section_name, specialty_id, specialty_name, class_id, class_name); if (static_students != null && static_students.size() > 0) {for (int i = 0; i < static_students.size(); i++) {List projectselecteds = select_Projectselected(static_students.get(i).getId(), null); if (projectselecteds != null && projectselecteds.size() > 0) {static_students.get(i).setStuselectFlag("" + projectselecteds.get(0).getStuselectFlag()); static_students.get(i).setProjectname(projectselecteds.get(0).getProject_name()); static_students.get(i).setTeachernames(projectselecteds.get(0).getProject_teachers()); } else {static_students.get(i).setProjectname("未选题"); static_students.get(i).setTeachernames(""); }}}return static_students; } @Overridepublic List select_class(Long institute_id, Long section_id, Long specialty_id, Long class_id, String class_name) {return classMapper.select_class(institute_id, section_id, specialty_id, class_id, class_name); } // 专业方向的增删改查@Overridepublic int add_specialty(Long section_id, String specialty_name) {List specialties = select_specialty(null, null, null, specialty_name); if (specialties == null || specialties.size() == 0) {Specialty specialty = new Specialty(); specialty.setIdSection(section_id); specialty.setSpecialtyName(specialty_name); return specialtyMapper.insert(specialty); }return 0; } @Overridepublic int delete_student(Long student_id) {return studentMapper.deleteByPrimaryKey(student_id); } @Overridepublic int update_student(Long student_id, String userName, String stuNum, Long id_class, String name, String gender, String pwd) {Student student = new Student(); student.setId(student_id); student.setUsername(userName); student.setStunum(stuNum); student.setIdClass(id_class); student.setName(name); student.setGender(gender); student.setPwd(pwd); return studentMapper.updateByPrimaryKeySelective((StudentWithBLOBs) student); } @Overridepublic List select_student(Long institute_id, Long specialty_id, Long class_id, Long student_id, String name) {List static_students = studentMapper.select_Student(institute_id, specialty_id, class_id, student_id, name); if (static_students != null) {for (int i = 0; i < static_students.size(); i++) {Static_student static_student = static_students.get(i); List projectselected = select_Projectselected(static_student.getId(), null); if (projectselected != null && projectselected.size() != 0) {String s = ""; if (projectselected.get(0).getStuselectFlag() == 1) s = "选题待审核"; else if (projectselected.get(0).getStuselectFlag() == 2) s = "选题未通过"; else s = "选题通过"; static_student.setStuselectFlag(s); static_student.setProjectname(projectselected.get(0).getProject_name()); static_student.setTeachernames(projectselected.get(0).getProject_teachers()); }}return static_students; }return null; } // 通过学生id 或者 课题id 查 课题的选择 情况public List select_Projectselected(Long student_id, Long project_id) {return subjectselectedMapper.select_Projectselected(student_id, project_id); } public List select_ProjectXQ(Long institute_id, Long section_id, String name) {List projects = subjectMapper.select_ProjectXQ(institute_id, section_id, name); if (projects != null) {for (int i = 0; i < projects.size(); i++) {if (projects.get(i).getSelectFlag() == 0) projects.get(i).setProjectGB("可选"); else if (projects.get(i).getSelectFlag() == 1) projects.get(i).setProjectGB("不可选"); }}return projects; }public int delete_specialty(Long specialty_id) {return specialtyMapper.deleteByPrimaryKey(specialty_id); } @Overridepublic int update_specialty(Long specialty_id, Long section_id, String specialty_name) {Specialty specialty = new Specialty(); specialty.setId(specialty_id); specialty.setIdSection(section_id); specialty.setSpecialtyName(specialty_name); return specialtyMapper.updateByPrimaryKeySelective(specialty); } @Overridepublic List select_specialty(Long institute_id, Long section_id, Long specialty_id, String specialty_name) {return specialtyMapper.select_specialty(institute_id, section_id, specialty_id, specialty_name); // 根据学院id 或者 教研室id 查所有专业方向} @Overridepublic List select_institute(Long institute_id, String institute_name) {InstituteExample instituteExample = new InstituteExample(); InstituteExample.Criteria criteria = instituteExample.createCriteria(); if (institute_id != null && institute_id != 0) criteria.andIdEqualTo(institute_id); if (institute_name != null && institute_name.length() > 0) criteria.andInstituteNameEqualTo(institute_name); return instituteMapper.selectByExample(instituteExample); } }
到此这篇关于Java 实战项目之教材管理系统的实现流程的文章就介绍到这了,更多相关Java 教材管理系统内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
推荐阅读
- JAVA(抽象类与接口的区别&重载与重写&内存泄漏)
- 事件代理
- Java|Java OpenCV图像处理之SIFT角点检测详解
- java中如何实现重建二叉树
- 数组常用方法一
- 【Hadoop踩雷】Mac下安装Hadoop3以及Java版本问题
- Java|Java基础——数组
- 17|17 关山松 第二课作业#公众号项目# D20
- RxJava|RxJava 在Android项目中的使用(一)
- java之static、static|java之static、static final、final的区别与应用