Java项目:学生管理系统Java基础Gui(java+Gui)

源码获取:博客首页 "资源" 里下载!

功能介绍:

学生信息管理,姓名,编号,性别,成绩,学号住址

登录控制层:

@Controller
public class LoginController {

    private static final Logger LOGGER = LoggerFactory.getLogger(LoginController.class);


    @Autowired
    AdminService adminService;

    @GetMapping("/cs")
    public String cs() {
        return "cs";
    }


    @GetMapping("/login")
    public String login() {
        return "login";
    }

    @PostMapping("/login")
    @ResponseBody
    public Msg login(String name, String pwd, HttpSession httpSession) {
        name = name.trim();
//        LOGGER.info("{}--{}",name,pwd);
        return adminService.login(name, pwd, httpSession);

    }
}

 角色业务处理:

@Authority(roles = {Role.STUDENT})
@Controller
@RequestMapping("/student")
public class StudentController {

    private static final Logger LOGGER = LoggerFactory.getLogger(StudentController.class);

    @Autowired
    private StudentService studentService;

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private LoginServiceImpl loginService;

    @Autowired
    IndexServiceImpl indexService;

    @Autowired
    AdminService adminService;



    @Autowired
    TopicsService topicsService;

    //Session过期时间
    private final Integer SAVE_TIME = 60*60*24;


    @GetMapping("/login")
    public String login(){
        return "student/login";
    }


    @PostMapping(value = "/login")
    @ResponseBody
    public String login(String name, String pwd, Model model, HttpServletResponse response) {
        name = name.trim();
        List<Student> student = studentService.selectByName(name);
        if (student.size() >= 1) {
            if (student.get(0).getPwd().equals(pwd)) {
                request.getSession().setAttribute("student",student.get(0));
                request.getSession().setMaxInactiveInterval(SAVE_TIME);
                User user = new User();
                //-1表示为超管
                user.setId(1L);
                user.setRole("student");
                user.setUserName(name);
                //生成Token 存到 Cookie
                Cookie cookie = new Cookie("token", TokenUtil.createToken(
                        user
                ));
                //该Cookie无法被js读取
                cookie.setHttpOnly(true);
                cookie.setPath("/");
                response.addCookie(cookie);
                model.addAttribute("student", student.get(0));
                return "200";
            }else {
                return "0";

            }
        } else {
            return "300";
        }
    }


    @RequestMapping("/index")
    public String index(Model model, HttpSession httpSession) {
        Student student = (Student) request.getSession().getAttribute("student");
        Subject project = indexService.indexinfo(student.getId());
        String str = null;
        Long flag = null;
        if (project == null) {
            model.addAttribute("projectName", "未选课题");
            model.addAttribute("flag", "未选题");
            model.addAttribute("teacher", "无");
            httpSession.removeAttribute("");
        } else {
            httpSession.setAttribute("XZproject", project.getProjectname());
            model.addAttribute("XZproject", project.getProjectname());
            model.addAttribute("projectName", project.getProjectname());
            flag = indexService.projectselectedstuflag(student.getId());
            if (flag == 0L) {
                str = "未选题";
            } else if (flag == 1L) {
                str = "选题待审核";
            } else if (flag == 2L) {
                str = "选题未通过";
            } else if (flag == 3L) {
                str = "选题通过";
            }
            model.addAttribute("flag", str);
            model.addAttribute("teacher", project.getTeachernames());
            request.getSession().setAttribute("filePath",project.getFilepath());
        }
        //用来判断当前页是否为首页
        model.addAttribute("path","1");
        //判断是否修改了个人信息
//        request.getSession().setAttribute("modifyFlag",0);

        return "student/index";
    }



    /**
     * 查看个人信息
     */
    @RequestMapping("/studentinfo")
    public String studentinfo(Model model) {
        Student student = (Student) request.getSession().getAttribute("student");
        MyClass idclass = indexService.studentinfo(student.getIdClass());
        model.addAttribute("tclass", idclass);
        return "student/studentinfo";
    }

    /**
     * 将查看的个人信息放到信息修改页面
     */
    @RequestMapping("/modifyinfo")
    public String modifyinfo(Model model) {
        Student student = (Student) request.getSession().getAttribute("student");
        MyClass idclass = indexService.studentinfo(student.getIdClass());
        model.addAttribute("tclass", idclass);

        return "student/modifyinfo";
    }


