基于javaweb+jsp的在线选课网上选课系统(java+SSM+jsp+mysql+maven)
一、项目简述
功能: 系统分为三个角色。最高权限管理员,学生,教师,包括 学生管理,教师管理,课程管理,选课,退课,成绩查 询。,教学课程,查看选课名单等等功能完全齐备。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + Mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP +Spring + SpringMVC + MyBatis + Bootstrap4+ css + JavaScript + JQuery + Ajax + particles.js+ maven等等。
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
* @param user
* @return
*/
@PostMapping("/addSaveStu")
@ApiOperation("添加学生接口")
@PreAuthorize("hasRole('管理员')")
@ResponseBody
public Message addSaveStudent(User user){
if(StringUtils.isEmpty(user.getUsername())){
return Message.error("请填写用户名");
}
} catch (Exception e) {
e.printStackTrace();
return new AjaxResult("删除失败");
}
return ajaxResult;
}
@PostMapping(value="/deleteBatchUser")
@ApiOperation("批量删除用户接口")
@PreAuthorize("hasRole('管理员')")
@ResponseBody
public AjaxResult deleteBatchUser(String ids){
String[] idsArr = ids.split(",");
List list = new ArrayList();
for(int i=0;i<idsArr.length;i++){
list.add(idsArr[i]);
}
try{
userService.batchRemove(list);
return new AjaxResult();
}catch(Exception e){
return "views/user/user_list";
}
@GetMapping("/listpage")
@ApiOperation("查询用户分页数据接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "UserQuery", value = "用户查询对象", defaultValue = "userQuery对象")
})
@ResponseBody
@PreAuthorize("hasRole('管理员')")
public PageList listpage(UserQuery userQuery){
return userService.listpage(userQuery);
}
@PreAuthorize("hasRole('管理员')")
public String index(String menuid,Model model){
List<Role> roles = queryAllRole();
model.addAttribute("roles",roles);
model.addAttribute("menuid",menuid);
//用户首页
return "views/user/user_list";
}
@GetMapping("/listpage")
@ApiOperation("查询用户分页数据接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "UserQuery", value = "用户查询对象", defaultValue = "userQuery对象")
})
@ResponseBody
@PreAuthorize("hasRole('管理员')")
}
if(StringUtils.isEmpty(user.getPassword())){
return Message.error("请填写密码");
}
if(StringUtils.isEmpty(user.getEmail())){
return Message.error("请填写邮箱");
}
if(StringUtils.isEmpty(user.getTel())){
return Message.error("请填写手机号");
}
User userByUserName = userService.findUserByUserName(user.getUsername());
if(userByUserName!=null){
return Message.error("用户名已存在");
}
user.setType(2);
if(userService.addUser(user)<=0){
return Message.error("教师添加失败");
}
//保存工作流程操作
IdentityService is = engine.getIdentityService();
// 添加用户组
return Message.error("请填写手机号");
}
if(StringUtils.isEmpty(user.getStunum())){
return Message.error("请填写学号");
}
User userByUserName = userService.findUserByUserName(user.getUsername());
if(userByUserName!=null){
return Message.error("用户名已存在");
}
if(userService.findByStuNum(user.getStunum())!=null){
@Autowired
private IRoleService roleService;
@Resource
private ProcessEngineConfiguration configuration;
@Resource
private ProcessEngine engine;
@GetMapping("/index")
@ApiOperation("跳转用户页接口")
@PreAuthorize("hasRole('管理员')")
public String index(String menuid,Model model){
return Message.error("请填写手机号");
}
if(StringUtils.isEmpty(user.getStunum())){
return Message.error("请填写学号");
}
User userByUserName = userService.findUserByUserName(user.getUsername());
if(userByUserName!=null){
return Message.error("用户名已存在");
}
if(userService.findByStuNum(user.getStunum())!=null){
return Message.error("该学号已存在");
}
user.setType(3);
if(userService.addUser(user)<=0){
return Message.error("学生添加失败");
}
userQuery.setType(3L);//2表示老学生
return userService.listpage(userQuery);
}
/**
* 添加学生操作
* @param user
* @return
*/
@PostMapping("/addSaveStu")
@ApiOperation("添加学生接口")
@PreAuthorize("hasRole('管理员')")
@ResponseBody
public Message addSaveStudent(User user){
if(StringUtils.isEmpty(user.getUsername())){
return Message.error("请填写用户名");
}
if(StringUtils.isEmpty(user.getPassword())){
return Message.error("请填写密码");
}
return Message.error("请填写用户名");
}
if(StringUtils.isEmpty(user.getEmail())){
return Message.error("请填写邮箱");
}
if(StringUtils.isEmpty(user.getTel())){
return Message.error("请填写手机号");
}
User userByUserName = userService.findUserByUserName(user.getUsername());
if(userByUserName!=null){
if(!userByUserName.getId().equals(user.getId())){
return Message.error("该用户名已存在");
}
}
try {
userService.editSaveUser(user);
operaterLogService.add("编辑学生成功,学生名称:"+user.getUsername());
return Message.success();
} catch (Exception e) {
return new AjaxResult();
}catch(Exception e){
return new AjaxResult("批量删除失败");
}
}
}
用户管理控制器:
/**
* 用户管理控制器
*/
@RequestMapping("/user/")
@Controller
public class UserController {
return userId;
}
/**
* 修改密码页面
* @return
*/
@RequestMapping(value="/update_pwd",method=RequestMethod.GET)
public String updatePwd(){
return "views/user/update_pwd";
}
/**
* 修改密码操作
* @param oldPwd
* @param newPwd
* @return
*/
@ResponseBody
@PostMapping("/update_pwd")
public Message updatePassword(@RequestParam(name="oldPwd",required=true)String oldPwd,
/**
* 修改密码操作
* @param oldPwd
* @param newPwd
* @return
*/
@ResponseBody
@PostMapping("/update_pwd")
public Message updatePassword(@RequestParam(name="oldPwd",required=true)String oldPwd,
@RequestParam(name="newPwd",required=true)String newPwd){
String username = CommonUtils.getLoginUser().getUsername();
User userByUserName = userService.findUserByUserName(username);
if(userByUserName!=null){
String password = userByUserName.getPassword();
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
boolean matches = bCryptPasswordEncoder.matches(oldPwd, password);
if(!matches){
return Message.error("旧密码不正确");//true
}
userByUserName.setPassword(bCryptPasswordEncoder.encode(newPwd));
if(userService.editUserPassword(userByUserName)<=0){
Group tGroup = new GroupEntityImpl();
tGroup.setId("tGroup");
if(user.getType() == 2) {
//保存老师组
userService.saveRel(is, userInfo, tGroup);
}
if(user.getType() == 3) {
//保存学生组
userService.saveRel(is, userInfo, stuGroup);
}
//添加用户的角色
@PostMapping("/addUserRole")
@ApiOperation("添加用户角色接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "paramMap", value = "如:{userId:1,[1,2,3,4]]}")
})
@ResponseBody
public AjaxResult addUserRole(@RequestBody Map paramMap){
AjaxResult ajaxResult = new AjaxResult();
String userId = (String)paramMap.get("userId");
List roleIds = (List) paramMap.get("roleIds");
try {
//添加用户对应的角色
roleService.addUserRole(userId,roleIds);
private IPermissionService permissionService;
@PreAuthorize("hasRole('管理员')")
@ResponseBody
@RequestMapping("/role/doAdd")
public String doAdd(Role role){
//角色添加
return "ok";
}
//添加角色
@RequestMapping("/role/addRole")
@PreAuthorize("hasRole('管理员')")
@ResponseBody
public Message addSaveStudent(User user){
if(StringUtils.isEmpty(user.getUsername())){
return Message.error("请填写用户名");
}
if(StringUtils.isEmpty(user.getPassword())){
return Message.error("请填写密码");
}
if(StringUtils.isEmpty(user.getEmail())){
return Message.error("请填写邮箱");
}
if(StringUtils.isEmpty(user.getTel())){
return Message.error("请填写手机号");
}
if(StringUtils.isEmpty(user.getStunum())){
return Message.error("请填写学号");
}
User userByUserName = userService.findUserByUserName(user.getUsername());
if(userByUserName!=null){
return Message.error("用户名已存在");
}
@ResponseBody
public PageList listpage(RoleQuery roleQuery){
System.out.println("传递参数:"+roleQuery);
return roleService.listpage(roleQuery);
}
//修改用户editSaveUser
@RequestMapping("/role/editSaveRole")
@ResponseBody
public AjaxResult editSaveRole(Role role){
System.out.println("修改角色...."+role);
try {
roleService.editSaveRole(role);
return new AjaxResult();
} catch (Exception e) {
e.printStackTrace();
}
return new AjaxResult("修改失败");
@PostMapping("/editSaveStu")
@ApiOperation("修改教师接口")
@PreAuthorize("hasRole('管理员')")
@ResponseBody
public Message editSaveStu(User user){
if(StringUtils.isEmpty(user.getUsername())){
return Message.error("请填写用户名");
}
if(StringUtils.isEmpty(user.getEmail())){
return Message.error("请填写邮箱");
private ProcessEngine engine;
@Autowired
private IOperaterLogService operaterLogService;
//老师列表
//后台查询学生列表
@RequestMapping("/index")
public String index(Model model){
//用户首页
model.addAttribute("courses",courseService.queryAll());
model.addAttribute("classes",classesService.queryAll());
return "views/student/student_list";
}
@RequestMapping("/listpage")
@ResponseBody
public PageList listpage(UserQuery userQuery){
userQuery.setType(3L);//2表示老学生
return userService.listpage(userQuery);
}
成绩管理接口:
@RequestMapping("/score")
@Controller
@Api(tags = "成绩管理接口")
public class ScoreController {
@Autowired
private IScoreService scoreService;
@Autowired
private IUserService userService;
@Autowired
private ICourseService courseService;
@Autowired
private IOperaterLogService operaterLogService;
@GetMapping("/index")
@ApiOperation("跳转成绩页接口")
@RequestMapping("/index")
public String index(Model model){
//用户首页
model.addAttribute("courses",courseService.queryAll());
model.addAttribute("classes",classesService.queryAll());
return "views/student/student_list";
}
@RequestMapping("/listpage")
@ResponseBody
public PageList listpage(UserQuery userQuery){
userQuery.setType(3L);//2表示老学生
return userService.listpage(userQuery);
}
/**
* 添加学生操作
* @param user
* @return
*/
@PostMapping("/addSaveStu")
@ApiOperation("添加学生接口")
@PreAuthorize("hasRole('管理员')")
return ajaxResult;
}catch (Exception e){
e.printStackTrace();
return new AjaxResult("保存权限失败");
}
}
}
学生管理接口:
@RequestMapping("/student")
@Controller
@Api(tags = "学生管理接口")
public class StudentController {
@Autowired
public String index(Model model){
//用户首页
model.addAttribute("classes",classesService.queryAll());
return "views/teacher/teacher_list";
}
@RequestMapping("/listpage")
@ResponseBody
public PageList listpage(UserQuery userQuery){
userQuery.setType(2L);//2表示老师
return userService.listpage(userQuery);
}
/**
* 添加教师操作
* @param user
* @return
*/
List<Permission> permisisons = permissionService.findAllPermisisons();
model.addAttribute("permissions",permisisons);
//返回角色
return "views/role/role_list";
}
@RequestMapping("/role/listpage")
@ResponseBody
public PageList listpage(RoleQuery roleQuery){
System.out.println("传递参数:"+roleQuery);
return roleService.listpage(roleQuery);
}
//修改用户editSaveUser
@RequestMapping("/role/editSaveRole")
@ResponseBody
public AjaxResult editSaveRole(Role role){
System.out.println("修改角色...."+role);
try {
roleService.editSaveRole(role);
return new AjaxResult();
} catch (Exception e) {
e.printStackTrace();
}
if(user.getType() == 2) {
//保存老师组
userService.saveRel(is, userInfo, tGroup);
}
if(user.getType() == 3) {
//保存学生组
userService.saveRel(is, userInfo, stuGroup);
}
Long userId = user.getId();
return userId;
}
@Autowired
private IUserService userService;
@Autowired
private IClassesService classesService;
@Resource
private ProcessEngine engine;
@Autowired
private IOperaterLogService operaterLogService;
//老师列表
@RequestMapping("/index")
public String index(Model model){
//用户首页
model.addAttribute("classes",classesService.queryAll());
return "views/teacher/teacher_list";
}
@RequestMapping("/listpage")
@ResponseBody
//添加用户对应的角色
roleService.addUserRole(userId,roleIds);
return ajaxResult;
}catch (Exception e){
e.printStackTrace();
return new AjaxResult("保存角色失败");
}
}
//添加用户
@RequestMapping("/regSaveUser")
@ResponseBody
public Long addTeacher(User user){
System.out.println("保存用户...."+user);
userService.addUser(user);
//保存工作流程操作
IdentityService is = engine.getIdentityService();
// 添加用户组
org.activiti.engine.identity.User userInfo = userService.saveUser(is, user.getUsername());
// 添加用户对应的组关系
Group stuGroup = new GroupEntityImpl();
stuGroup.setId("stuGroup");
Group tGroup = new GroupEntityImpl();
tGroup.setId("tGroup");
if(user.getType() == 2) {
public class StudentController {
@Autowired
private IUserService userService;
@Autowired
private ICourseService courseService;
@Autowired
private IClassesService classesService;
@Resource
private ProcessEngine engine;
@Autowired
private IOperaterLogService operaterLogService;
//老师列表
//后台查询学生列表
@RequestMapping("/index")
public String index(Model model){
//用户首页
model.addAttribute("courses",courseService.queryAll());
model.addAttribute("classes",classesService.queryAll());
return "views/student/student_list";
}
@RequestMapping("/listpage")