源码获取:俺的博客首页 "资源" 里下载!
项目介绍
基于SSM的在线网络教学系统
角色:管理员、用户
管理员:个人中心、 教师管理、学生管理、课程信息管理、教学信息管理、作业信息管理、作业评分管理 试卷管理、试题管理、管理员管理、学习论坛、系统管理
前台用户 登录注册、首页、学习论坛 、试卷列表 、网站公告 、个人中心、 后台管理等
教师:课程信息管理、教学信息管理、作业信息管理、作业评分管理等
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 5.7/8.0等版本均可;
技术栈
后端:SSM(Spring+SpringMVC+Mybatis)
前端:ElementUI+Vue
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,修改配置,运行项目;
3. 将项目中db.xml配置文件中的数据库配置改为自己的配置,然后运行;
![](https://i-blog.csdnimg.cn/blog_migrate/6f7eea3d7c4c9c90ad7fe1d1f44cc46c.png)
![](https://i-blog.csdnimg.cn/blog_migrate/e7db8d5b3f1c7b3ebf702308ada020b4.png)
![](https://i-blog.csdnimg.cn/blog_migrate/bb0e6127fffe1d2d4b9ec92887c04021.png)
![](https://i-blog.csdnimg.cn/blog_migrate/85e730bde2351b032cdd13af45e2211f.png)
![](https://i-blog.csdnimg.cn/blog_migrate/9ccb4313d65ce7a305c941c0ed91480a.png)
![](https://i-blog.csdnimg.cn/blog_migrate/4901430a332c14ec650203c8bdae300f.png)
教师管理控制层:
@Controller
@RequestMapping("/teacher")
public class TeacherController extends BaseController {
/**
* 依赖注入 start dao/service/===
*/
@Autowired
private TeacherService teacherService;
// --------------------------------------- 华丽分割线 ------------------------------
/**
* 分页查询 返回list对象(通过对By Sql)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findBySql")
public String findBySql(Teacher teacher, Model model, HttpServletRequest request, HttpServletResponse response) {
//分页查询
String sql = "SELECT * FROM teacher WHERE isDelete = 0 ";
if(!isEmpty(teacher.getUsername())){
sql += " and username like '%"+teacher.getUsername()+"%'";
}
if(!isEmpty(teacher.getSex())){
sql += " and sex like '%"+teacher.getSex()+"%'";
}
if(!isEmpty(teacher.getPassword())){
sql += " and password like '%"+teacher.getPassword()+"%'";
}
if(!isEmpty(teacher.getXw())){
sql += " and xw like '%"+teacher.getXw()+"%'";
}
if(!isEmpty(teacher.getPhone())){
sql += " and phone like '%"+teacher.getPhone()+"%'";
}
if(!isEmpty(teacher.getIsDelete())){
sql += " and isDelete like '%"+teacher.getIsDelete()+"%'";
}
sql += " ORDER BY ID DESC ";
Pager<Teacher> pagers = teacherService.findBySqlRerturnEntity(sql);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", teacher);
return "teacher/teacher";
}
/**
* 分页查询 返回list对象(通过Map)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByMap")
public String findByMap(Teacher teacher, Model model, HttpServletRequest request, HttpServletResponse response) {
//通过map查询
Map<String,Object> params = new HashMap<String,Object>();
if(!isEmpty(teacher.getUsername())){
params.put("username", teacher.getUsername());
}
if(!isEmpty(teacher.getSex())){
params.put("sex", teacher.getSex());
}
if(!isEmpty(teacher.getPassword())){
params.put("password", teacher.getPassword());
}
if(!isEmpty(teacher.getXw())){
params.put("xw", teacher.getXw());
}
if(!isEmpty(teacher.getPhone())){
params.put("phone", teacher.getPhone());
}
if(!isEmpty(teacher.getIsDelete())){
params.put("isDelete", teacher.getIsDelete());
}
//分页查询
Pager<Teacher> pagers = teacherService.findByMap(params);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", teacher);
return "teacher/teacher";
}
/**********************************【增删改】******************************************************/
/**
* 跳至添加页面
* @return
*/
@RequestMapping(value = "/add")
public String add() {
return "teacher/add";
}
/**
* 跳至详情页面
* @return
*/
@RequestMapping(value = "/view")
public String view(Integer id,Model model) {
Teacher obj = teacherService.load(id);
model.addAttribute("obj",obj);
return "teacher/view";
}
/**
* 添加执行
* @return
*/
@RequestMapping(value = "/exAdd")
public String exAdd(Teacher teacher, Model model, HttpServletRequest request, HttpServletResponse response) {
teacher.setIsDelete(0);
teacher.setPassword("111111");
teacherService.insert(teacher);
return "redirect:/teacher/findBySql.action";
}
/**
* 跳至修改页面
* @return
*/
@RequestMapping(value = "/update")
public String update(Integer id,Model model) {
Teacher obj = teacherService.load(id);
model.addAttribute("obj",obj);
return "teacher/update";
}
/**
* 添加修改
* @return
*/
@RequestMapping(value = "/exUpdate")
public String exUpdate(Teacher teacher, Model model, HttpServletRequest request, HttpServletResponse response) {
teacherService.updateById(teacher);
return "redirect:/teacher/findBySql.action";
}
/**
* 删除通过主键
* @return
*/
@RequestMapping(value = "/delete")
public String delete(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
Teacher load = teacherService.load(id);
load.setIsDelete(1);
teacherService.updateById(load);
return "redirect:/teacher/findBySql.action";
}
}
管理员管理控制层:
@Controller
@RequestMapping("/manage")
public class ManageController extends BaseController {
/**
* 依赖注入 start dao/service/===
*/
@Autowired
private ManageService manageService;
// --------------------------------------- 华丽分割线 ------------------------------
/*********************************查询列表【不分页】***********************************************/
/**
* 【不分页 => 查询列表 => 无条件】
* @Title: listAll
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @author
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listAll")
public String listAll(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response){
List<Manage> listAll = manageService.listAll();
model.addAttribute("list", listAll);
return "manage/manage";
}
/**
* 【不分页=》查询列表=>有条件】
* @Title: listByEntity
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @author
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listByEntity")
public String listByEntity(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response){
List<Manage> listAll = manageService.listAllByEntity(manage);
model.addAttribute("list", listAll);
return "manage/manage";
}
/**
* 【不分页=》查询列表=>有条件】
* @Title: listByMap
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @author
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listByMap")
public String listByMap(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response){
//通过map查询
Map<String,Object> params = new HashMap<String,Object>();
if(!isEmpty(manage.getUserName())){
params.put("userName", manage.getUserName());
}
if(!isEmpty(manage.getPassWord())){
params.put("passWord", manage.getPassWord());
}
if(!isEmpty(manage.getRealName())){
params.put("realName", manage.getRealName());
}
List<Manage> listAll = manageService.listByMap(params);
model.addAttribute("list", listAll);
return "manage/manage";
}
/*********************************查询列表【分页】***********************************************/
/**
* 分页查询 返回list对象(通过对象)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByObj")
public String findByObj(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response) {
//分页查询
Pager<Manage> pagers = manageService.findByEntity(manage);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", manage);
return "manage/manage";
}
/**
* 分页查询 返回list对象(通过对By Sql)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findBySql")
public String findBySql(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response) {
//分页查询
String sql = "SELECT * FROM manage WHERE 1=1 ";
if(!isEmpty(manage.getUserName())){
sql += " and userName like '%"+manage.getUserName()+"%'";
}
if(!isEmpty(manage.getPassWord())){
sql += " and passWord like '%"+manage.getPassWord()+"%'";
}
if(!isEmpty(manage.getRealName())){
sql += " and realName like '%"+manage.getRealName()+"%'";
}
sql += " ORDER BY ID DESC ";
Pager<Manage> pagers = manageService.findBySqlRerturnEntity(sql);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", manage);
return "manage/manage";
}
/**
* 分页查询 返回list对象(通过Map)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByMap")
public String findByMap(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response) {
//通过map查询
Map<String,Object> params = new HashMap<String,Object>();
if(!isEmpty(manage.getUserName())){
params.put("userName", manage.getUserName());
}
if(!isEmpty(manage.getPassWord())){
params.put("passWord", manage.getPassWord());
}
if(!isEmpty(manage.getRealName())){
params.put("realName", manage.getRealName());
}
//分页查询
Pager<Manage> pagers = manageService.findByMap(params);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", manage);
return "manage/manage";
}
/**********************************【增删改】******************************************************/
/**
* 跳至添加页面
* @return
*/
@RequestMapping(value = "/add")
public String add() {
return "manage/add";
}
/**
* 跳至详情页面
* @return
*/
@RequestMapping(value = "/view")
public String view(Integer id,Model model) {
Manage obj = manageService.load(id);
model.addAttribute("obj",obj);
return "manage/view";
}
/**
* 添加执行
* @return
*/
@RequestMapping(value = "/exAdd")
public String exAdd(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response) {
manageService.insert(manage);
return "redirect:/manage/findBySql.action";
}
/**
* 跳至修改页面
* @return
*/
@RequestMapping(value = "/update")
public String update(Integer id,Model model) {
Manage obj = manageService.load(id);
model.addAttribute("obj",obj);
return "manage/update";
}
/**
* 添加修改
* @return
*/
@RequestMapping(value = "/exUpdate")
public String exUpdate(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response) {
//1.通过实体类修改,可以多传修改条件
manageService.updateById(manage);
//2.通过主键id修改
//manageService.updateById(manage);
return "redirect:/manage/findBySql.action";
}
/**
* 删除通过主键
* @return
*/
@RequestMapping(value = "/delete")
public String delete(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
///1.通过主键删除
manageService.deleteById(id);
/*以下是多种删除方式*/
// //2.通过实体条件删除
// manageService.deleteByEntity(manage);
// //3.通过参数删除
// //通过map查询
// Map<String,Object> params = new HashMap<String,Object>();
//
// if(!isEmpty(manage.getUserName())){
// params.put("userName", manage.getUserName());
// }
//
// if(!isEmpty(manage.getPassWord())){
// params.put("passWord", manage.getPassWord());
// }
//
// if(!isEmpty(manage.getRealName())){
// params.put("realName", manage.getRealName());
// }
//
// manageService.deleteByMap(params);
// //4.状态删除
// Manage load = manageService.getById(manage.getId())
// load.setIsDelete(1);
// manageService.update(load);
//5.状态删除
//Manage load = manageService.load(id);
//load.setIsDelete(1);
//manageService.update(load);
return "redirect:/manage/findBySql.action";
}
// --------------------------------------- 华丽分割线 ------------------------------
// --------------------------------------- 【下面是ajax操作的方法。】 ------------------------------
/*********************************查询列表【不分页】***********************************************/
/**
* 【不分页 => 查询列表 => 无条件】
* @Title: listAll
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @author
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listAllJson", method = RequestMethod.POST)
@ResponseBody
public String listAllJson(Manage manage, HttpServletRequest request, HttpServletResponse response){
List<Manage> listAll = manageService.listAll();
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", listAll);
jsonObject.put("obj", manage);
return jsonObject.toString();
}
/**
* 【不分页=》查询列表=>有条件】
* @Title: listByEntity
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @author
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listByEntityJson", method = RequestMethod.POST)
@ResponseBody
public String listByEntityJson(Manage manage, HttpServletRequest request, HttpServletResponse response){
List<Manage> listAll = manageService.listAllByEntity(manage);
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", listAll);
jsonObject.put("obj", manage);
return jsonObject.toString();
}
/**
* 【不分页=》查询列表=>有条件】
* @Title: listByMap
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @author
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listByMapJson", method = RequestMethod.POST)
@ResponseBody
public String listByMapJson(Manage manage,HttpServletRequest request, HttpServletResponse response){
//通过map查询
Map<String,Object> params = new HashMap<String,Object>();
if(!isEmpty(manage.getUserName())){
params.put("userName", manage.getUserName());
}
if(!isEmpty(manage.getPassWord())){
params.put("passWord", manage.getPassWord());
}
if(!isEmpty(manage.getRealName())){
params.put("realName", manage.getRealName());
}
List<Manage> listAll = manageService.listByMap(params);
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", listAll);
jsonObject.put("obj", manage);
return jsonObject.toString();
}
/**
* 分页查询 返回list json(通过对象)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByObjJson", method = RequestMethod.POST)
@ResponseBody
public String findByObjByEntityJson(Manage manage, HttpServletRequest request, HttpServletResponse response) {
//分页查询
Pager<Manage> pagers = manageService.findByEntity(manage);
JSONObject jsonObject = new JSONObject();
jsonObject.put("pagers", pagers);
jsonObject.put("obj", manage);
return jsonObject.toString();
}
/**
* 分页查询 返回list json(通过Map)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByMapJson", method = RequestMethod.POST)
@ResponseBody
public String findByMapJson(Manage manage,HttpServletRequest request, HttpServletResponse response) {
//通过map查询
Map<String,Object> params = new HashMap<String,Object>();
if(!isEmpty(manage.getUserName())){
params.put("userName", manage.getUserName());
}
if(!isEmpty(manage.getPassWord())){
params.put("passWord", manage.getPassWord());
}
if(!isEmpty(manage.getRealName())){
params.put("realName", manage.getRealName());
}
//分页查询
Pager<Manage> pagers = manageService.findByMap(params);
JSONObject jsonObject = new JSONObject();
jsonObject.put("pagers", pagers);
jsonObject.put("obj", manage);
return jsonObject.toString();
}
/**
* ajax 添加
* @param
* @return
*/
@RequestMapping(value = "/exAddJson", method = RequestMethod.POST)
@ResponseBody
public String exAddJson(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response) {
manageService.insert(manage);
JSONObject jsonObject = new JSONObject();
jsonObject.put("message", "添加成功");
return jsonObject.toString();
}
/**
* ajax 修改
* @param
* @return
*/
@RequestMapping(value = "/exUpdate.json", method = RequestMethod.POST)
@ResponseBody
public String exUpdateJson(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response) {
//1.通过实体类修改,可以多传修改条件
manageService.updateById(manage);
//2.通过主键id修改
//manageService.updateById(manage);
JSONObject jsonObject = new JSONObject();
jsonObject.put("message", "修改成功");
return jsonObject.toString();
}
/**
* ajax 删除
* @return
*/
@RequestMapping(value = "/delete.json", method = RequestMethod.POST)
@ResponseBody
public String exDeleteJson(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
///1.通过主键删除
manageService.deleteById(id);
/*以下是多种删除方式*/
// //2.通过实体条件删除
// manageService.deleteByEntity(manage);
// //3.通过参数删除
// //通过map查询
// Map<String,Object> params = new HashMap<String,Object>();
//
// if(!isEmpty(manage.getUserName())){
// params.put("userName", manage.getUserName());
// }
//
// if(!isEmpty(manage.getPassWord())){
// params.put("passWord", manage.getPassWord());
// }
//
// if(!isEmpty(manage.getRealName())){
// params.put("realName", manage.getRealName());
// }
//
// manageService.deleteByMap(params);
// //4.状态删除
// Manage load = manageService.getById(manage.getId())
// load.setIsDelete(1);
// manageService.updateById(load);
//5.状态删除
//Manage load = manageService.load(id);
//load.setIsDelete(1);
//manageService.updateById(load);
JSONObject jsonObject = new JSONObject();
jsonObject.put("message", "删除成功");
return jsonObject.toString();
}
/**
* 单文件上传
* @param file
* @param request
* @param model
* @return
*/
@RequestMapping(value = "/saveFile")
public String saveFile(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request, Model model) {
System.out.println("开始");
String path = request.getSession().getServletContext().getRealPath("/upload");
String fileName = file.getOriginalFilename();
System.out.println(path);
File targetFile = new File(path, fileName);
if(!targetFile.exists()){
targetFile.mkdirs();
}
//保存
try {
file.transferTo(targetFile);
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
/**
* springMvc多文件上传
* @param files
* @param id
* @return
*/
@RequestMapping(value = "/saveFiles")
public String saveFiles(@RequestParam("file") CommonsMultipartFile[] files,Integer id,HttpServletRequest request){
for(int i = 0;i<files.length;i++){
System.out.println("fileName---------->" + files[i].getOriginalFilename());
if(!files[i].isEmpty()){
int pre = (int) System.currentTimeMillis();
try {
//拿到输出流,同时重命名上传的文件
String filePath = request.getRealPath("/upload");
File f=new File(filePath);
if(!f.exists()){
f.mkdirs();
}
String fileNmae=new Date().getTime() + files[i].getOriginalFilename();
File file=new File(filePath+"/"+pre + files[i].getOriginalFilename());
if(!file.exists()){
file.createNewFile();
}
files[i].transferTo(file);
} catch (Exception e) {
e.printStackTrace();
System.out.println("上传出错");
}
}
}
return "";
}
// --------------------------------------- 华丽分割线 ------------------------------
}
登录管理控制层:
@Controller
@RequestMapping("/login")
public class LoginController extends BaseController{
@Autowired
private ManageService manageService;
@Autowired
private TeacherService teacherService;
/**
* 跳转登陆
* @return
*/
@RequestMapping("/login")
public String login(){
return "login/mLogin";
}
@RequestMapping("/mtuichu")
public String mtuichu(HttpServletRequest request){
//request.getSession().invalidate();
return "login/mLogin";
}
@RequestMapping("/welcome")
private String welcome(){
return "login/welcome";
}
@RequestMapping("/toLogin")
public String toLogin(Manage manage, Integer type,HttpServletRequest request, HttpServletResponse response){
if (type == null){
return "redirect:/login/mtuichu";
}
if (type == 1){
Manage byEntity = manageService.getByEntity(manage);
if(byEntity == null){
return "redirect:/login/mtuichu";
}else{
request.getSession().setAttribute("role", 1);
request.getSession().setAttribute("username", byEntity.getUserName());
request.getSession().setAttribute("userId", byEntity.getId());
}
}
if (type == 2){
Teacher t = new Teacher();
t.setPassword(manage.getPassWord());
t.setUsername(manage.getUserName());
t.setIsDelete(0);
Teacher byEntity = teacherService.getByEntity(t);
if(byEntity == null){
return "redirect:/login/mtuichu";
}else{
request.getSession().setAttribute("role", 2);
request.getSession().setAttribute("username", byEntity.getUsername());
request.getSession().setAttribute("userId", byEntity.getId());
}
}
return "login/mIndex";
}
/**
* 退出
* @param request
* @param response
* @return
*/
@RequestMapping("/tuichu")
public String tuichu( HttpServletRequest request, HttpServletResponse response){
HttpSession session = request.getSession();
session.invalidate();
return "login/login";
}
@RequestMapping("/head")
private String head(){
return "inc/head";
}
@RequestMapping("/left")
private String left(){
return "inc/left";
}
@RequestMapping(value = "/update")
public String update(Integer id,Model model,HttpServletRequest request) {
Object attribute = request.getSession().getAttribute("userId");
if (attribute == null){
return "redirect:/login/mtuichu";
}
Integer userId = Integer.valueOf(attribute.toString());
Teacher byId = teacherService.getById(userId);
model.addAttribute("obj",byId);
return "login/update";
}
@RequestMapping(value = "/toUpdate")
public String toUpdate(Integer id,String phone,Model model,HttpServletRequest request) {
Object attribute = request.getSession().getAttribute("userId");
if (attribute == null){
return "redirect:/login/mtuichu";
}
Integer userId = Integer.valueOf(attribute.toString());
Teacher byId = teacherService.getById(userId);
byId.setPhone(phone);
teacherService.updateById(byId);
model.addAttribute("obj",byId);
return "login/update";
}
@RequestMapping(value = "/pass")
public String pass(Integer id,Model model,HttpServletRequest request) {
Object attribute = request.getSession().getAttribute("userId");
if (attribute == null){
return "redirect:/login/mtuichu";
}
Integer userId = Integer.valueOf(attribute.toString());
Teacher byId = teacherService.getById(userId);
model.addAttribute("obj",byId);
return "login/pass";
}
@RequestMapping("/upass")
@ResponseBody
public String upass(HttpServletRequest request,String password){
Object attribute = request.getSession().getAttribute("userId");
JSONObject j = new JSONObject();
if (attribute == null){
j.put("res", 0);
return j.toString();
}
Integer userId = Integer.valueOf(attribute.toString());
Teacher byId = teacherService.getById(userId);
byId.setPassword(password);
teacherService.updateById(byId);
j.put("res", 1);
return j.toString();
}
}