基于javaweb+mysql的springboot在线考试平台(java+springboot+ssm+mysql+maven+thymeleaf+html+redis)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot在线考试平台(java+springboot+ssm+mysql+maven+thymeleaf+html+redis)
一、项目简述
功能列表 考试前台 /系统登录:学生、教师、管理员登录 /门户首页:无需认证访问 /在线考试:需认证即可查看当前考除目 /题库中心:需认证查看题库 /成绩查询:需认证查询成绩 /留言板:需认证留言 管理后台 /考:署理:发布考试,考试列表,课程管理,题库管 理,成绩管理,成绩情况 /权限管理:学院管理,班级管理,用户管理,角色管 理,资源管理 4网站管理:基础信息,友链管理,评论管理,标签管理 /系统管理:在线用户 /上传管理:云存储配置 /运维管理:数据监控
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP +SpringBoot + MyBatis + Redis+ Thymeleaf+ Druid+ JQuery + SLF4J+ Fileupload + maven等等
@Controller
public class ExamWebController {
@Autowired
private ExaminationService examService;
@Autowired
private GradeService gradeService;
@Autowired
private QuestionService questionService;
@Autowired
private SubjectService subjectService;
@Autowired
private CommentService commentService;
@Autowired
private LoveService loveService;
@Autowired
private UserService userService;
@Autowired
private ClassesService classesService;
@Autowired
private ShiroRealm shiroRealm;
/**
* 考试界面
* @param model
* @param examConditionVo
List<String> grades = userService.selectGradeList();
model.addAttribute("user", user);
model.addAttribute("classes", classes);
model.addAttribute("grades", grades);
return "user/userDetail";
}
/**编辑用户*/
@PostMapping("/edit")
@ResponseBody
public ResponseVo editUser(User userFrom){
int a = userService.updateByUserId(userFrom);
if (a > 0) {
return ResultUtil.success("编辑用户成功!");
} else {
return ResultUtil.error("编辑用户失败");
}
}
/**
* 禁用用户
* @param userId
* @return
*/
@PostMapping("/ban")
@ResponseBody
public ResponseVo banUser(String userId) {
List<String> userIdsList = Arrays.asList(userId);
int a = userService.updateStatusBatch(userIdsList,CoreConst.STATUS_INVALID);
if(a > 0) {
return ResultUtil.success("禁用用户成功");
}else {
return ResultUtil.error("禁用用户失败");
}
}
/**批量禁用用户*/
@PostMapping("/batch/ban")
@ResponseBody
public ResponseVo batchBanUser(String userIdStr) {
String[] userIds = userIdStr.split(",");
@GetMapping("/institutes")
public String instituteList() {
return "institute/list";
}
/*班级管理入口*/
@GetMapping("/classes")
public String classesList(Model model) {
List<Institute> institutes = instituteService.selectAll();
model.addAttribute("institutes",institutes);
return "classes/list";
}
/*权限列表入口*/
@GetMapping("/permissions")
public String permissionList(){
return "permission/list";
}
/*在线用户入口*/
@GetMapping("/online/users")
public String onlineUsers(){
return "onlineUsers/list";
}
}
package com.exam.controller;
subject.setAuthor(user.getNickname());
Date date = new Date();
subject.setCreateTime(date);
subject.setUpdateTime(date);
subject.setStatus(0);
int i = subjectService.insert(subject);
if(i > 0) {
return ResultUtil.success("新增课目成功!");
}else {
return ResultUtil.error("新增课目失败!");
}
}
/**
* 编辑课程信息
* @param model
* @param id
* @return
*/
@GetMapping("/edit")
public String edit(Model model, Integer id) {
Subject subject = subjectService.selectById(id);
model.addAttribute("subject", subject);
return "subject/detail";
}
@PostMapping("/edit")
@ResponseBody
public ResponseVo edit(Subject subject) {
subject.setUpdateTime(new Date());
int i = subjectService.updateNotNull(subject);
if( i > 0) {
return ResultUtil.success("编辑课目成功!");
}else {
return ResultUtil.error("编辑课目失败!");
}
}
/**
* 删除课目
/*登出*/
@RequestMapping(value = "/logout")
@ResponseBody
public ResponseVo logout() {
Subject subject = SecurityUtils.getSubject();
if(null!=subject){
String username = ((User) SecurityUtils.getSubject().getPrincipal()).getUsername();
Serializable sessionId = SecurityUtils.getSubject().getSession().getId();
Cache<String, Deque<Serializable>> cache = redisCacheManager.getCache(redisCacheManager.getKeyPrefix()+username);
Deque<Serializable> deques = cache.get(username);
for(Serializable deque : deques){
if(sessionId.equals(deque)){
deques.remove(deque);
break;
}
}
cache.put(username,deques);
}
subject.logout();
return ResultUtil.success("退出成功");
}
/*获取当前登录用户的菜单*/
@PostMapping("/menu")
@ResponseBody
public List<Permission> getMenus(){
List<Permission> permissionListList = permissionService.selectMenuByUserId(((User) SecurityUtils.getSubject().getPrincipal()).getUserId());
return permissionListList;
}
}
package com.exam.controller;
List<Subject> subjects = subjectService.select(subject);
model.addAttribute("subjects", subjects);
return "question/list";
}
/*成绩*/
@GetMapping("/grades")
public String Grade(Model model) {
List<String> grades = userService.selectGradeList();
List<Institute> institutes = instituteService.selectAll();
List<Classes> classes = classesService.selectAll();
List<Subject> subjects = subjectService.selectAll();
model.addAttribute("grades", grades);
model.addAttribute("institutes", institutes);
model.addAttribute("classes", classes);
model.addAttribute("subjects", subjects);
return "grade/list";
}
/**
* 成绩统计
* @param model
* @return
*/
@GetMapping("/datas")
public String data(Model model) {
List<Examination> examList = examService.selectAllByStatus(CoreConst.STATUS_INVALID);
List<String> grades = userService.selectGradeList();
List<Institute> institutes = instituteService.selectAll();
List<Classes> classes = classesService.selectAll();
List<Subject> subjects = subjectService.selectAll();
model.addAttribute("exams", examList);
model.addAttribute("grades", grades);
model.addAttribute("institutes", institutes);
model.addAttribute("classes", classes);
model.addAttribute("subjects", subjects);
return "statistics/list";
}
/*评论*/
@GetMapping("/comments")
public String comments(){
return "comment/list";
}
}
package com.exam.controller;
}else {
return ResultUtil.error("批量删除题目失败");
}
}
}
package com.exam.controller;
@Controller
@RequestMapping("institute")
public class InstituteController {
@Autowired
private InstituteService instituteService;
@PostMapping("list")
@ResponseBody
public PageResultVo loadInstitute(Institute institute, Integer limit, Integer offset) {
PageHelper.startPage(PageUtil.getPageNo(limit, offset),limit);
List<Institute> instituteList = instituteService.selectInstitutes(institute);
PageInfo<Institute> pages = new PageInfo<>(instituteList);
return ResultUtil.table(instituteList, pages.getTotal(), pages);
}
/**
* 新增学院
* @param institute
* @return
@PostMapping("/batch/assign/role")
@ResponseBody
public ResponseVo batchAssignRole(String userIdStr, String roleIdStr){
String[] userIds = userIdStr.split(",");
List<String> userIdList = Arrays.asList(userIds);
String[] roleIds = roleIdStr.split(",");
List<String> roleIdsList = Arrays.asList(roleIds);
ResponseVo responseVo = userService.addAssignRole(userIdList,roleIdsList);
shiroRealm.clearAuthorizationByUserId(userIdList);
return responseVo;
}
/*修改密码*/
@RequestMapping(value = "/changePassword",method = RequestMethod.POST)
@ResponseBody
public ResponseVo changePassword(ChangePasswordVo changePasswordVo) {
if(!changePasswordVo.getNewPassword().equals(changePasswordVo.getConfirmNewPassword())){
return ResultUtil.error("两次密码输入不一致");
}
User loginUser = userService.selectByUserId(((User) SecurityUtils.getSubject().getPrincipal()).getUserId());
User newUser = CopyUtil.getCopy(loginUser,User.class);
String sysOldPassword = loginUser.getPassword();
newUser.setPassword(changePasswordVo.getOldPassword());
String entryOldPassword = PasswordHelper.getPassword(newUser);
if(sysOldPassword.equals(entryOldPassword)){
newUser.setPassword(changePasswordVo.getNewPassword());
PasswordHelper.encryptPassword(newUser);
userService.updateUserByPrimaryKey(newUser);
//*清除登录缓存*//
List<String> userIds = new ArrayList<>();
userIds.add(loginUser.getUserId());
shiroRealm.removeCachedAuthenticationInfo(userIds);
/*SecurityUtils.getSubject().logout();*/
}else{
return ResultUtil.error("您输入的旧密码有误");
}
return ResultUtil.success("修改密码成功");
}
}
package com.exam.controller;
public ResponseVo add(Subject subject) {
User user = (User)SecurityUtils.getSubject().getPrincipal();
subject.setUserId(user.getUserId());
subject.setAuthor(user.getNickname());
Date date = new Date();
subject.setCreateTime(date);
subject.setUpdateTime(date);
subject.setStatus(0);
int i = subjectService.insert(subject);
if(i > 0) {
return ResultUtil.success("新增课目成功!");
}else {
return ResultUtil.error("新增课目失败!");
}
}
/**
* 编辑课程信息
* @param model
* @param id
* @return
*/
@GetMapping("/edit")
public String edit(Model model, Integer id) {
Subject subject = subjectService.selectById(id);
model.addAttribute("subject", subject);
return "subject/detail";
}
@PostMapping("/edit")
@ResponseBody
public ResponseVo edit(Subject subject) {
subject.setUpdateTime(new Date());
int i = subjectService.updateNotNull(subject);
if( i > 0) {
return ResultUtil.success("编辑课目成功!");
}else {
return ResultUtil.error("编辑课目失败!");
}
}
/**
@PostMapping("/delete")
@ResponseBody
public ResponseVo delete(Integer id) {
int i = examService.deleteBatch(new Integer[] {id});
int j = examQuestionService.deleteBatch(new Integer[] {id});
if(i > 0 && j > 0) {
return ResultUtil.success("删除考试成功");
}else {
return ResultUtil.error("删除考试失败");
}
}
@PostMapping("/batch/delete")
@ResponseBody
public ResponseVo deleteBatch(@RequestParam("ids[]") Integer[] ids) {
int i = examService.deleteBatch(ids);
int j = examQuestionService.deleteBatch(ids);
if(i > 0 && j > 0) {
return ResultUtil.success("批量删除成功");
}else {
return ResultUtil.error("批量删除失败");
}
}
}
package com.exam.controller;
//腾讯云对象存储
@ResponseBody
@PostMapping(value = "/upload")
public UploadResponse upload(@RequestParam(value = "file", required = false) MultipartFile file) throws Exception {
if(file == null || file.isEmpty()) {
throw new UploadFileNotFoundException(UploadResponse.Error.FILENOTFOUND);
}
try {
String originalFileName = file.getOriginalFilename();
String suffix = originalFileName.substring(originalFileName.lastIndexOf(".")).toLowerCase();
String value = sysConfigService.selectAll().get(SysConfigKey.CLOUD_STORAGE_CONFIG.getValue());
Gson gson = new Gson();
CloudStorageConfigVo cloudStorageConfig = gson.fromJson(value, CloudStorageConfigVo.class);
String dir = cloudStorageConfig.getQcloudPrefix();
String md5 = MD5.getMessageDigest(file.getBytes());
String filePath = String.format("%1$s/%2$s%3$s", dir, md5, suffix);
ResponseVo responseVo = QCloudUtil.writeFile(cloudStorageConfig, filePath, file);
String qCloudDomain = cloudStorageConfig.getQcloudDomain();
String url = String.format("%1$s/%2$s", qCloudDomain, filePath);
if(responseVo.getStatus().equals(CoreConst.SUCCESS_CODE)){
return new UploadResponse(url,originalFileName, suffix, url, CoreConst.SUCCESS_CODE);
}else{
return new UploadResponse(originalFileName, CoreConst.FAIL_CODE,responseVo.getMsg());
}
} catch (Exception e) {
logger.error(String.format("UploadController.upload%s", e));
throw e;
}
}
//上传到七牛云图床
/*@ResponseBody
@PostMapping(value = "/upload")
public UploadResponse upload(@RequestParam(value = "file", required = false) MultipartFile file) throws Exception{
if (file == null || file.isEmpty()) {
throw new UploadFileNotFoundException(UploadResponse.Error.FILENOTFOUND);
}
try {
String originalFilename = file.getOriginalFilename();
String suffix = originalFilename.substring(originalFilename.lastIndexOf(".")).toLowerCase();
String value = sysConfigService.selectAll().get(SysConfigKey.CLOUD_STORAGE_CONFIG.getValue());
Gson gson = new Gson();
CloudStorageConfigVo cloudStorageConfig = gson.fromJson(value,CloudStorageConfigVo.class);
String dir =cloudStorageConfig.getQiniuPrefix();
String md5 = MD5.getMessageDigest(file.getBytes());
String filePath = String.format("%1$s/%2$s%3$s", dir, md5, suffix);
@ResponseBody
public ResponseVo deleteRole(String roleId) {
if(roleService.findByRoleId(roleId).size()>0){
return ResultUtil.error("删除失败,该角色下存在用户");
}
List<String> roleIdsList = Arrays.asList(roleId);
int a = roleService.updateStatusBatch(roleIdsList, CoreConst.STATUS_INVALID);
if (a > 0) {
return ResultUtil.success("删除角色成功");
} else {
return ResultUtil.error("删除角色失败");
}
}
/*批量删除角色*/
@GetMapping("/batch/delete")
@ResponseBody
public ResponseVo batchDeleteRole(String roleIdStr) {
String[] roleIds = roleIdStr.split(",");
List<String> roleIdsList = Arrays.asList(roleIds);
if(roleService.findByRoleIds(roleIdsList).size()>0){
return ResultUtil.error("删除失败,选择的角色下存在用户");
}
int a = roleService.updateStatusBatch(roleIdsList,CoreConst.STATUS_INVALID);
if (a > 0) {
return ResultUtil.success("删除角色成功");
} else {
return ResultUtil.error("删除角色失败");
}
}
/*编辑角色详情*/
@GetMapping("/edit")
public String detail(Model model, Integer id) {
Role role = roleService.findById(id);
model.addAttribute("role", role);
return "role/detail";
}
/*编辑角色*/
@Controller
@RequestMapping("exam")
public class ExaminationController {
@Autowired
private ExaminationService examService;
@Autowired
private SubjectService subjectService;
@Controller
@RequestMapping("institute")
public class InstituteController {
@Autowired
private InstituteService instituteService;
@PostMapping("list")
@ResponseBody
public PageResultVo loadInstitute(Institute institute, Integer limit, Integer offset) {
PageHelper.startPage(PageUtil.getPageNo(limit, offset),limit);
List<Institute> instituteList = instituteService.selectInstitutes(institute);
PageInfo<Institute> pages = new PageInfo<>(instituteList);
return ResultUtil.table(instituteList, pages.getTotal(), pages);
}
/**
* 新增学院
* @param institute
* @return
*/
@PostMapping("/add")
@ResponseBody
public ResponseVo add(Institute institute) {
User user = (User)SecurityUtils.getSubject().getPrincipal();
institute.setAuthor(user.getNickname());
Date date = new Date();
institute.setCreateTime(date);
institute.setUpdateTime(date);
institute.setStatus(CoreConst.STATUS_INVALID);
int i = instituteService.insert(institute);
if(i > 0) {
return ResultUtil.success("新增学院成功");
}else {
return ResultUtil.error("新增学院失败");
* @param userIds 已经修改了权限的userId
*/
public void clearAuthorizationByUserId(List<String> userIds){
if(null == userIds || userIds.size() == 0) {
return ;
}
List<SimplePrincipalCollection> list = getSpcListByUserIds(userIds);
RealmSecurityManager securityManager =
(RealmSecurityManager) SecurityUtils.getSecurityManager();
ShiroRealm realm = (ShiroRealm)securityManager.getRealms().iterator().next();
for (SimplePrincipalCollection simplePrincipalCollection : list) {
realm.clearCachedAuthorizationInfo(simplePrincipalCollection);
}
}
/**
* 根据用户id获取所有spc
* @param userIds 已经修改了权限的userId
*/
private List<SimplePrincipalCollection> getSpcListByUserIds(List<String> userIds){
//获取所有session
Collection<Session> sessions = redisSessionDAO.getActiveSessions();
//定义返回
List<SimplePrincipalCollection> list = new ArrayList<SimplePrincipalCollection>();
for (Session session:sessions){
//获取session登录信息。
Object obj = session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY);
if(null != obj && obj instanceof SimplePrincipalCollection){
//强转
SimplePrincipalCollection spc = (SimplePrincipalCollection)obj;
//判断用户,匹配用户ID。
obj = spc.getPrimaryPrincipal();
if(null != obj && obj instanceof User){
User user = (User) obj;
System.out.println("user:"+user);
//比较用户ID,符合即加入集合
if(null != user && userIds.contains(user.getUserId())){
list.add(spc);
}
}
}
}
return list;
}
public class ShiroRealm extends AuthorizingRealm {
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
@Autowired
private PermissionService permissionService;
@Autowired
private RedisSessionDAO redisSessionDAO;
//授权
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
if(principals == null){
throw new AuthorizationException("principals should not be null");
}
User user = (User) principals.getPrimaryPrincipal();
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.setRoles(roleService.findRoleByUserId(user.getUserId()));
info.setStringPermissions(permissionService.findPermsByUserId(user.getUserId()));
return info;
}
@Controller
public class AdminRenderController {
@Autowired
private SysConfigService sysConfigService;
@Autowired
private SubjectService subjectService;
@Autowired
private InstituteService instituteService;
@Autowired
private ClassesService classesService;
@Autowired
private UserService userService;
@Autowired
private ExaminationService examService;
/*网站基本信息*/
@GetMapping("/siteinfo")
public String siteinfo(Model model){
Map<String, String> map = sysConfigService.selectAll();
model.addAttribute("siteinfo", map);
return "site/siteinfo";
}
/*友情链接*/
@GetMapping("/links")
public String links(){
return "link/list";
}
/*课程*/
@GetMapping("/subjects")
public String subjects() {
return "subject/list";
}
/*标签*/
@GetMapping("/tags")
public String tags(){
return "tag/list";
}
/*考试*/
@GetMapping("/exams")
public String exams(Model model) {
@Controller
public class ExamWebController {
@Autowired
private ExaminationService examService;
@Autowired
private GradeService gradeService;
@Autowired
private QuestionService questionService;
@Autowired
private SubjectService subjectService;
@Autowired
private CommentService commentService;
@Autowired
private LoveService loveService;
@Autowired
private UserService userService;
@Autowired
private ClassesService classesService;
@Autowired
private ShiroRealm shiroRealm;
/**
* 考试界面
* @param model
* @param examConditionVo
* @return
*/
@GetMapping("/exam/examination")
}
/**批量启用用户*/
@PostMapping("/batch/enable")
@ResponseBody
public ResponseVo batchEnableUser(String userIdStr) {
String[] userIds = userIdStr.split(",");
List<String> userIdsList = Arrays.asList(userIds);
int a = userService.updateStatusBatch(userIdsList,CoreConst.STATUS_VALID);
if (a > 0) {
return ResultUtil.success("批量启用用户成功");
} else {
return ResultUtil.error("批量启用用户失败");
}
}
/**删除用户*/
@PostMapping("/delete")
@ResponseBody
public ResponseVo deleteUser(String userId) {
List<String> userIdsList = Arrays.asList(userId);
int a = userService.deleteBatch(userIdsList);
if (a > 0) {
return ResultUtil.success("删除用户成功");
} else {
return ResultUtil.error("删除用户失败");
}
}
/**批量删除用户*/
@PostMapping("/batch/delete")
@ResponseBody
public ResponseVo batchDeleteUser(String userIdStr) {
String[] userIds = userIdStr.split(",");
List<String> userIdsList = Arrays.asList(userIds);
int a = userService.deleteBatch(userIdsList);
if (a > 0) {
return ResultUtil.success("批量删除用户成功");
} else {
return ResultUtil.error("批量删除用户失败");
}
public ResponseVo batchDeleteUser(String userIdStr) {
String[] userIds = userIdStr.split(",");
List<String> userIdsList = Arrays.asList(userIds);
int a = userService.deleteBatch(userIdsList);
if (a > 0) {
return ResultUtil.success("批量删除用户成功");
} else {
return ResultUtil.error("批量删除用户失败");
}
}
/**分配角色列表查询*/
@PostMapping("/assign/role/list")
@ResponseBody
public Map<String,Object> assignRoleList(String userId){
List<Role> roleList = roleService.selectRoles(new Role());
Set<String> hasRoles = roleService.findRoleByUserId(userId);
Map<String, Object> jsonMap = new HashMap<>(2);
jsonMap.put("rows", roleList);
jsonMap.put("hasRoles",hasRoles);
return jsonMap;
}
/**保存分配角色*/
@PostMapping("/assign/role")
@ResponseBody
public ResponseVo assignRole(String userId, String roleIdStr){
List<String> userIdList = new ArrayList<>();
userIdList.add(userId);
String[] roleIds = roleIdStr.split(",");
List<String> roleIdsList = Arrays.asList(roleIds);
ResponseVo responseVo = userService.addAssignRole(userIdList,roleIdsList);
shiroRealm.clearAuthorizationByUserId(userIdList);
return responseVo;
}
/**批量分配角色列表查询*/
@PostMapping("/batch/assign/role/list")
@ResponseBody
public Map<String,Object> batchAssignRoleList(String userId){
List<Role> roleList = roleService.selectRoles(new Role());
Set<String> hasRoles = roleService.findRoleByUserId(userId);
Map<String, Object> jsonMap = new HashMap<>(2);
jsonMap.put("rows", roleList);
jsonMap.put("hasRoles",hasRoles);
/*标签*/
@GetMapping("/tags")
public String tags(){
return "tag/list";
}
/*考试*/
@GetMapping("/exams")
public String exams(Model model) {
Subject subject = new Subject();
subject.setStatus(CoreConst.STATUS_INVALID);
List<Subject> subjects = subjectService.select(subject);
List<Institute> institutes = instituteService.selectAll();
List<Classes> classes = classesService.selectAll();
List<String> grades = userService.selectGradeList();
model.addAttribute("subjects", subjects);
model.addAttribute("institutes", institutes);
model.addAttribute("classes", classes);
model.addAttribute("grades", grades);
return "exam/list";
}
/*题目*/
@GetMapping("/questions")
public String questions(Model model) {
Subject subject = new Subject();
subject.setStatus(CoreConst.STATUS_INVALID);
List<Subject> subjects = subjectService.select(subject);
model.addAttribute("subjects", subjects);
return "question/list";
}
/*成绩*/
@GetMapping("/grades")
public String Grade(Model model) {
List<String> grades = userService.selectGradeList();
List<Institute> institutes = instituteService.selectAll();
List<Classes> classes = classesService.selectAll();
List<Subject> subjects = subjectService.selectAll();
model.addAttribute("grades", grades);
model.addAttribute("institutes", institutes);
model.addAttribute("classes", classes);
List<Classes> classes = classesService.selectAll();
List<String> grades = userService.selectGradeList();
model.addAttribute("user", user);
model.addAttribute("classes", classes);
model.addAttribute("grades", grades);
return "user/userDetail";
}
/**编辑用户*/
@PostMapping("/edit")
@ResponseBody
public ResponseVo editUser(User userFrom){
int a = userService.updateByUserId(userFrom);
if (a > 0) {
return ResultUtil.success("编辑用户成功!");
} else {
return ResultUtil.error("编辑用户失败");
}
}
/**
* 禁用用户
* @param userId
* @return
*/
@PostMapping("/ban")
@ResponseBody
public ResponseVo banUser(String userId) {
List<String> userIdsList = Arrays.asList(userId);
int a = userService.updateStatusBatch(userIdsList,CoreConst.STATUS_INVALID);
if(a > 0) {
return ResultUtil.success("禁用用户成功");
}else {
return ResultUtil.error("禁用用户失败");
}
}
/**批量禁用用户*/
@PostMapping("/batch/ban")
@ResponseBody
public ResponseVo batchBanUser(String userIdStr) {
String[] userIds = userIdStr.split(",");
List<String> userIdsList = Arrays.asList(userIds);
int a = userService.updateStatusBatch(userIdsList,CoreConst.STATUS_INVALID);
if (a > 0) {
return ResultUtil.success("批量禁用用户成功");
} else {
return ResultUtil.error("批量禁用用户失败");
}
}
/**
return ResultUtil.success("新增班级信息成功");
}else {
return ResultUtil.error("新增班级信息失败");
}
}
/**
* 更新班级信息
* @param model
* @param id
* @return
*/
@GetMapping("/edit")
public String edit(Model model,Integer id) {
Classes classes = classesService.selectById(id);
List<Institute> institutes = instituteService.selectAll();
model.addAttribute("institutes",institutes);
model.addAttribute("classes", classes);
return "classes/detail";
}
@PostMapping("/edit")
@ResponseBody
public ResponseVo edit(Classes classes) {
int i = classesService.updateNotNull(classes);
if(i > 0) {
return ResultUtil.success("更新班级信息成功");
}else {
return ResultUtil.error("更新班级信息失败");
}
}
/**
* 删除班级信息
* @param id
* @return
*/
@PostMapping("/delete")
@ResponseBody
public ResponseVo delete(Integer id) {
//验证班级下是否有学生
int i = classesService.validateByClassIds(new Integer[] {id});
List<String> permissionIdsList = new ArrayList<>();
if(StringUtils.isNotBlank(permissionIdStr)){
String[] permissionIds = permissionIdStr.split(",");
permissionIdsList = Arrays.asList(permissionIds);
}
ResponseVo responseVo = roleService.addAssignPermission(roleId,permissionIdsList);
/*重新加载角色下所有用户权限*/
List<User> userList = roleService.findByRoleId(roleId);
if(userList.size()>0){
List<String> userIds = new ArrayList<>();
for(User user : userList){
userIds.add(user.getUserId());
}
shiroRealm.clearAuthorizationByUserId(userIds);
}
return responseVo;
}
}
package com.exam.shiro;
return ResultUtil.error("该学号已存在");
}
if(passwordType == 0) {
String password = userForm.getPassword();
//判断两次输入密码是否相等
if (confirmPassword != null && password != null) {
if (!confirmPassword.equals(password)) {
return ResultUtil.error("两次密码不一致");
}
}
}else {
userForm.setPassword(CoreConst.DEFAULT_PASSWORD);
}
userForm.setUserId(UUIDUtil.getUniqueIdByUUId());
userForm.setImg(CoreConst.DEFAULT_IMG);
userForm.setStatus(CoreConst.STATUS_VALID);
Date date = new Date();
userForm.setCreateTime(date);
userForm.setUpdateTime(date);
userForm.setLastLoginTime(date);
PasswordHelper.encryptPassword(userForm);
int num = userService.register(userForm);
if(num > 0){
return ResultUtil.success("添加用户成功");
}else {
return ResultUtil.error("添加用户失败");
}
}
/**编辑用户详情*/
@GetMapping("/edit")
public String userDetail(Model model, String userId){
User user = userService.selectByUserId(userId);
List<Classes> classes = classesService.selectAll();
List<String> grades = userService.selectGradeList();
model.addAttribute("user", user);
model.addAttribute("classes", classes);
model.addAttribute("grades", grades);
return "user/userDetail";
}
/**编辑用户*/
@PostMapping("/edit")
@Controller
public class AdminRenderController {
@Autowired
private SysConfigService sysConfigService;
@Autowired
private SubjectService subjectService;
@Autowired
private InstituteService instituteService;
@Autowired
private ClassesService classesService;
@Autowired
private UserService userService;
@Autowired
private ExaminationService examService;
/*网站基本信息*/
@GetMapping("/siteinfo")
public String siteinfo(Model model){
Map<String, String> map = sysConfigService.selectAll();
model.addAttribute("siteinfo", map);
return "site/siteinfo";
}
/*友情链接*/
@GetMapping("/links")
public String links(){
return "link/list";
}
/*课程*/
@GetMapping("/subjects")
public String subjects() {
return "subject/list";
}
/*标签*/
@GetMapping("/tags")
public String tags(){
return "tag/list";
}
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private ShiroRealm shiroRealm;
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
@Autowired