Java实战之课程在线学习系统的实现

 更新时间:2022年04月13日 10:08:51   作者:qq_1334611189  
本文将采用SpringBoot+Spring+Mybatis+Thyeleaf实现一个课程在线学习系统,采用SpringBoot框架实现 前台模板用的thymeleaf数据库层采用mybatis框架注解模式,感兴趣的可以了解一下

一、前言

项目介绍

采用SpringBoot+Spring+Mybatis+Thyeleaf实现的在线学习系统,一共2个身份。

管理员登录系统后可以管理所有用户信息,管理角色信息,添加修改管理课件信息,学生学习培训批次管理,成绩导入管理

学生登录系统后可以查询自己的个人信息,查询课件列表学习,查询我的培训记录,查询自己的成绩

采用SpringBoot框架实现 前台模板用的thymeleaf 数据库层采用mybatis框架 注解模式

upload文件夹放入D盘根目录!

项目运行

登录地址: http://localhost:8080/th/login

管理员账号和密码: admin     admin

学生登录账号: 1314 密码: 123456

二、效果图展示

三、核心代码

用户管理控制层

@Controller
@RequestMapping("/User")
public class UserController {
 
	@Autowired
	private UserService userService;
 
	@Autowired
	private PowerService powerService;
 
	@Autowired
	private RoleService roleService;
 
	@Autowired
	private NoticeService noticeService;
 
	@RequestMapping("/Main")
	public String res(HttpServletRequest request){
		String time = DateUtil.getStringToday();
		request.getSession().setAttribute("time", time);
 
		Notice notice = new Notice();
 
		List<Notice> list = noticeService.queryAll(notice);
 
		notice = list.get(0);
 
		User user = userService.selectByPrimaryKey(notice.getUserid());
 
		notice.setUserid(user.getName());
		request.getSession().setAttribute("notice", notice);
 
		return "Main";
	}
 
	@RequestMapping("/changePa")
	public String res1(){
		return "changePass";
	}
 
 
	@RequestMapping("/Login")
	public ModelAndView login(HttpServletRequest request,String id,String password) throws Exception{
 
		ModelAndView mav = new ModelAndView();
 
		User user1 = userService.selectByPrimaryKey(id);
 
		if(user1 == null || !password.equals(user1.getPassword())){
			mav.setViewName("index");
		    request.getSession().setAttribute("info", "error");
			return mav;
		}else{
			Role role = new Role();
			role.setRoleid(user1.getRoleid());
			List<Role> list =roleService.QueryAll(role);
			role =list.get(0);
			request.getSession().setAttribute("roleName", role.getRolename());
			Power power = powerService.selectByPrimaryKey(role.getPowerid());
 
			if(!StringUtil.isNullOrEmpty(power.getPower())){
				request.getSession().setAttribute("power", power.getPower());
			}
 
			String time = DateUtil.getStringToday();
			request.getSession().setAttribute("time", time);
			request.getSession().setAttribute("user", user1);
			mav.setViewName("redirect:/User/Main");
		}
		return mav;
	}
 
	@RequestMapping("/updateStudent")
	public String update(User user){
		userService.updateByPrimaryKey(user);
		return "redirect:/User/student";
	}
 
	@RequestMapping("/updateTeacher")
	public String updatet(User user){
		userService.updateByPrimaryKey(user);
		return "redirect:/User/teacher";
	}
 
	@RequestMapping("/updatePa")
	public String updatePa(String userID,String password){
		User user = new User();
		System.out.println(userID);
		User user1 = userService.selectByPrimaryKey(userID);
		user1.setPassword(password);
		userService.updateByPrimaryKey(user1);
		return "Main";
	}
 
	@RequestMapping("/delete")
	public String delete(String ID){
		userService.deleteByPrimaryKey(ID);
		return "redirect:/User/queryAll";
	}
 
	@RequestMapping("/teacher")
	public String QueryAllTeacher(HttpServletRequest request,User user){
 
		List<User> list = userService.QueryAllTeacher(user);
		request.setAttribute("list", list);
 
	   if(null != user.getName()){
			request.setAttribute("name", user.getName());
		}
	   if(null != user.getMobile()){
			request.setAttribute("mobile", user.getMobile());
		}
		return "teacher";
	}
 
 
	@ResponseBody
	@RequestMapping("/jsonteacher")
	public String QueryAllTeacherjson(HttpServletRequest request,User user){
 
		List<User> list = userService.QueryAllTeacher(user);
		JSONObject json = new JSONObject();
 
		return json.toJSONString(list);
	}
 