    /**
     * 修改个人信息
     * 根据班级(className)修改
     *
     */
    /*@RequestMapping(value = "/modifyinfodao", method = RequestMethod.PUT)
    @ResponseBody
    public String modifyinfodao(Student student, String className, Model model) {
        Student Tstudent = (Student) request.getSession().getAttribute("student");
        MyClass Tclass = indexService.selectByclassName(className);
        int count = -1;
        student.setIdClass(Tclass.getId());
        System.out.println("******"+Tstudent.toString());
        System.out.println("******"+student.toString());

        if (student.getStunum().equals(Tstudent.getStunum())) {
            student.setStunum(null);
        }
        if (student.getIdClass().equals(Tstudent.getIdClass())) {
            student.setIdClass(null);
        }
        if (student.getName().equals(Tstudent.getName())) {
            student.setName(null);
        }
        if (student.getGender().equals(Tstudent.getGender())) {
            student.setGender(null);
        }
        if (student.getGender() == null && student.getName() == null && student.getIdClass() == null && student.getStunum() == null) {

        } else {
            student.setId(Tstudent.getId());
            count = indexService.updateBymodifyinfo(student);
            student = indexService.selectByid(Tstudent.getId());
            model.addAttribute("student", student);
        }
        if (count > 0) {
            request.getSession().setAttribute("student",student);
            request.getSession().setAttribute("modifyFlag",1);
            return "200";
        } else {
            request.getSession().setAttribute("modifyFlag",0);
            return "201";
        }
    }*/



    /**
     *   跳转页面(修改密码)
     */
    @RequestMapping("/changepsw")
    public String changepsw() {
        return "student/changepsw";
    }


    /**
     * 200修改成功
     * 201对不起密码错误
     * 202对不起输入框为空
     * 203新密码不一致
     * 204修改失败
     */
    @RequestMapping(value = "/changepassword", method = RequestMethod.PUT)
    @ResponseBody
    public String changepswdao(String oldpassword, String newpassword, String newpassword1) {
        if(!verifypassword(newpassword)){
            return "206";
        }
        if(!verifypassword(newpassword1)){
            return "206";
        }
        Student student = (Student) request.getSession().getAttribute("student");
        Student studentdao = loginService.selectByName(student.getUsername());
        int result;
        if (newpassword.equals(newpassword1) && !newpassword.equals("") && !newpassword1.equals("")) {
            if (studentdao.getPwd().equals(oldpassword)) {

                if(oldpassword.equals(newpassword)){
                    return "205";
                }else{
                    result = indexService.updatepassword(newpassword, student.getId());
                    if (result > 0) {
                        return "200";
                    }else{
                        return "204";
                    }
                }
            } else {
                return "201";
            }
        } else if (newpassword.equals("") && newpassword1.equals("")) {
            return "202";
        }
        return "203";
    }


    //密码验证
    public boolean verifypassword(String password){
        if(password.length() < 6 || password.length() > 16){
            return false;
        }
        for(int i = 0;i < password.length();i++){
            if(!(password.charAt(i)>='A' && password.charAt(i)<='Z')){
                if(!(password.charAt(i)>='a' && password.charAt(i)<='z')){
                    if(!(password.charAt(i)>='0' && password.charAt(i)<='9')){
                        return false;
                    }
                }
            }
        }
        return true;
    }

    //退出
    //清除Session数据
    @RequestMapping("/exit")
    public String exit(HttpServletResponse response,HttpSession httpSession) {
//        httpSession.setAttribute("XZproject", null);
//       清除Session
        Enumeration em = request.getSession().getAttributeNames();
        while(em.hasMoreElements()){
            request.getSession().removeAttribute(em.nextElement().toString());
        }
        //将Cookie 中的token 置空
        Cookie cookie = new Cookie("token", null);
        cookie.setPath("/");
        response.addCookie(cookie);

        return "student/login";
    }




    /**
     * 查看班级选报信息
     */
    @RequestMapping("/classinfo")
    public String classinfo(Model model,HttpSession httpSession) {

        Student student = (Student) request.getSession().getAttribute("student");
        removeSession();
        List<Static_student> list =  adminService.select_student(null, null, student.getIdClass(), null, null);

        System.out.println(list);
        model.addAttribute("list", list);
        return "student/classinfo";
    }


    /**
     * 查看课题
     */
    @RequestMapping("/topics")
    public String Topics(Model model,HttpSession httpSession) {
        Student student = (Student) request.getSession().getAttribute("student");
        removeSession();
        List<topicsinfo> topicsinfolist = topicsService.topics(student.getIdClass());
        System.out.println(topicsinfolist);
        model.addAttribute("topicsinfolist", topicsinfolist);
        return "student/topicsinfo";
    }


