Java实战之课程信息管理系统的实现


Posted in Java/Android onApril 01, 2022

一、项目运行

环境配置:

Jdk1.8 + Tomcat8.0 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)

项目技术:

Springboot + SpringMVC + MyBatis + FreeMarker + JavaScript + JQuery + Ajax + maven等等。

二、效果图展示

Java实战之课程信息管理系统的实现

Java实战之课程信息管理系统的实现

Java实战之课程信息管理系统的实现

Java实战之课程信息管理系统的实现

Java实战之课程信息管理系统的实现

Java实战之课程信息管理系统的实现

Java实战之课程信息管理系统的实现

三、核心代码

用户管理控制层

@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("/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";
    }
 
}

公告控制层

@Controller
@RequestMapping("/Notice")
public class NoticeController {
 
	@Autowired
	private NoticeService noticeService;
 
	@RequestMapping("/add")
	public String toAdd(){
		return "NoticeAdd";
	}
 
 
	@RequestMapping("/modify")
	public String modify(HttpServletRequest request,Notice notice){
		List<Notice> noticeList = noticeService.queryAll(notice);
		request.setAttribute("list",noticeList);
		return "noticeModfiy";
	}
 
	@RequestMapping("/update")
	public String update(HttpServletRequest request,Notice notice){
		User user = (User) request.getSession().getAttribute("user");
		notice.setUserid(user.getId());
		notice.setCreatdate(DateUtil.getStringToday());
		noticeService.update(notice);
		return "redirect:/Notice/modify";
	}
 
	@RequestMapping("/delete")
	public String delete(HttpServletRequest request,Notice notice){
		List<Notice> noticeList = noticeService.queryAll(notice);
		request.setAttribute("list",noticeList);
		return "noticeDelete";
	}
 
	@RequestMapping("/delete1")
	public String delete1(String ID){
		noticeService.delete(ID);
		return "redirect:/Notice/delete";
	}
 
	@ResponseBody
	@RequestMapping("/queryOne")
	public String queryOne(String id){
		System.out.println("=================="+id);
 
		Notice notice = new Notice();
		notice.setId(id);
		List<Notice> noticeList = noticeService.queryAll(notice);
		JSONObject json = new JSONObject();
		return json.toJSONString(noticeList.get(0));
	}
 
 
	@RequestMapping("/add1")
	public String  add(HttpServletRequest request,String Content,String biaoti) throws Exception{
		User user = (User) request.getSession().getAttribute("user");
		Notice notice = new Notice();
		notice.setContent(Content);
		notice.setTitle(biaoti);
		notice.setCreatdate(DateUtil.Date2String(new Date()));
		notice.setId(String.valueOf(Math.random()).substring(2, 8));
		notice.setUserid(user.getId());
		noticeService.add(notice);
 
		return "redirect:/User/Main";
	}
}

角色控制层

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

以上就是Java实战之课程信息管理系统的实现的详细内容,更多关于Java课程管理系统的资料请关注三水点靠木其它相关文章!

Java/Android 相关文章推荐
详解Java实践之建造者模式
Jun 18 Java/Android
SpringAop日志找不到方法的处理
Jun 21 Java/Android
深入理解java.lang.String类的不可变性
Jun 27 Java/Android
Java实现二维数组和稀疏数组之间的转换
Jun 27 Java/Android
java解析XML详解
Jul 09 Java/Android
在Spring-Boot中如何使用@Value注解注入集合类
Aug 02 Java/Android
SpringCloud Feign请求头删除修改的操作代码
Mar 20 Java/Android
SpringBoot2零基础到精通之数据库专项精讲
Mar 22 Java/Android
Java详细解析==和equals的区别
Apr 07 Java/Android
Java 垃圾回收超详细讲解记忆集和卡表
Apr 08 Java/Android
Java设计模式之代理模式
Apr 22 Java/Android
Spring 使用注解开发
May 20 Java/Android
Android超详细讲解组件ScrollView的使用
Spring Boot DevTools 全局配置学习指南
Spring事务管理下synchronized锁失效问题的解决方法
Mar 31 #Java/Android
Spring依赖注入多种类型数据的示例代码
Mar 31 #Java/Android
springboot layui hutool Excel导入的实现
spring注解 @PropertySource配置数据源全流程
Mar 25 #Java/Android
Netty客户端接入流程NioSocketChannel创建解析
Mar 25 #Java/Android
You might like
php中出现空白页的原因及解决方法汇总
2014/07/08 PHP
php查询相似度最高的字符串的方法
2015/03/12 PHP
Javascript操作cookie的函数代码
2012/10/03 Javascript
Javascript获取窗口(容器)的大小及位置参数列举及简要说明
2012/12/09 Javascript
javascript获取dom的下一个节点方法
2014/09/05 Javascript
JavaScript中实现最高效的数组乱序方法
2014/10/11 Javascript
javascript根据时间生成m位随机数最大13位
2014/10/30 Javascript
分析js闭包引起的事件注册问题
2016/03/29 Javascript
微信小程序 HTTPS报错整理常见问题及解决方案
2016/12/14 Javascript
jQuery实现判断控件是否显示的方法
2017/01/11 Javascript
微信小程序 页面跳转及数据传递详解
2017/03/14 Javascript
JavaScript闭包_动力节点Java学院整理
2017/06/27 Javascript
Angularjs实现下拉框联动的示例代码
2017/08/22 Javascript
Vue.js实现输入框绑定的实例代码
2017/08/24 Javascript
JS点击图片弹出文件选择框并覆盖原图功能的实现代码
2017/08/25 Javascript
vue.js模仿京东省市区三级联动的选择组件实例代码
2017/11/22 Javascript
详解浏览器缓存和webpack缓存配置
2018/07/06 Javascript
js/jQuery实现全选效果
2019/06/17 jQuery
JS实现横向轮播图(初级版)
2020/06/24 Javascript
javascript实现前端成语点击验证
2020/06/24 Javascript
基于vue hash模式微信分享#号的解决
2020/09/07 Javascript
NodeJS模块Buffer原理及使用方法解析
2020/11/11 NodeJs
python使用paramiko模块实现ssh远程登陆上传文件并执行
2014/01/27 Python
Python 爬虫模拟登陆知乎
2016/09/23 Python
Python双精度浮点数运算并分行显示操作示例
2017/07/21 Python
Scrapy爬虫实例讲解_校花网
2017/10/23 Python
python删除文本中行数标签的方法
2018/05/31 Python
Python 多维List创建的问题小结
2019/01/18 Python
Python实现多态、协议和鸭子类型的代码详解
2019/05/05 Python
pyenv与virtualenv安装实现python多版本多项目管理
2019/08/17 Python
pyenv虚拟环境管理python多版本和软件库的方法
2019/12/26 Python
python抢购软件/插件/脚本附完整源码
2021/03/04 Python
猫途鹰英国网站:TripAdvisor英国(旅游社区和旅游评论)
2016/08/30 全球购物
法国购买隐形眼镜和眼镜网站:Optical Center
2019/10/08 全球购物
小学教育见习总结
2015/06/23 职场文书
安全生产隐患排查制度
2015/08/05 职场文书