Java怎么实现教材管理系统

技术Java怎么实现教材管理系统这篇文章给大家介绍Java怎么实现教材管理系统,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。一、项目简述功能包括: 管理员可以增删改查教材、教材商、入库教材、用户(用

本文介绍了如何用Java实现教材管理系统。内容非常详细,有兴趣的朋友可以参考一下,希望对你有帮助。

一、项目简述

功能包括:管理员可以添加、删除和检查教科书、教科书供应商、存储的教科书,用户(包括学生和教师)可以检查教科书供应商和教科书。Excel的导入导出操作。教师可以退回教材,以便接收存储的教材。学生只能从相应的老师那里领取教材,可以退回教材,查询已经收到的教材。并为收集的教材付费等等。

00-1010环境配置:JDK 1.8 Tomcat 8.5 MySQL eclispe(由IntelliJ idea、eclispe、Myeclispe和STS支持)

技术:JSP spring MVC my batis html CSS JavaScript jquery Ajax layuimaven等等。

Java怎么实现教材管理系统

Java怎么实现教材管理系统

Java怎么实现教材管理系统

Java怎么实现教材管理系统

Java怎么实现教材管理系统

二、项目运行

@服务

public class topicsservice implemplementstopicsservice {

@自动连线

privateMyClassMapperclassMapper类映射器;

@自动连线

privateStudentMapperstudentMapper;

@自动连线

private subject selected统计师subject selected统计师;

@自动连线

privateSubjectMapPerspectMapper;

@自动连线

privatehttpersvletrequestrequest;

/**

*查看班级选报信息。

*/

@覆盖

public list class info class info(Longid){ 0

myclass class name=class mapper . selectbyid(id);//查找类名

list studentstudents=studentmapper . selectbylistall(id);//根据学生表中的班级id找到用户班级的所有者。

列表主题选择项目选择列表=

 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);
    }
}

班级信息查询业务:

@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("没有权限操作");
    }
 
}

管理员业务操作:

@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://www.230890.com/zhan/114462.html

(0)

相关推荐

  • SQL Server中的Forwarded Record计数器影响IO性能的解决方法

    技术SQL Server中的Forwarded Record计数器影响IO性能的解决方法SQL Server中的Forwarded Record计数器影响IO性能的解决方法,针对这个问题,这篇文章详细介绍了相对应的分析和

    攻略 2021年12月1日
  • 正确写SQL的方法有哪些

    技术正确写SQL的方法有哪些这篇文章主要介绍“正确写SQL的方法有哪些”,在日常操作中,相信很多人在正确写SQL的方法有哪些问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”正确写SQL的方法

    攻略 2021年10月23日
  • 医保跨省转移,如何异地转移社保和医保

    技术医保跨省转移,如何异地转移社保和医保医保跨省转移手续:首先要在原参保地办理医疗保险关系注销手续,然后由本人向市社保中心提出医疗保险关系转移申请医保跨省转移;凭转出地经办机构出具的《参保(合)凭证》以及原参保地医疗保险

    生活 2021年10月31日
  • 如何理解Java通过加密技术保护源代码的方法

    技术如何理解Java通过加密技术保护源代码的方法这篇文章主要讲解了“如何理解Java通过加密技术保护源代码的方法”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“如何理解Ja

    攻略 2021年10月25日
  • Hibernate如何连接配置

    技术Hibernate如何连接配置小编给大家分享一下Hibernate如何连接配置,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!在Hibern

    攻略 2021年12月8日
  • Linux操作系统源

    技术Linux操作系统源 Linux操作系统源记录常见linux操作系统的源以及换源方式。Linux发行版分类
    Linux的发行版本根据维护主体的不同可以大体分为两类,一类是商业公司维护的发行版本,一类

    礼包 2021年12月21日