	@RequestMapping("/student")
	public String QueryAllStudent(HttpServletRequest request,User user){
 
		List<User> list = userService.QueryAllStudent(user);
		request.setAttribute("list", list);
 
		if(null != user.getName()){
			request.setAttribute("name", user.getName());
		}
		if(null != user.getMobile()){
			request.setAttribute("mobile", user.getMobile());
		}
		return "student";
	}
 
	@RequestMapping("/addteacher")
	public String  addUser(User user){
 
	    String passWord = "123456";
		user.setPassword(passWord);
		user.setType(Constans.TEACHER);
		userService.insert(user);
		return "redirect:/User/teacher";
	}
 
	@RequestMapping("/addstudent")
	public String  addStudent(User user){
 
		String passWord = "123456";
		user.setPassword(passWord);
		user.setType(Constans.STUDENT);
		userService.insert(user);
		return "redirect:/User/student";
	}
 
	@ResponseBody
	@RequestMapping("/queryOne")
	public String queryOne(String ID){
		User user = new User();
		user.setId(ID);
		List<User> list = userService.QueryAll(user);
		user = list.get(0);
		JSONObject json = new JSONObject();
		String data = json.toJSONString(user);
 
		return data;
	}
 
	@RequestMapping("/quit")
	public ModelAndView quit(HttpServletRequest request) throws Exception{
		ModelAndView mav = new ModelAndView();
		HttpSession session1 = request.getSession();
		session1.invalidate();
		request.getSession().setAttribute("info", "quit");
		mav.setViewName("index");
 
		return mav;
	}
 
 
 
}

角色管理控制层

@Controller
@RequestMapping("/Role")
public class RoleController {
 
	@Autowired
	private RoleService depotService;
 
	@Autowired
	private PowerService powerService;
 
	@RequestMapping("/update")
	public String update(String id,String rolename,String powerContent){
		Role role = new Role();
		role.setRoleid(id);
		role.setRolename(rolename);
		depotService.update(role);
		List<Role> list = depotService.QueryAll(role);
		Role role1 = list.get(0);
		Power power = new Power();
		if(powerContent.indexOf("110") != -1){
			powerContent = powerContent + ",1100";
		}
		if(powerContent.indexOf("120") != -1){
			powerContent = powerContent + ",1200";
		}
		if(powerContent.indexOf("130") != -1){
			powerContent = powerContent + ",1300";
		}
		if(powerContent.indexOf("140") != -1){
			powerContent = powerContent + ",1400";
		}
		if(powerContent.indexOf("150") != -1){
			powerContent = powerContent + ",1500";
		}
		power.setPower(powerContent);
		power.setRoleid(role1.getPowerid());
		powerService.update(power);
		return "redirect:/Role/queryAll";
	}
 
	@RequestMapping("/delete")
	public String delete(String ID){
		depotService.deleteByPrimaryKey(ID);
		return "redirect:/Role/queryAll";
	}
 
	@RequestMapping("/queryAll")
	public String queryAll(HttpServletRequest request,Role role){
 
 
		List<Role> list = depotService.QueryAll(role);
		request.setAttribute("list", list);
 
	   if(null != role.getRolename()){
			request.setAttribute("rolename", role.getRolename());
		}
		return "Role";
	}
 
	@RequestMapping("/add")
	public String  add(String roleid,String rolename,String powerContent){
		Power power1 = new Power();
		Role role = new Role();
		String powerid = String.valueOf(Math.random()).substring(2, 8);
		role.setRoleid(String.valueOf(Math.random()).substring(2, 6));
		role.setPowerid(powerid);
		role.setRolename(rolename);
 
		power1.setPower(powerContent);
		power1.setRoleid(powerid);
		power1.setId(String.valueOf(Math.random()).substring(2, 8));
 
		powerService.insert(power1);
		depotService.insert(role);
		return "redirect:/Role/queryAll";
	}
 