    /**
     * 课题具体信息
     */
    @RequestMapping("/topicsto")
    public String Topicsto(Long project_id,int selectFlag,String projectName, Model model, HttpSession httpSession) {
        List<topicsto> topicstos = topicsService.topicsinfo(project_id);
        Student student = (Student) request.getSession().getAttribute("student");
        Long flag = topicsService.state(student);
        Long flagto = topicsService.flag(project_id);
        if (flagto != 0) {
            flag = 3L;
        }
        model.addAttribute("selectFlag",selectFlag);
        model.addAttribute("flag", flag);
        model.addAttribute("topicstos", topicstos);
        model.addAttribute("projectName", projectName);
        model.addAttribute("project_id", project_id);
        model.addAttribute("XZproject", httpSession.getAttribute("XZproject"));
        return "student/topicsinfoto";
    }


    /**
     * 选报课题
     */
    @Autowired
    SubjectselectedMapper subjectselectedMapper;
    @RequestMapping("/enroll")
    @ResponseBody
    public String enroll(Long project_id, HttpSession httpSession) {
        String projectName = topicsService.selectprojectname(project_id);
        Student student = (Student) request.getSession().getAttribute("student");
        List<Subjectselected> subjectselected = subjectselectedMapper.selectBystudentid(student.getId());


        if(subjectselected.size() == 0){
            studentService.updateselectnumAdd(projectName);
            topicsService.insertproject(projectName, student.getId());
            httpSession.setAttribute("XZproject", projectName);
            return "200";
        }else {
            return "201";
        }

    }

    /**
     * 取消选报
     */
    @RequestMapping("/cancel")
    @ResponseBody()
    public String cancel(Long project_id, Model model, HttpSession httpSession) {
        System.out.println(1);
        String projectName = topicsService.selectprojectname(project_id);
        Student student = (Student) request.getSession().getAttribute("student");
        List<Subjectselected> subjectselected = subjectselectedMapper.selectBystudentid(student.getId());

        if (subjectselected != null && subjectselected.size() != 0 && subjectselected.get(0).getStuselectFlag() != 3
                && project_id.equals(subjectselected.get(0).getIdProject())) {
            topicsService.deleteprojectselectedid(student.getId());
            httpSession.removeAttribute("XZproject");
            model.addAttribute("XZproject", null);
            httpSession.setAttribute("XZproject", null);
            studentService.updateselectnumReduce(projectName);
            return "200";

        } else {
            return "203";
        }
    }

    /**
     * 清除session中存的项目名
     */
    public void removeSession(){
        Student student = (Student) request.getSession().getAttribute("student");
        Subject project = indexService.indexinfo(student.getId());
        if(project==null){
            request.getSession().removeAttribute("XZproject");
        }
    }




}

源码获取:博客首页 "资源" 里下载!

  • 5
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 8
    评论
图书资料管理信息系统,带源代码、数据库sql文件、课设报告,具备如下基本功能: 1、 系统管理功能有:角色管理、用户管理、修改密码。主要实现系统的安全管理,不同的操作者有不同的权限,可以执行不同的操作。普通读者的权限只能是查询图书及自己的借阅情况;而图书馆管理员可以对图书信息进行管理,如对新书入库,也可以管理用户,如添加新用户和删除不用的账号等。 2、 进书管理功能有:登记基本的图书信息。这部分的功能用于登记新书的书名、作者、出版社、价格、进书的册数、进书日期、ISBN等。 3、 图书入库管理功能有:对新书分类编目,及时更新图书库中的图书信息。这部分的功能用于对所购进的新书,按其种类学科进行编目,给与唯一的书号;及时更新书库中的图书信息,包括书名、书号、作者、出版社、价格、库存位置和库存册数这些信息,方便读者查询借阅。 4、 查询功能功能有:查询图书的信息,查询读者的借阅情况。这部分的功能主要提供多种方式的查询服务。读者可以根据书名、作者或关键字模糊查询图书信息;读者也可以根据自己的借书证号查询自己的借阅情况,如已借了几本书,借书日期,还书日期,有没有续借等。 5、 借书/还书管理功能有:借书管理、还书管理。这部分的功能是当读者借书时,系统根据借书证号识别读者身份,核对读者的借书信息,做出判断如可不可以借、还可借几本,成功借阅后记录在借书信息并修改书库图书信息。当读者还书时,系统根据借书证号识别读者身份,核对读者的借书信息,做出判断如有没有超期,要不要罚款,需要罚多少等,最后还书成功,修改书库图书信息。
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

beyondwild

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值