IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Java知识库 -> IDEA+Java+SSM+Mysql+Bootstrap实现Web学生信息管理系统 -> 正文阅读

[Java知识库]IDEA+Java+SSM+Mysql+Bootstrap实现Web学生信息管理系统

目录

一、系统介绍

1.开发环境

2.技术选型

3.系统功能

二、系统展示

1.登录系统?

2.管理员-首页?

3.管理员-学生管理?

4.管理员-课程管理?

5.管理员-班级管理?

6.管理员-更改密码?

7.用户-首页?

8.用户-查看课表?

9.用户-选课?

三、部分代码

ClassesController

CourseController

StudentController

TeacherController

UserController

四、其他

1.更多系统

2.源码下载

3.运行项目

4.备注

5.支持博主


一、系统介绍

1.开发环境

开发工具:IDEA2018

JDK版本:jdk1.8

Mysql版本:8.0.13

2.技术选型

Java+Spring+SpringMVC+Mybatis+Boostrap

3.系统功能

管理员

1.学生管理

2.课程管理

3.班级管理

4.更改密码

用户

1.查看课表

2.选课

二、系统展示

1.登录系统

2.管理员-首页

3.管理员-学生管理

4.管理员-课程管理

5.管理员-班级管理

6.管理员-更改密码

7.用户-首页

8.用户-查看课表

9.用户-选课

三、部分代码

ClassesController

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.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.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.offcn.pojo.Classes;
import com.offcn.pojo.Student;
import com.offcn.pojo.StudentExt;
import com.offcn.pojo.User;
import com.offcn.service.ClassesService;
import com.offcn.service.StudentService;

/**
 * <p>Company: offcn</p>
 * @author zgf
 * @date 2017年5月22日
 * @version 1.0
 */
@Controller
@RequestMapping("/cla")//用来处理请求地址映射的注解
public class ClassesController {
	@Resource
    ClassesService classesService;
	@Resource
	StudentService studentService;

	 /*
     * 列表与分页Action
     */
    @RequestMapping("/list")
    //声明一个list方法,返回一个String类型
    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",classesService.getClassesCount());
        
        model.addAttribute("clalist", classesService.getClassPager(pageNO, size));
        return "class/list";
     }


    /*
     * 删除单个对象Action
     */
    @RequestMapping("/delete/{id}")
    public String delete(Model model,@PathVariable int id,@RequestParam(required=false,defaultValue="1") int pageNO,RedirectAttributes redirectAttributes){
        if(classesService.delete(id)>0)
        {
        	//redirectAttributes:重定向之后还能带参数跳转
        	//隐藏了参数,链接地址上不直接暴露,但是能且只能在重定向的 “页面” 获取message参数值。其原理就是放到session中,session在跳到页面后马上移除对象。
            redirectAttributes.addFlashAttribute("message", "删除成功!");
        }else{
            redirectAttributes.addFlashAttribute("message", "删除失败!");
        }
        return "redirect:/cla/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=classesService.deletes(id);
        if(rows>0)
        {
            redirectAttributes.addFlashAttribute("message", "删除"+rows+"行记录成功!");
        }else{
            redirectAttributes.addFlashAttribute("message", "删除失败!");
        }
        return "redirect:/cla/list?pageNO="+pageNO;
    }
    
    /*
     * 添加学生
     */
    @RequestMapping("/add")
    public String add(Model model){
        model.addAttribute("entity", new Classes());
        return "class/add";
    }
    
    /*
     * 添加保存
     */
    @RequestMapping("/addSave")
    //@ModelAttribute:绑定请求参数到指定对象?
    public String addSave(Model model,@ModelAttribute("entity") @Valid Classes entity,BindingResult bindingResult){
        //如果模型中存在错误
        if(bindingResult.hasErrors()){
        	 model.addAttribute("entity", entity);
             return "class/add";
           
        }else{
        	classesService.insert(entity);
             return "redirect:/cla/list";    
             
        }
    }

    
    /*
     * 编辑
     */
    @RequestMapping("/edit/{id}")
    //@PathVariable可以用来映射URL中的占位符到目标方法的参数中
    public String edit(Model model,@PathVariable int id){
        model.addAttribute("entity", classesService.getCLassId(id));
        return "class/edit";
    }
    
    /*
     * 编辑保存
     */
    @RequestMapping("/editSave")
    //@Valid的参数后必须紧挨着一个BindingResult 参数
    //Spring验证的错误返回
    public String editSave(Model model,@ModelAttribute("entity") @Valid Classes entity,BindingResult bindingResult){
        //如果模型中存在错误
        if(bindingResult.hasErrors()){
        	 model.addAttribute("entity", entity);
             return "/class/edit";
            
        }else{
        	classesService.update(entity);
            
            return "redirect:list";    
            
        }
       
    }
    
    @RequestMapping("search/{id}")
    public String search(@PathVariable int id,Model model) {
    	List<StudentExt> slist=studentService.getStuByCid(id);
    	model.addAttribute("slist", slist);
		return "class/stulist";
	}
    

    
    @RequestMapping("search1/{id}")
    public String search1(@PathVariable int id,Model model) {
    	/*List<StudentExt> slist=studentService.getStuByCid(id);
    	model.addAttribute("slist", slist);*/
    	Classes classes=classesService.getStuByid(id);
    	model.addAttribute("classes", classes);
		return "class/stulist1";
	}
    
}


CourseController

package com.offcn.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import org.springframework.http.HttpRequest;
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.mapper.CtcMapper;
import com.offcn.pojo.Classes;
import com.offcn.pojo.Course;
import com.offcn.pojo.CtcKey;
import com.offcn.pojo.Teacher;
import com.offcn.pojo.User;
import com.offcn.service.ClassesService;
import com.offcn.service.CourseService;
import com.offcn.service.TeacherService;

