Java 实战项目之教材管理系统的实现流程
读万卷书不如行万里路,只学书上的理论是远远不够的,只有在实战中才能获得能力的提升,本篇文章手把手带你用java+SSM+jsp+mysql+maven实现教材管理系统,大家可以在过程中查缺补漏,提升水平
一、项目简述
功能包括: 管理员可以增删改查教材、教材商、入库教材、用户(用 户包括学生和教师)可以对教材商、教材进行。Excel的导入 导出操作。教师以领取入库的教材,可以退还教材。学生只能在对应的教师那里领取教材,并且可以退还教材、 查询自己已经领取的教材。并且对已领教材付款等等。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。
查看班级选报信息:
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 | @Service public class TopicsServiceImpl implements TopicsService { @Autowired private MyClassMapper classMapper; @Autowired private StudentMapper studentMapper; @Autowired private SubjectselectedMapper subjectselectedMapper; @Autowired private SubjectMapper subjectMapper; @Autowired private HttpServletRequest request; /** * 查看班级选报信息 */ @Override public List<classinfo> classinfo(Long id) { MyClass className = classMapper.selectById(id); //查到班级名字 List<Student> students = studentMapper.selectByListAll(id); //根据student表里班级id查到用户所在班级的所有人 List<Subjectselected> projectselectedlist = new ArrayList<>(); List<Subject> projectlist = new ArrayList<>(); Subjectselected projectselected = null ; Subject project = null ; for ( int i = 0 ; i < students.size(); i++) { List<Subjectselected> 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<classinfo> 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 */ @Override public List<topicsinfo> topics(Long id) { String specialty = classMapper.selectByspecialty(id); List<Subject> projectlist = subjectMapper.selectByAll( "%" + specialty + "%" ); List<topicsinfo> 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; } /** * 课题具体信息 */ @Override public List<topicsto> topicsinfo(Long project_id) { List<Subjectselected> listed = subjectselectedMapper.selectByprojectid(project_id); //中间表 request.getSession().setAttribute( "listsize" ,listed.size()); List<topicsto> 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<Subjectselected> tprojectselecteds = subjectselectedMapper.selectBystudentid(student.getId()); if (tprojectselecteds != null && tprojectselecteds.size() > 0 ) project = tprojectselecteds.get( 0 ); if (project == null ) { return 0L; } else return project.getStuselectFlag(); } /** * 添加选题 */ @Override public void insertproject(String project, Long studentid) { Long projectid = subjectMapper.selectByprojectid(project); int flagid = subjectselectedMapper.insertenroll(projectid, studentid); } /** * 删除选题 */ @Override public 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; } /** * 获取该题是否可选 */ @Override public Long flag(Long project_id) { return subjectMapper.selectByselectFlag(project_id); } } |
班级信息查询业务:
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 | @Service public class ClassServiceImpl implements ClassService { @Autowired MyClassMapper myClassMapper; @Autowired SpecialtyService specialtyService; @Autowired StudentService studentService; @Override public 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); } } @Override public 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); } @Override public long delClass(MyClass myClass, Long id_institute) throws MyException { checkSpecialtyId(myClass,id_institute); return myClassMapper.deleteByPrimaryKey(myClass.getId()); } @Override public long putClass(MyClass myClass, Long id_institute) throws MyException { checkSpecialtyId(myClass,id_institute); return myClassMapper.updateByPrimaryKey(myClass); } @Override public 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); } @Override public 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<Specialty> specialties = specialtyService.getSpecialtys(- 1 , null , null ,id_institute); //提取 id列 列表 List<Long> specialtiesIDs = 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<Specialty> specialtyes = specialtyService.getSpecialtys( 1 , null , null ,id_institute); //如果被删除的专业是不属于本系教研室则提示没有权限 for (Specialty specialty :specialtyes) { if (specialty.getId()==id_specialty) return ; } throw new MyException( "没有权限操作" ); } } |
管理员业务操作:
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 | @Service public class AdminServiceImpl implements AdminService { @Autowired AdminMapper adminMapper; @Autowired SadminMapper sadminMapper; @Autowired GeneralPurposeMapper mapper; @Autowired PublicService publicService; //Session 保存时间(秒) private final Integer SAVE_TIME = 60 * 60 * 24 ; //超管 和 子管用一个登录 @Autowired StudentMapper studentMapper; @Autowired SubjectselectedMapper subjectselectedMapper; @Autowired SubjectMapper subjectMapper; @Autowired ProjectMapper projectMapper; @Autowired ClassMapper classMapper; @Autowired SpecialtyMapper specialtyMapper; @Autowired InstituteMapper instituteMapper; @Autowired HttpServletRequest request; @Autowired HttpServletResponse response; @Override public 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 存到 Cookie Cookie 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( "密码错误" ); } } } @Override public Admin selectByName(String name) { //创建一个 Admin 实例 ,添加条件 为 Name == name AdminExample adminExample = new AdminExample(); adminExample.createCriteria().andNameEqualTo(name); //根据实例 来查询 List<Admin> admin = adminMapper.selectByExample(adminExample); if ( admin== null || admin.size()== 0 ) { return null ; } return admin.get( 0 ); } @Override public Sadmin selectSadminByName(String name) { SadminExample sadminExample = new SadminExample(); sadminExample.createCriteria().andNameEqualTo(name); List<Sadmin> sadmin = sadminMapper.selectByExample(sadminExample); if ( sadmin== null || sadmin.size()== 0 ) return null ; return sadmin.get( 0 ); } @Override public 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 ; } @Override public 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); } // 班级的增加 @Override public int add_class(Long specialty_id, String class_name) { List<Class> classes = 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 ; } @Override public int addAdmin(Admin admin) { //添加的时候检测又没用户名重复的 publicService.CheckIfTheUsernameIsDuplicated(admin.getName()); return adminMapper.insert(admin); } @Override public int delAdmin(Admin admin) { return adminMapper.deleteByPrimaryKey(admin.getId()); } @Override public int updateAdmin(Admin admin) { //不更新username admin.setName( null ); return adminMapper.updateByPrimaryKeySelective(admin); } @Override public List selectAdmins(Long offset) { if (offset!= null && offset==- 1 ){ return adminMapper.selectByExampleSelective( new AdminExample(), Admin.Column.id ); } return adminMapper.selectByExample( new AdminExample() ); } // 学生的增删改查 @Override public 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); } @Override public 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); } @Override public List<Project> select_project(Long institute_id, Long section_id, String section_name) { return projectMapper.select_project(institute_id, null , null ); } @Override public List<Static_student> select_studentXT_all(Long section_id, String section_name, Long specialty_id, String specialty_name, Long class_id, String class_name) { List<Static_student> 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<Subjectselected> 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; } @Override public List<Class> 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); } // 专业方向的增删改查 @Override public int add_specialty(Long section_id, String specialty_name) { List<Specialty> 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 ; } @Override public int delete_student(Long student_id) { return studentMapper.deleteByPrimaryKey(student_id); } @Override public 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); } @Override public List<Static_student> select_student(Long institute_id, Long specialty_id, Long class_id, Long student_id, String name) { List<Static_student> 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<Subjectselected> 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<Subjectselected> select_Projectselected(Long student_id, Long project_id) { return subjectselectedMapper.select_Projectselected(student_id, project_id); } public List<Subject> select_ProjectXQ(Long institute_id, Long section_id, String name) { List<Subject> 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); } @Override public 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); } @Override public List<Specialty> 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 查所有专业方向 } @Override public List<Institute> 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 实战项目之教材管理系统的实现流程的文章就介绍到这了
原文链接:https://blog.csdn.net/m0_59687645/article/details/121435917