IDEA+Java+SSM+Mysql+Bootstrap实现Web学生信息管理系统(下)

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
云数据库 RDS MySQL Serverless,价值2615元额度,1个月
简介: IDEA+Java+SSM+Mysql+Bootstrap实现Web学生信息管理系统

StudentController

package com.offcn.controller;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.offcn.pojo.Classes;
import com.offcn.pojo.CourseExt;
import com.offcn.pojo.Sc;
import com.offcn.pojo.Student;
import com.offcn.service.ClassesService;
import com.offcn.service.StudentService;
@Controller
@RequestMapping("/stu")
public class StudentController {
  @Resource
  StudentService studentService;
  @Resource
  ClassesService classesService;
  @RequestMapping("/list")
  public String getlist(@RequestParam(required=false,defaultValue="1") int pageNO,Model model) {
    int size=3;
      List<Student> slist=studentService.getStudentPager(pageNO, size);
      model.addAttribute("pageNO", pageNO);
      model.addAttribute("size", size);
      model.addAttribute("count", studentService.getCount());
      model.addAttribute("slist", slist);
    return "student/list";
  }
  @RequestMapping("/findByName")
  public String findByName(String name,Model model) {
    int size=10;
      List<Student> slist=studentService.findByName(name);
      model.addAttribute("pageNO", 1);
      model.addAttribute("size", size);
      model.addAttribute("count", studentService.getCount());
      model.addAttribute("slist", slist);
      model.addAttribute("name", name);
    return "student/list";
  }
  @RequestMapping("/findByName2")
  public String findByName2(String id,Model model) {
    int size=10;
    List<Student> slist = new ArrayList<>();
    if(id!=""&&id!=null) {
        slist=studentService.findByName2(Integer.parseInt(id));
    }
      model.addAttribute("pageNO", 1);
      model.addAttribute("size", size);
      model.addAttribute("count", studentService.getCount());
      model.addAttribute("slist", slist);
      model.addAttribute("id", id);
    return "student/list";
  }
  @RequestMapping("/findByName3")
  public String findByName3(String address,Model model) {
    int size=10;
      List<Student> slist=studentService.findByName3(address);
      model.addAttribute("pageNO", 1);
      model.addAttribute("size", size);
      model.addAttribute("count", studentService.getCount());
      model.addAttribute("slist", slist);
      model.addAttribute("address", address);
    return "student/list";
  }
  //重定向一定要写绝对路径eg:redirect:/stu/list
  @RequestMapping("/delete/{id}")
  public String  delete(@PathVariable int id,Model model) {
    studentService.deleteByPrimaryKey(id);
    return "redirect:/stu/list";
  }
  @RequestMapping("/deletes")
  public String  deletes(@RequestParam("id") int[] ids,Model model,RedirectAttributes redirectAttributes) {
    int rows=0;
    rows=studentService.multiDelete(ids);
    if(rows>0){
      redirectAttributes.addFlashAttribute("message", "成功删除!");
    }else{
      redirectAttributes.addFlashAttribute("message", "删除shibai!");
    }
    return "redirect:/stu/list";
  }
  //
  @RequestMapping("/add")
  public String add(Model model) {
    List<Classes> clist=classesService.getAllClasses();
    model.addAttribute("clist", clist);
    model.addAttribute("entity", new Student());
    return "student/add";
  }
  //mm           `
  @RequestMapping("/addSave")
  public String addSave(Model model,@ModelAttribute("entity") @Valid Student entity,BindingResult bindingResult,RedirectAttributes redirectAttributes) {
    if(bindingResult.hasErrors()){
       model.addAttribute("entity", entity);
       List<Classes> clist=classesService.getAllClasses();
       model.addAttribute("clist", clist);
       //redirectAttributes.addFlashAttribute("entity", arg1)
             return "student/add";
       //return "redirect:/add";
    }else{
      List<Classes> clist=classesService.getAllClasses();
      model.addAttribute("clist", clist);
      model.addAttribute("entity", new Student());
      studentService.insert(entity);
      return "redirect:/stu/list";
    }
  }
  //edit/${entity.id}
  @RequestMapping("/edit/{id}")
  public String add(Model model,@PathVariable int id) {
    List<Classes> clist=classesService.getAllClasses();
    model.addAttribute("clist", clist);
    model.addAttribute("entity", studentService.selectByPrimaryKey(id));
    return "student/edit";
  }
  //
  @RequestMapping("/editSave")
  public String editSave(Model model,Student student) {
    studentService.updateByPrimaryKey(student);
    return "redirect:/stu/list";
  }
  @RequestMapping("/getXuXiu")
  public String getXuXiu(Model model,HttpServletRequest req){
    HttpSession session=req.getSession();
    Student student=(Student) session.getAttribute("user");
    List<CourseExt> clist= studentService.getXuxiu(student.getClassid());
    model.addAttribute("colist", clist);
    return "student/colist";
  }
  @RequestMapping(value="/semycou",produces="text/html;charset=utf8")
  @ResponseBody
  public String semycou(@RequestParam("cou") String[] ct,HttpServletRequest req){
    HttpSession session=req.getSession();
    Student student=(Student) session.getAttribute("user");
    List<Sc> sclist=new ArrayList<Sc>();
    for(int i=0;i<ct.length;i++){
      Sc sc=new Sc();
      String cteveryone=ct[i];
      String[] ctarray=cteveryone.split("_");
      sc.setCid(Integer.parseInt(ctarray[0]));
      sc.setTid(Integer.parseInt(ctarray[1]));
      sc.setSid(student.getId());
      sclist.add(sc);
    }
    String msg="";
    try{
      studentService.inserBatch(sclist);
      msg="选课成功!";
    }catch(Exception e){
      msg="选课可能有重复,请审核后重试!";
    }
    return msg;
  }
  @RequestMapping("/getStuCourse")
  public String getStuCourse(Model model,HttpServletRequest req){
    HttpSession session=req.getSession();
    Student student=(Student) session.getAttribute("user");
    List<CourseExt> ctlist=studentService.getMycourses(student.getClassid(), student.getId());
    model.addAttribute("ctlist", ctlist);
    return "student/cslist";
  }
}