	@ResponseBody
	@RequestMapping("/queryOne")
	public String queryOne(String ID){
		JSONObject json = new JSONObject();
		Role depot = new Role();
		Power power = new Power();
		power.setId(ID);
		System.out.println(ID);
		depot.setRoleid(ID);
 
		List<Role> list = depotService.QueryAll(depot);
 
		Role role1 = list.get(0);
		Power power1 = powerService.selectByPrimaryKey(role1.getPowerid());
		String name = role1.getRolename();
 
		role1.setPowerid(power1.getPower());
 
		String data = json.toJSONString(role1);
 
		return data;
	}
 
	@ResponseBody
	@RequestMapping("/getAll")
	public String getAll(Role role){
		JSONObject json = new JSONObject();
		List<Role> list = depotService.QueryAll(role);
 
		String jsonq = json.toJSONString(list);
 
		System.out.println(jsonq);
		return jsonq;
	}
 
 
}

课程管理控制层

@Controller
@RequestMapping("/Course")
public class CourseController {
 
    @Autowired
    private CourseService courseService;
    @Autowired
    private CurelationService curelationService;
 
 
    @Autowired
    private CoursecommentService coursecommentService;
 
    @ResponseBody
    @RequestMapping("/queryOneCom")
    public String queryOneCom(String ID){
        Coursecomment course = new Coursecomment();
        course.setId(ID);
        System.out.println("===================================="+ID);
        List<Coursecomment> list = coursecommentService.queryAll(course);
        course = list.get(0);
        JSONObject json = new JSONObject();
        return json.toJSONString(course);
    }
 
 
 
    @RequestMapping("addComment")
    public String addComment(HttpServletRequest request, Coursecomment coursecomment){
        User user = (User) request.getSession().getAttribute("user");
        coursecomment.setCreatetime(DateUtil.getStringToday());
        coursecomment.setUserid(user.getName());
        coursecomment.setId(String.valueOf(Math.random()).substring(2,10));
        coursecommentService.insert(coursecomment);
        return "redirect:/Course/suggeetion";
    }
 
 
    @ResponseBody
    @RequestMapping("jsoncourse")
    public String jsoncourse(HttpServletRequest request, Curelation course){
        User user = (User) request.getSession().getAttribute("user");
        /*String type = "1";
        if ("1".equals(user.getType())){
            type="2";
        }
        course.setType(type);
        course.setUserid(user.getId());*/
        List<Curelation> curelationList = curelationService.queryAll(course);
        List<Course> dataList = new ArrayList<>();
        for (int i = 0; i < curelationList.size(); i++) {
            Course curelation = courseService.selectByPrimaryKey(curelationList.get(i).getCourseid());
            dataList.add(curelation);
        }
 
        JSONObject json = new JSONObject();
        return json.toJSONString(dataList);
    }
 
    @RequestMapping("suggeetion")
    public String suggeetion(HttpServletRequest request, Coursecomment coursecomment){
 
        List<Coursecomment> coursecomments = coursecommentService.queryAll(coursecomment);
 
 
        request.setAttribute("list",coursecomments);
        return "suggeetion";
    }
 
    @RequestMapping("view")
    public String view(HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("user");
 
        String type = "1";
 
        if ("1".equals(user.getType())){
            type="2";
        }
 
        List<Map<String,String>> list=curelationService.courseview(type,user.getId());
        request.setAttribute("list",list);
        return "courseview";
    }
 
    @RequestMapping("deletecomment")
    public String deletecomment(String ID){
        coursecommentService.deleteByPrimaryKey(ID);
        return "redirect:/Course/suggeetion";
    }
 
 
 
    @RequestMapping("queryAll")
    public String queryAll(HttpServletRequest request, Course course){
        List<Course> list = courseService.queryAll(course);
        request.setAttribute("list",list);
 
        return "course";
    }
 
