源码获取:俺的博客首页 "资源" 里下载!
项目介绍
本项目为前后端分离的项目;
系统分为管理员、老师、学生等三种角色
管理员:学生管理、教师管理、课程管理、开课表管理、学生成绩管理
教师:教师信息编辑、课程设置、教师成绩管理
学生:学生信息编辑、选课管理、学生成绩管理
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 前端推荐使用vscode;
3.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
4.数据库:MySql 5.7/8.0版本均可;
5.是否Maven项目:是;
6.是否为前后端分离项目:是;
技术栈
后端框架:Springboot
前端技术:ElementUI、Vue、nodejs
使用说明
后端项目运行:
1. 使用Navicat或者其它工具,在mysql中创建对应sql文件名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入源码中的student_server项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 运行项目,控制台提示运行成功后再去运行前端项目;
前端项目运行:
1.打开运行中的cmd;
2.cd到student_client文件夹目录;
3.执行命令:npm run serve
4. 运行成功后,在浏览器中输入地址:http://localhost:8080/
管理员:666/123456
学生:23/123456
老师:14/123456
登录页面展示:
成绩查询展示:
用户信息展示:
查询课程展示:
编辑学生信息展示:
我开设的课程页面展示:
选课页面展示:
成绩管理页面展示:
开设课程页面展示:
学生列表页面展示:
用户管理控制层:
@Controller
@RequestMapping("admin/system/user")
public class UserController {
@Autowired
UserService userService;
@Autowired
RoleService roleService;
@Autowired
UploadService uploadService;
@RequestMapping("list")
@SysLog("跳转系统用户列表页面")
public String list(){
return "admin/user/list";
}
@RequiresPermissions("sys:user:list")
@PostMapping("list")
@ResponseBody
public PageData<User> list(@RequestParam(value = "page",defaultValue = "1")Integer page,
@RequestParam(value = "limit",defaultValue = "10")Integer limit,
ServletRequest request){
Map map = WebUtils.getParametersStartingWith(request, "s_");
PageData<User> userPageData = new PageData<>();
QueryWrapper<User> userWrapper = new QueryWrapper<>();
if(!map.isEmpty()){
String type = (String) map.get("type");
if(StringUtils.isNotBlank(type)) {
userWrapper.eq("is_admin", "admin".equals(type) ? true : false);
}
String keys = (String) map.get("key");
if(StringUtils.isNotBlank(keys)) {
userWrapper.and(wrapper -> wrapper.like("login_name", keys).or().like("tel", keys).or().like("email", keys));
}
}
IPage<User> userPage = userService.page(new Page<>(page,limit),userWrapper);
userPageData.setCount(userPage.getTotal());
userPageData.setData(userPage.getRecords());
return userPageData;
}
@RequestMapping("add")
public String add(ModelMap modelMap){
List<Role> roleList = roleService.selectAll();
modelMap.put("roleList",roleList);
return "admin/user/add";
}
@RequiresPermissions("sys:user:add")
@PostMapping("add")
@ResponseBody
@SysLog("保存新增系统用户数据")
public ResponseEntity add(@RequestBody User user){
if(StringUtils.isBlank(user.getLoginName())){
return ResponseEntity.failure("登录名不能为空");
}
if(user.getRoleLists() == null || user.getRoleLists().size() == 0){
return ResponseEntity.failure("用户角色至少选择一个");
}
if(userService.userCount(user.getLoginName())>0){
return ResponseEntity.failure("登录名称已经存在");
}
// if(StringUtils.isNotBlank(user.getEmail())){
// if(userService.userCount(user.getEmail())>0){
// return ResponseEntity.failure("该邮箱已被使用");
// }
// }
// if(StringUtils.isNoneBlank(user.getTel())){
// if(userService.userCount(user.getTel())>0){
// return ResponseEntity.failure("该手机号已被绑定");
// }
// }
//设置默认密码
if(StringUtils.isBlank(user.getPassword())){
user.setPassword(Constants.DEFAULT_PASSWORD);
}
userService.saveUser(user);
if(StringUtils.isBlank(user.getId())){
return ResponseEntity.failure("保存用户信息出错");
}
//保存用户角色关系
userService.saveUserRoles(user.getId(),user.getRoleLists());
return ResponseEntity.success("操作成功");
}
@RequestMapping("edit")
public String edit(String id,ModelMap modelMap){
User user = userService.findUserById(id);
String roleIds = "";
if(user != null) {
roleIds = user.getRoleLists().stream().map(role -> role.getId()).collect(Collectors.joining(","));
}
List<Role> roleList = roleService.selectAll();
modelMap.put("localuser",user);
modelMap.put("roleIds",roleIds);
modelMap.put("roleList",roleList);
return "admin/user/edit";
}
@RequiresPermissions("sys:user:edit")
@PostMapping("edit")
@ResponseBody
@SysLog("保存系统用户编辑数据")
public ResponseEntity edit(@RequestBody User user){
if(StringUtils.isBlank(user.getId())){
return ResponseEntity.failure("用户ID不能为空");
}
if(StringUtils.isBlank(user.getLoginName())){
return ResponseEntity.failure("登录名不能为空");
}
if(user.getRoleLists() == null || user.getRoleLists().size() == 0){
return ResponseEntity.failure("用户角色至少选择一个");
}
User oldUser = userService.findUserById(user.getId());
if(StringUtils.isNotBlank(user.getEmail())){
if(!user.getEmail().equals(oldUser.getEmail())){
if(userService.userCount(user.getEmail())>0){
return ResponseEntity.failure("该邮箱已被使用");
}
}
}
if(StringUtils.isNotBlank(user.getLoginName())){
if(!user.getLoginName().equals(oldUser.getLoginName())) {
if (userService.userCount(user.getLoginName()) > 0) {
return ResponseEntity.failure("该登录名已存在");
}
}
}
if(StringUtils.isNotBlank(user.getTel())){
if(!user.getTel().equals(oldUser.getTel())) {
if (userService.userCount(user.getTel()) > 0) {
return ResponseEntity.failure("该手机号已经被绑定");
}
}
}
user.setIcon(oldUser.getIcon());
userService.updateUser(user);
if(StringUtils.isBlank(user.getId())){
return ResponseEntity.failure("保存用户信息出错");
}
userService.saveUserRoles(user.getId(),user.getRoleLists());
return ResponseEntity.success("操作成功");
}
@RequiresPermissions("sys:user:lock")
@PostMapping("lock")
@ResponseBody
@SysLog("锁定或开启系统用户")
public ResponseEntity lock(@RequestParam(value = "id",required = false)String id){
if(StringUtils.isBlank(id)){
return ResponseEntity.failure("参数错误");
}
User user = userService.getById(id);
if(user == null){
return ResponseEntity.failure("用户不存在");
}
userService.lockUser(user);
return ResponseEntity.success("操作成功");
}
@RequiresPermissions("sys:user:delete")
@PostMapping("delete")
@ResponseBody
@SysLog("删除系统用户数据(单个)")
public ResponseEntity delete(@RequestParam(value = "id",required = false)String id){
if(StringUtils.isBlank(id)){
return ResponseEntity.failure("参数错误");
}
User user = userService.getById(id);
if(user == null){
return ResponseEntity.failure("用户不存在");
}else if(user.getAdminUser()) {
return ResponseEntity.failure("不能删除后台用户");
}
userService.deleteUser(user);
return ResponseEntity.success("操作成功");
}
@RequiresPermissions("sys:user:delete")
@PostMapping("deleteSome")
@ResponseBody
@SysLog("删除系统用户数据(多个)")
public ResponseEntity deleteSome(@RequestBody List<User> users){
if(users == null || users.size()==0){
return ResponseEntity.failure("请选择需要删除的用户");
}
for (User u : users){
if(u.getAdminUser()){
return ResponseEntity.failure("不能删除超级管理员");
}else{
userService.deleteUser(u);
}
}
return ResponseEntity.success("操作成功");
}
@RequestMapping("userinfo")
public String toEditMyInfo(ModelMap modelMap){
String userId = MySysUser.id();
User user = userService.findUserById(userId);
modelMap.put("userinfo",user);
modelMap.put("userRole",user.getRoleLists());
return "admin/user/userInfo";
}
@SysLog("系统用户个人信息修改")
@PostMapping("saveUserinfo")
@ResponseBody
public ResponseEntity saveUserInfo(User user){
if(StringUtils.isBlank(user.getId())){
return ResponseEntity.failure("用户ID不能为空");
}
if(StringUtils.isBlank(user.getLoginName())){
return ResponseEntity.failure("登录名不能为空");
}
User oldUser = userService.findUserById(user.getId());
if(StringUtils.isNotBlank(user.getEmail())){
if(!user.getEmail().equals(oldUser.getEmail())){
if(userService.userCount(user.getEmail())>0){
return ResponseEntity.failure("该邮箱已被使用");
}
}
}
if(StringUtils.isNotBlank(user.getTel())){
if(!user.getTel().equals(oldUser.getTel())) {
if (userService.userCount(user.getTel()) > 0) {
return ResponseEntity.failure("该手机号已经被绑定");
}
}
}
userService.updateById(user);
return ResponseEntity.success("操作成功");
}
@RequestMapping("changePassword")
public String changePassword(ModelMap modelMap){
modelMap.put("currentUser",userService.getById(MySysUser.id()));
return "admin/user/changePassword";
}
@CrossOrigin
@SysLog("用户修改密码")
@PostMapping("changePassword")
@ResponseBody
public ResponseEntity changePassword(@RequestParam(value = "userName",required = false)String userName,
@RequestParam(value = "oldPwd",required = false)String oldPwd,
@RequestParam(value = "newPwd",required = false)String newPwd,
@RequestParam(value = "confirmPwd",required = false)String confirmPwd){
if(StringUtils.isBlank(oldPwd)){
return ResponseEntity.failure("旧密码不能为空");
}
if(StringUtils.isBlank(newPwd)){
return ResponseEntity.failure("新密码不能为空");
}
if(StringUtils.isBlank(confirmPwd)){
return ResponseEntity.failure("确认密码不能为空");
}
if(!confirmPwd.equals(newPwd)){
return ResponseEntity.failure("确认密码与新密码不一致");
}
//小程序修改密码
if(StringUtils.isBlank(userName)){
//PC修改密码
User user = userService.findUserById(MySysUser.id());
byte[] hashPassword = Encodes.sha1(oldPwd.getBytes(), Encodes.SHA1, Encodes.decodeHex(user.getSalt()), Constants.HASH_INTERATIONS);
String password = Encodes.encodeHex(hashPassword);
if(!user.getPassword().equals(password)){
return ResponseEntity.failure("旧密码错误");
}
user.setPassword(newPwd);
Encodes.entryptPassword(user);
userService.updateById(user);
return ResponseEntity.success("操作成功");
}else {
//小程序修改密码
User user = userService.findUserByLoginName(userName);
byte[] hashPassword = Encodes.sha1(oldPwd.getBytes(), Encodes.SHA1, Encodes.decodeHex(user.getSalt()), Constants.HASH_INTERATIONS);
String password = Encodes.encodeHex(hashPassword);
if(!user.getPassword().equals(password)){
return ResponseEntity.failure("旧密码错误");
}
user.setPassword(newPwd);
Encodes.entryptPassword(user);
userService.updateById(user);
return ResponseEntity.success("操作成功");
}
}
@SysLog("上传头像")
@PostMapping("uploadFace")
@ResponseBody
public ResponseEntity uploadFile(@RequestParam("icon") MultipartFile file, HttpServletRequest httpServletRequest) {
if(file == null){
return ResponseEntity.failure("上传文件为空 ");
}
String url = null;
Map map = new HashMap();
try {
url = uploadService.upload(file);
map.put("url", url);
map.put("name", file.getOriginalFilename());
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.failure(e.getMessage());
}
return ResponseEntity.success("操作成功").setAny("data",map);
}
}
学生管理控制层:
@Controller
public class StudentController extends BaseController {
@Autowired
private StudentService studentService;
// 跳转学生查询页面
@RequestMapping("/selectStudent")
public String selectStudent(){
return "view/student/selStudent";
}
// 查询所有学生
@RequestMapping("selStudent")
@ResponseBody
public LayuiResult<Map> selectStu(pageCount pageCount, StudentVO studentVO){
LayuiResult<Map> result = new LayuiResult<>();
List<Map> list = studentService.selStudent(studentVO,pageCount);
int count = studentService.selCount(studentVO);
result.setData(list);
result.setCount(count);
return result;
}
// 查询所有专业
@RequestMapping("selDepartment")
@ResponseBody
public LayuiResult<Map> selDepartment(){
List<DepartmentDB> selDepartment = studentService.selDepartment();
LayuiResult result = new LayuiResult();
result.setData(selDepartment);
return result;
}
// 根据系部查询专业
@RequestMapping("selectdid")
@ResponseBody
public LayuiResult<Map> selMajorDB(Integer did){
List<MajorDB> major =studentService.selMajorDB(did);
LayuiResult result = new LayuiResult();
result.setData(major);
return result;
}
// 根据专业查询年级
@RequestMapping("selectmid")
@ResponseBody
public LayuiResult<Map> selGradeDB(Integer mid){
List<GradeDB> grade = studentService.selGradeDB(mid);
LayuiResult result = new LayuiResult();
result.setData(grade);
return result;
}
// 根据年级查询班级
@RequestMapping("selectgid")
@ResponseBody
public LayuiResult<Map> selClassinfoDB(Integer gid){
List<ClassinfoDB> classinfo = studentService.selClassinfoDB(gid);
LayuiResult result = new LayuiResult();
result.setData(classinfo);
return result;
}
// 根据id查询一条学生信息以此进行修改
@RequestMapping("/selStudentId")
public String selStudentId(Integer id, Model model){
// 查询学生信息
List<StudentDB> stu = studentService.selStudentId(id);
// 查询班级
List<ClassinfoDB> cls = studentService.selClass();
// 查询政治面貌表
List<PoliticsTypeDB> stupol = studentService.selPolitics();
model.addAttribute("stu",stu);
model.addAttribute("cls",cls);
model.addAttribute("stupol",stupol);
return "view/student/updStudent";
}
// 根据id查询显示学生详细信息
@RequestMapping("/selectMessage")
public String selectMessage(Integer id, Model model){
// 查询学生信息
List<StudentDB> stu = studentService.selStudentId(id);
// 查询班级
List<ClassinfoDB> cls = studentService.selClass();
// 查询政治面貌表
List<PoliticsTypeDB> stupol = studentService.selPolitics();
model.addAttribute("stu",stu);
model.addAttribute("cls",cls);
model.addAttribute("stupol",stupol);
return "view/student/selStuExam";
}
// 修改用户信息
@RequestMapping("/updateStudent")
@ResponseBody
public LayuiResult<StudentDB> updateStudent(StudentDB studentDB, String birthday) throws Exception{
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date=format.parse(birthday);
studentDB.setSbirthday(date);
studentService.updateStudent(studentDB);
LayuiResult result= new LayuiResult();
//删除提示
result.setMsg("修改成功!");
return result;
}
}
课程管理控制层:
@Controller
public class SelCourseManController {
@Autowired
private SelCourseManageService selCourseManageService;
@RequestMapping("selCourses")
public String selCourses(){
System.out.println("----------------------");
return "SelCourseMan";
}
@RequestMapping("selSc")
@ResponseBody
public Object selSc(Integer page, Integer limit, StuCourseVO stuCourseVO){
System.out.println(stuCourseVO.getSname());
PageHelper.startPage(page, limit);
List<StuCourseVO> stuCourseVOS = selCourseManageService.selSc(stuCourseVO);
PageInfo pageInfo = new PageInfo(stuCourseVOS);
Map<String, Object> tableData = new HashMap<String, Object>();
//这是layui要求返回的json数据格式
tableData.put("code", 0);
tableData.put("msg", "");
//将全部数据的条数作为count传给前台(一共多少条)
tableData.put("count", pageInfo.getTotal());
//将分页后的数据返回(每页要显示的数据)
tableData.put("data", pageInfo.getList());
// System.out.print(cs);
return tableData;
}
//下面是下拉框
@RequestMapping("selDe")
@ResponseBody
public Object selDe(){
List<DepartmentDB> departmentDBS = selCourseManageService.selDe();
//System.out.println(departmentDBS);
return departmentDBS;
}
@RequestMapping("selMa")
@ResponseBody
public Object selMa(Integer did){
//System.out.println(did);
List<MajorDB> majors = selCourseManageService.selMa(did);
//System.out.println(majors);
return majors;
}
@RequestMapping("selGr")
@ResponseBody
public Object selGr(Integer mid){
//System.out.println(mid);
List<GradeDB> gradeDBS = selCourseManageService.selGr(mid);
// System.out.println(gradeDBS);
return gradeDBS;
}
@RequestMapping("selCl")
@ResponseBody
public Object selCl(Integer gid){
// System.out.println(gid);
List<ClassinfoDB> classinfoDBS = selCourseManageService.selClass(gid);
// System.out.println(classinfoDBS);
return classinfoDBS;
}
@RequestMapping("selSt")
@ResponseBody
public Object selSt(Integer classid){
//System.out.println(classid);
List<StudentDB> studentDBS = selCourseManageService.selSt(classid);
// System.out.println(studentDBS);
return studentDBS;
}
@RequestMapping("selCo")
@ResponseBody
public Object selCo(){
//System.out.println(classid);
List<CourseDB> courseDBS = selCourseManageService.selCo();
// System.out.println(studentDBS);
return courseDBS;
}
//退课
@RequestMapping("dropCous")
@ResponseBody
public Object dropCous(Integer sid,Integer cid){
int dropcou = selCourseManageService.dropcou(sid, cid);
int updatecou = selCourseManageService.updatecou(cid);
if(dropcou>0 && updatecou>0){
return "退课成功";
}else{
return "退课失败,请稍后再试或联系管理员";
}
}
//换课
@RequestMapping("changesCou")
@ResponseBody
public Object changesCou( Integer ccd, Integer sid,Integer cid) {
/*System.out.println(ccd+"8888888");
System.out.println(sid+"-----"+cid);*/
int i = selCourseManageService.selStc(ccd, sid);
if (i > 0) {
return "该学生已经选过这门课";
} else {
int dropcou = selCourseManageService.changesCou(ccd, sid, cid);
if (dropcou > 0) {
return "换课成功";
} else {
return "退课失败,请稍后再试或联系管理员";
}
}
}
}
源码获取:俺的博客首页 "资源" 里下载!