TeacherController

package com.offcn.controller;
import java.io.File;
import java.util.List;
import java.util.UUID;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.offcn.pojo.Grade;
import com.offcn.pojo.StudentView;
import com.offcn.pojo.Teacher;
import com.offcn.service.TeacherService;
/**
 * <p>Company: offcn</p>
 * @author zgf
 * @date 2017年5月22日
 * @version 1.0
 */
@Controller
@RequestMapping("/tea")
public class TeacherController {
  @Resource
    TeacherService teacherService;
   /*
     * 学生列表与分页Action
     */
    @RequestMapping("/list")
    public String list(Model model,@RequestParam(required=false,defaultValue="1") int pageNO){
        int size=3;
        model.addAttribute("size",size);
        model.addAttribute("pageNO",pageNO);
        model.addAttribute("count",teacherService.getTeacherCount());
        model.addAttribute("tealist", teacherService.getTeacherPager(pageNO, size));
        return "teacher/list";
     }
    /*
     * 删除单个学生对象Action
     */
    @RequestMapping("/delete/{id}")
    public String delete(Model model,@PathVariable int id,@RequestParam(required=false,defaultValue="1") int pageNO,RedirectAttributes redirectAttributes){
        if(teacherService.delete(id)>0)
        {
            redirectAttributes.addFlashAttribute("message", "删除成功!");
        }else{
            redirectAttributes.addFlashAttribute("message", "删除失败!");
        }
        return "redirect:/tea/list?pageNO="+pageNO;
    }
    /*
     * 删除多个学生对象Action
     */
    @RequestMapping("/deletes")
    public String deletes(Model model,@RequestParam int[] id,@RequestParam(required=false,defaultValue="1") int pageNO,RedirectAttributes redirectAttributes){
        //执行删除
      System.out.println("批量删除"+id.toString());
        int rows=teacherService.deletes(id);
        if(rows>0)
        {
            redirectAttributes.addFlashAttribute("message", "删除"+rows+"行记录成功!");
        }else{
            redirectAttributes.addFlashAttribute("message", "删除失败!");
        }
        return "redirect:/tea/list?pageNO="+pageNO;
    }
    /*
     * 添加
     */
    @RequestMapping("/add")
    public String add(Model model){
        model.addAttribute("entity", new Teacher());
        return "teacher/add";
    }
    /*
     * 添加保存
     */
    @RequestMapping("/addSave")
    public String addSave(Model model,@ModelAttribute("entity") @Valid Teacher entity,BindingResult bindingResult){
        //如果模型中存在错误
        if(bindingResult.hasErrors()){
           model.addAttribute("entity", entity);
             return "teacher/add";
        }else{
          entity.setPassword("aaaaaa");
          teacherService.insert(entity);
             return "redirect:/tea/list";    
        }
    }
    /*
     * 编辑
     */
    @RequestMapping("/edit/{id}")
    public String edit(Model model,@PathVariable int id){
        model.addAttribute("entity", teacherService.getTeacherId(id));
        return "teacher/edit";
    }
    /*
     * 保存
     */
    @RequestMapping("/editSave")
    public String editSave(Model model,@ModelAttribute("entity") @Valid Teacher entity,BindingResult bindingResult){
        //如果模型中存在错误
        if(bindingResult.hasErrors()){
           model.addAttribute("entity", entity);
             return "/teacher/edit";
        }else{
          //entity.setPassword("aaaaaa");
          teacherService.update(entity);
            return "redirect:list";    
        }
    }
   //
    @RequestMapping("getMyStu")
    public String getMyStu(Model model,HttpServletRequest req){
      HttpSession session=req.getSession();
      Teacher teacher=(Teacher) session.getAttribute("user");
        List<StudentView> slist=teacherService.getMystus(teacher.getId());
        model.addAttribute("stulist", slist);
      return "teacher/couOftea/stulist";
    }
    //
    @RequestMapping("setGrades/{sid}/{sname}/{cid}")
    public String setGrades(Model model,@PathVariable int sid,@PathVariable String sname,@PathVariable int cid){
      Grade grade=new Grade();
      grade.setSid(sid);
      grade.setCid(cid);
      model.addAttribute("entity", grade);
      model.addAttribute("sname", sname);
      return "teacher/couOftea/setgrade";
    }
    @RequestMapping("/saveGrade")
    public String setGrades(Model model,Grade entity,HttpServletRequest req,RedirectAttributes redirectAttributes){
      HttpSession session=req.getSession();
      Teacher teacher=(Teacher) session.getAttribute("user");
      entity.setZgrade(entity.getPgrade()+entity.getKgrade());
      entity.setTid(teacher.getId());
      int rows=teacherService.insertGrade(entity);
      if(rows>0){
        redirectAttributes.addFlashAttribute("msg", "录入成功!");
      }else{
        redirectAttributes.addFlashAttribute("msg", "录入失败!");
      }
      return "redirect:getMyStu";
    }
}