    @RequestMapping("/receive")
    public String receive(HttpServletRequest request, HttpServletResponse response, MultipartFile file){
 
        try {
            //也可以用request获取上传文件
            //MultipartFile  fileFile = request.getFile("file"); //这里是页面的name属性
            //转换成输入流
            InputStream is = file.getInputStream();
            //得到excel
            Workbook workbook = Workbook.getWorkbook(is);
            //得到sheet
            Sheet sheet = workbook.getSheet(0);
            //得到列数
            int colsNum = sheet.getColumns();
            //得到行数
            int rowsNum = sheet.getRows();
            //单元格
            Cell cell;
            Cell cell1;
 
            List<Map> list = new ArrayList<>();
            Map<Integer, String> map = new HashMap<Integer, String>();
            for (int i = 1; i < rowsNum; i++) {//我的excel第一行是标题,所以 i从1开始
                cell  = sheet.getCell(0,i);
                cell1 = sheet.getCell(5,i);
                Curelation curelation = new Curelation();
 
                curelation.setId(cell.getContents());
                curelation.setScore(cell1.getContents());
                curelationService.updateByPrimaryKey(curelation);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (BiffException e) {
            e.printStackTrace();
        }
        return "redirect:/Course/queryCourse";
    }
 
    @RequestMapping("/queryCourse")
    public String queryScore(HttpServletRequest request,Curelation curelation){
 
        curelation.setType("1");
        List<Curelation> list = curelationService.queryAll(curelation);
        request.setAttribute("list",list );
        return "ScoreList";
    }
 
    @RequestMapping("/teacher")
    public String teacher(HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("user");
        Course course = new Course();
        course.setCourseteacher(user.getName());
        List<Course> courseList = courseService.queryAll(course);
        request.setAttribute("list",courseList);
        return "teacherDeal";
    }
 
    @RequestMapping("/student")
    public String student(HttpServletRequest request){
        Course course = new Course();
        course.setStatus("1");
        List<Course> courseList = courseService.queryAll(course);
        request.setAttribute("list",courseList);
        return "studentChoose";
    }
 
 
    @RequestMapping("/upload")
    public  String upload(){
 
        return "uploadScore";
    }
 
 
    @RequestMapping("/Export")
    public void Export(HttpServletResponse response, User user){
 
        response.setContentType("application/binary;charset=UTF-8");
        try {
            ServletOutputStream out = response.getOutputStream();
            String fileName1 = "学生信息";
            String fileName2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date());
            String fileName = fileName1+fileName2;
            response.setHeader("Content-disposition", "attachment; filename=" +new String(fileName.getBytes("gbk"),"iso8859-1") + ".xls");
            String[] titles = { "成绩编号","学生编号", "学生姓名", "课程编号", "课程名称", "成绩" };
            courseService.export(titles, out,user);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
 
 
    @RequestMapping("delete")
    public String delete(String ID){
        courseService.deleteByPrimaryKey(ID);
        return "redirect:/Course/queryAll";
    }
 
    @RequestMapping("update")
    public String update(Course course){
        courseService.updateByPrimaryKey(course);
        return "redirect:/Course/queryAll";
    }
 
    @Transactional
    @RequestMapping("update1")
    public String update1(HttpServletRequest request,Course course){
        course.setStatus("1");
        courseService.updateByPrimaryKey(course);
        User user = (User) request.getSession().getAttribute("user");
        Curelation curelation1 = new Curelation();
        curelation1.setCourseid(course.getId());
        curelation1.setUserid(user.getId());
        List<Curelation> curelationList = curelationService.queryAll(curelation1);
        if(curelationList.size()==0){
            Curelation curelation = new Curelation();
            curelation.setUserid(user.getId());
            curelation.setCourseid(course.getId());
            curelation.setId(String.valueOf(Math.random()).substring(2, 10));
            curelation.setType("2");
            curelationService.insert(curelation);
        }
        return "redirect:/Course/teacher";
    }
 
    @RequestMapping("update2")
    public String update2(HttpServletRequest request,Course course){
        User user = (User) request.getSession().getAttribute("user");
        Curelation curelation = new Curelation();
        curelation.setUserid(user.getId());
        curelation.setCourseid(course.getId());
        List<Curelation> curelationList = curelationService.queryAll(curelation);
        if(curelationList.size() == 0){
            curelation.setId(String.valueOf(Math.random()).substring(2, 10));
            curelation.setType("1");
            curelationService.insert(curelation);
        }else{
            Curelation curelation1 = curelationList.get(0);
            curelation1.setUserid(user.getId());
            curelation1.setCourseid(course.getId());
            System.out.println(curelation1.toString());
            curelationService.updateByPrimaryKey(curelation1);
        }
        return "redirect:/Course/student";
    }
 
    @ResponseBody
    @RequestMapping("/queryOne")
    public String queryOne(String ID){
        Course course = new Course();
        course.setId(ID);
        List<Course> list = courseService.queryAll(course);
        course = list.get(0);
        JSONObject json = new JSONObject();
        return json.toJSONString(course);
    }
 
    @RequestMapping("add")
    public String addCourse(Course course){
        course.setId(String.valueOf(Math.random()).substring(2, 10));
        System.out.println(course.toString());
        courseService.insert(course);
        return "redirect:/Course/queryAll";
    }
 
}

以上就是Java实战之课程在线学习系统的实现的详细内容,更多关于Java课程在线学习系统的资料请关注脚本之家其它相关文章!

相关文章

  • springboot使用swagger-ui 2.10.5 有关版本更新带来的问题小结

    springboot使用swagger-ui 2.10.5 有关版本更新带来的问题小结

    这篇文章主要介绍了springboot使用swagger-ui 2.10.5 有关版本更新带来的问题小结,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-12-12
  • 关于spring项目中无法加载resources下文件问题及解决方法

    关于spring项目中无法加载resources下文件问题及解决方法

    在学习Spring过程中,TestContext框架试图检测一个默认的XML资源位置,再resources下创建了一个com.example的文件夹,执行时,报错,本文给大家介绍spring项目中无法加载resources下文件,感兴趣的朋友跟随小编一起看看吧
    2023-10-10
  • JavaWeb实现表单提交的示例详解

    JavaWeb实现表单提交的示例详解

    这篇文章主要介绍了如何利用JavaWeb实现表单提交功能,文中的示例代码讲解详细,对我们学习JavaWeb有一定帮助,感兴趣的可以了解一下
    2022-03-03
  • Java利用泛型实现折半查找法

    Java利用泛型实现折半查找法

    泛型是JAVA重要的特性,使用泛型编程,可以使代码复用率提高。查找作为泛型的一个简单应用,本文将使用泛型实现折半查找法,感兴趣的可以了解一下
    2022-08-08
  • 从 JVM 中深入探究 Synchronized作用及原理

    从 JVM 中深入探究 Synchronized作用及原理

    这篇文章主要为大家介绍了从 JVM 中深入探究 Synchronized作用及原理,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-03-03
  • mybatis分页及模糊查询功能实现

    mybatis分页及模糊查询功能实现

    这篇文章主要为大家详细为大家详细介绍了mybatis实现分页及模糊查询功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-06-06
  • Security中的WebSecurityConfigurerAdapter详解

    Security中的WebSecurityConfigurerAdapter详解

    这篇文章主要介绍了Security中的WebSecurityConfigurerAdapter详解,今天我们要进一步的的学习如何自定义配置Spring Security,本文结合实例代码给大家介绍的非常详细,需要的朋友可以参考下
    2023-07-07
  • Java如何通过Maven管理项目依赖

    Java如何通过Maven管理项目依赖

    这篇文章主要介绍了Java如何通过Maven管理项目依赖,帮助大家更好的理解和使用maven,感兴趣的朋友可以了解下
    2020-10-10
  • Spring框架中IoC容器与DI依赖注入教程

    Spring框架中IoC容器与DI依赖注入教程

    IOC也是Spring的核心之一了,之前学的时候是采用xml配置文件的方式去实现的,后来其中也多少穿插了几个注解,但是没有说完全采用注解实现。那么这篇文章就和大家分享一下,全部采用注解来实现IOC + DI
    2023-01-01
  • 基于Java解析国密数字证书的操作方法

    基于Java解析国密数字证书的操作方法

    在Java环境中解析使用国密算法(如SM3WITHSM2)的数字证书可能遇到挑战,使用BouncyCastle加密库可以解决Java标准库无法识别国密算法椭圆曲线的问题,成功解析国密数字证书,添加BouncyCastle依赖并修改代码,使其支持国密算法,即可解析采用SM3WITHSM2算法的数字证书
    2024-09-09

最新评论