import java.util.ArrayList;
import java.util.List;
/**
 * <p>Company: offcn</p>
 * @author zgf
 * @date 2017年5月22日
 * @version 1.0
 */
@Controller
@RequestMapping("/cou")
public class CourseController {
	@Resource
    CourseService courseService;
	@Resource
	TeacherService teacherService; 
	@Resource
	ClassesService classesService;
	
   /* @Resource
	CtcService ctcService;*/
    /* @Resource
     GradeService gradeService;*/

	 /*
     * 列表与分页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",courseService.getCourseCount());
        
        model.addAttribute("coulist", courseService.getCoursePager(pageNO, size));
        return "course/list";
     }


    /*
     * 删除单个对象Action
     */
    @RequestMapping("/delete/{id}")
    public String delete(Model model,@PathVariable int id,@RequestParam(required=false,defaultValue="1") int pageNO,RedirectAttributes redirectAttributes){
        if(courseService.delete(id)>0)
        {
            redirectAttributes.addFlashAttribute("message", "删除成功!");
        }else{
            redirectAttributes.addFlashAttribute("message", "删除成功!");
        }
        return "redirect:/cou/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=courseService.deletes(id);
        if(rows>0)
        {
            redirectAttributes.addFlashAttribute("message", "删除"+rows+"行记录成功!");
        }else{
            redirectAttributes.addFlashAttribute("message", "删除失败!");
        }
        return "redirect:/cou/list?pageNO="+pageNO;
    }
    
    /*
     * 添加
     */
    @RequestMapping("/add")
    public String add(Model model){
        model.addAttribute("entity", new Course());
        return "course/add";
    }
    
    /*
     * 添加保存
     */
    @RequestMapping("/addSave")
    public String addSave(Model model,@ModelAttribute("entity") @Valid Course entity,BindingResult bindingResult){
        //如果模型中存在错误
        if(bindingResult.hasErrors()){
        	 model.addAttribute("entity", entity);
             return "course/add";
           
        }else{
        	courseService.insert(entity);
             return "redirect:/cou/list";    
             
        }
    }

    
    /*
     * 编辑
     */
    @RequestMapping("/edit/{id}")
    public String edit(Model model,@PathVariable int id){
        model.addAttribute("entity", courseService.getCourseId(id));
        return "course/edit";
    }
    
    /*
     * 编辑保存
     */
    @RequestMapping("/editSave")
    public String editSave(Model model,@ModelAttribute("entity") @Valid Course entity,BindingResult bindingResult){
        //如果模型中存在错误
        if(bindingResult.hasErrors()){
        	 model.addAttribute("entity", entity);
             return "/course/edit";
            
        }else{
        	courseService.update(entity);
            
            return "redirect:list";    
            
        }
       
    }
    
    //排课
   @RequestMapping("/setTeacher/{id}")
    public String setTeacher(Model model,@PathVariable int id){
    	Course course=courseService.getCourseId(id);
    	model.addAttribute("entity",course);
    	List<Teacher> tlist=teacherService.getAllTeacher();
    	List<Classes> clist=classesService.getAllClasses();
    	model.addAttribute("tlist", tlist);
    	model.addAttribute("clist", clist);
    	return "course/setct";
    }
   
    @RequestMapping("editSavect")
    public String editSavect(Model model,@ModelAttribute("entity") Course entity,RedirectAttributes redirectAttributes){
    	//Course course=entity;
    	String classid=entity.getClasses();
    	String[] classids=classid.split(",");
    	List<CtcKey> ctclist=new ArrayList<CtcKey>();
    	for(int i=0;i<classids.length;i++){
    		CtcKey c=new CtcKey();
    		c.setCouid(entity.getId());
    		c.setClaid(Integer.parseInt(classids[i]));
    		c.setTid(entity.getTeacher().getId());
    		ctclist.add(c);
    	}
    	try{
    	  courseService.insertBatch(ctclist);
    	}catch(Exception e){
    		redirectAttributes.addFlashAttribute("msg", "排课存在冲突,请核对后重新选!");
    	}
    	return "redirect:/cou/list";
    }
    
    @RequestMapping("toChangePassword")
    public String toChangePassword(){
    	return "course/changePassword";
    }
    
    
    @ResponseBody
    @RequestMapping("changePassword")
    public int changePassword(String password,String oldPass,int id,HttpServletRequest re){
    	HttpSession session = re.getSession();
    	User user = (User)session.getAttribute("user");
    	if(user.getPassword().equals(oldPass)) {
    		courseService.changePassword(password,id,user);
    		return 1;
    	}else
    		return 2;
    	
    }
    
    
}


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.htmlhttps://blog.csdn.net/helongqiang/category_10020130.html

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

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

2.源码下载

3.运行项目

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

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

4.备注

如有侵权请联系我删除。

5.支持博主

如果您觉得此文对您有帮助,请点赞加关注加收藏。祝您生活愉快!想要获取其他资源可关注左侧微信公众号获取!

  Java知识库 最新文章
计算距离春节还有多长时间
系统开发系列 之WebService(spring框架+ma
springBoot+Cache(自定义有效时间配置)
SpringBoot整合mybatis实现增删改查、分页查
spring教程
SpringBoot+Vue实现美食交流网站的设计与实
虚拟机内存结构以及虚拟机中销毁和新建对象
SpringMVC---原理
小李同学: Java如何按多个字段分组
打印票据--java
上一篇文章      下一篇文章      查看所有文章
加:2021-11-11 12:35:06  更:2021-11-11 12:35:58 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 1:16:20-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码