UserController

package com.offcn.controller;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.offcn.pojo.Student;
import com.offcn.pojo.Teacher;
import com.offcn.pojo.User;
import com.offcn.service.StudentService;
import com.offcn.service.TeacherService;
import com.offcn.service.UserService;
@Controller
@RequestMapping("/admin")
public class UserController {
  @Resource
  UserService userService;
  @Resource
  StudentService studentService;
  @RequestMapping("/login")
  public String login(User user,Model model,HttpServletRequest req) {
    HttpSession session=req.getSession();
    int usertype=-1;
    if(user!=null){
      usertype=user.getUsertype();
      if(usertype==1){
        //管理员
       User loginuser= userService.userlogin(user);
       if(loginuser!=null){
         session.setAttribute("user", loginuser);
         return "homepage/index";
       }else{
         model.addAttribute("msg", "请输入正确的用户名和密码");
         return "/index";
       }
      }else if(usertype==2){
        //学生
        Student student=new Student();
        student.setLoginname(user.getName());
        student.setPassword(user.getPassword());
        Student loginstu=studentService.stulogin(student);
        if(loginstu!=null){
          session.setAttribute("user", loginstu);
          return "homepage/index";
        }else{
          model.addAttribute("msg", "请输入正确的用户名和密码");
          return "/index";
        }
      }
    }
    return "homepage/index";
  }
  //
//    @RequestMapping("isPassword") 
  @ResponseBody
    @RequestMapping("/isPassword")
  public Object isPassword(@RequestParam(value ="oldpwd") String oldpwd ,@RequestParam(value ="id")Integer id) {
     Map<String,Object> map=new HashMap<String, Object>();
          Student student =  studentService.selectByPrimaryKey(id);
          if(null != student && !student.getPassword().equals(oldpwd)){
              map.put("code", "error");
          }else{
              map.put("code", "success");
          }
    return map;
    }
}


四、其他


1.更多系统


1.更多JavaWeb系统请关注专栏。


https://blog.csdn.net/helongqiang/category_10020130.html

https://blog.csdn.net/helongqiang/category_10020130.html


2.更多JavaSwing系统请关注专栏。


https://blog.csdn.net/helongqiang/category_6229101.html

https://blog.csdn.net/helongqiang/category_6229101.html


2.源码下载

Java+SSM+Boostrap学生信息管理系统


3.运行项目

请点击以下链接,部署你的项目。


IDEA如何导入JavaWeb项目超详细视频教程


4.备注

如有侵权请联系我删除。


5.支持博主

如果您觉得此文对您有帮助,请点赞加关注加收藏。祝您生活愉快!


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
6天前
|
关系型数据库 MySQL Java
Java时间转换为MySQL中的INT类型时间戳
Java时间转换为MySQL中的INT类型时间戳
|
7天前
|
开发框架 前端开发 JavaScript
学会Web UI框架--Bootstrap,快速搭建出漂亮的前端界面
学会Web UI框架--Bootstrap,快速搭建出漂亮的前端界面
|
7天前
|
网络协议 安全 关系型数据库
IntelliJ IDEA如何使用固定地址公网远程访问本地Mysql数据库
IntelliJ IDEA如何使用固定地址公网远程访问本地Mysql数据库
18 1
|
7天前
|
Java 关系型数据库 MySQL
【JDBC编程】基于MySql的Java应用程序中访问数据库与交互数据的技术
【JDBC编程】基于MySql的Java应用程序中访问数据库与交互数据的技术
|
7天前
|
Java 关系型数据库 MySQL
Java基础教程(20)-Java连接mysql数据库CURD
【4月更文挑战第19天】MySQL是流行的关系型数据库管理系统,支持SQL语法。在IDEA中加载jar包到项目类路径:右击项目,选择“Open Module Settings”,添加库文件。使用JDBC连接MySQL,首先下载JDBC驱动,然后通过`Class.forName()`加载驱动,`DriverManager.getConnection()`建立连接。执行CRUD操作,例如创建表、插入数据和查询,使用`Statement`或`PreparedStatement`,并确保正确关闭数据库资源。
|
18天前
|
Java 关系型数据库 MySQL
一套java+ spring boot与vue+ mysql技术开发的UWB高精度工厂人员定位全套系统源码有应用案例
UWB (ULTRA WIDE BAND, UWB) 技术是一种无线载波通讯技术,它不采用正弦载波,而是利用纳秒级的非正弦波窄脉冲传输数据,因此其所占的频谱范围很宽。一套UWB精确定位系统,最高定位精度可达10cm,具有高精度,高动态,高容量,低功耗的应用。
一套java+ spring boot与vue+ mysql技术开发的UWB高精度工厂人员定位全套系统源码有应用案例
|
20天前
|
缓存 小程序
Java+saas模式 智慧校园系统源码MySQL5.7+ elmentui前后端分离架构 让校园管理更高效的数字化平台系统源码
智慧校园是在数字通增强版基础上,研发的一套面向教育行业的数字化校园软件,其显著特点是集学校网站、协同办公、即时通讯、网络空间、移动办公于一体。在满足教职工日常办公需要的同时,拥有诸多教育行业功能,并提供便捷易用的“家校通”平台以满足老师、学生、家长的日常交流。数字通智慧校园教育版中的协同办公、即时通讯、移动办公等功能模块随通用版一同改进,将网络办公最新技术应用到教育行业。
24 1
|
5天前
|
SQL 关系型数据库 MySQL
【MySQL-3】图形化界面工具DataGrip安装&配置&使用
【MySQL-3】图形化界面工具DataGrip安装&配置&使用
|
5天前
|
关系型数据库 MySQL Linux
【MySQL-2】MySQL的下载&安装&启停&配置环境变量【一条龙教程】
【MySQL-2】MySQL的下载&安装&启停&配置环境变量【一条龙教程】
|
6天前
|
弹性计算 关系型数据库 MySQL
在线安装MySQL5.7和MySQL8.0
【4月更文挑战第30天】
21 0