Java毕业设计实战之教室预订管理系统的实现
作者:OldWinePot 发布时间:2023-03-03 20:38:11
标签:Java,教室预订管理,毕业设计
一、项目运行
环境配置:
Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。
项目技术:
Spring + SpringBoot+ mybatis + Maven + Vue 等等组成,B/S模式 + Maven管理等等。
用户管理控制器:
/**
* 用户管理控制器
*/
@RequestMapping("/user/")
@Controller
public class UserController {
@Autowired
private IUserService userService;
@Autowired
private IRoleService roleService;
@Resource
private ProcessEngineConfiguration configuration;
@Resource
private ProcessEngine engine;
@GetMapping("/index")
@ApiOperation("跳转用户页接口")
@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('管理员')")
public PageList listpage(UserQuery userQuery){
return userService.listpage(userQuery);
}
//添加用户
@PostMapping("/addUser")
@ApiOperation("添加用户接口")
@ResponseBody
public Map<String,Object> addUser(User user){
Map<String, Object> ret = new HashMap<>();
ret.put("code",-1);
if(StringUtils.isEmpty(user.getUsername())){
ret.put("msg","请填写用户名");
return ret;
}
if(StringUtils.isEmpty(user.getPassword())){
ret.put("msg","请填写密码");
return ret;
}
if(StringUtils.isEmpty(user.getEmail())){
ret.put("msg","请填写邮箱");
return ret;
}
if(StringUtils.isEmpty(user.getTel())){
ret.put("msg","请填写手机号");
return ret;
}
if(StringUtils.isEmpty(user.getHeadImg())){
ret.put("msg","请上传头像");
return ret;
}
if(userService.addUser(user)<=0) {
ret.put("msg", "添加用户失败");
return ret;
}
ret.put("code",0);
ret.put("msg","添加用户成功");
return ret;
}
/**
* 修改用户信息操作
* @param user
* @return
*/
@PostMapping("/editSaveUser")
@ApiOperation("修改用户接口")
@PreAuthorize("hasRole('管理员')")
@ResponseBody
public Message editSaveUser(User user){
if(StringUtils.isEmpty(user.getUsername())){
return Message.error("请填写用户名");
}
if(StringUtils.isEmpty(user.getEmail())){
return Message.error("请填写邮箱");
}
if(StringUtils.isEmpty(user.getTel())){
return Message.error("请填写手机号");
}
try {
userService.editSaveUser(user);
return Message.success();
} catch (Exception e) {
e.printStackTrace();
return Message.error("修改用户信息失败");
}
}
//添加用户
@GetMapping("/deleteUser")
@ApiOperation("删除用户接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "如:88",required = true)
})
@PreAuthorize("hasRole('管理员')")
@ResponseBody
public AjaxResult deleteUser(@RequestParam(required = true) Long id){
AjaxResult ajaxResult = new AjaxResult();
try {
userService.deleteUser(id);
} 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 new AjaxResult("批量删除失败");
}
}
//查询所有角色
public List<Role> queryAllRole(){
return roleService.queryAll();
}
//添加用户的角色
@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);
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) {
//保存老师组
userService.saveRel(is, userInfo, tGroup);
}
if(user.getType() == 3) {
//保存学生组
userService.saveRel(is, userInfo, stuGroup);
}
Long userId = user.getId();
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,
@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){
return Message.error("密码修改失败");
}
}
return Message.success();
}
/**
* 清除缓存
* @param request
* @param response
* @return
*/
@ResponseBody
@PostMapping("/clear_cache")
public Message clearCache(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragrma","no-cache");
response.setDateHeader("Expires",0);
return Message.success();
}
}
角色管理控制层:
@Controller
public class RoleController {
@Autowired
private IRoleService roleService;
@Autowired
private IPermissionService permissionService;
@PreAuthorize("hasRole('管理员')")
@ResponseBody
@RequestMapping("/role/doAdd")
public String doAdd(Role role){
//角色添加
return "ok";
}
//添加角色
@RequestMapping("/role/addRole")
@PreAuthorize("hasRole('管理员')")
@ResponseBody
public AjaxResult addRole(Role role){
System.out.println("保存角色...."+role);
try {
roleService.saveRole(role);
return new AjaxResult();
} catch (Exception e) {
e.printStackTrace();
return new AjaxResult("操作失败");
}
}
@PreAuthorize("hasRole('管理员')")
@RequestMapping("/role/index")
public String index(Model model){
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();
}
return new AjaxResult("修改失败");
}
//添加角色
@RequestMapping("/role/deleteRole")
@ResponseBody
public AjaxResult deleteRole(Long id){
System.out.println("删除角色...."+id);
AjaxResult ajaxResult = new AjaxResult();
try {
roleService.deleteRole(id);
} catch (Exception e) {
e.printStackTrace();
return new AjaxResult("删除失败");
}
return ajaxResult;
}
//添加角色权限 addRolePermission
@RequestMapping("/role/addRolePermission")
@ResponseBody
public AjaxResult addRolePermission(@RequestBody Map paramMap){
AjaxResult ajaxResult = new AjaxResult();
String roleId = (String)paramMap.get("roleId");
List permissionIds = (List) paramMap.get("permissionIds");
try {
//添加角色对应的权限
roleService.addRolePermission(roleId,permissionIds);
return ajaxResult;
}catch (Exception e){
e.printStackTrace();
return new AjaxResult("保存权限失败");
}
}
}
来源:https://blog.csdn.net/pastclouds/article/details/122596179


猜你喜欢
- 背景重装的系统,新导入的项目。正常编译能通过,但是clean install就提示包不存在。奇特的是,提示的时jdk库的包。解决问题注: 后
- 前言最近一直被无尽的业务需求淹没,没时间喘息,终于接到一个能让我突破代码舒适区的活儿,解决它的过程非常曲折,一度让我怀疑人生,不过收获也很大
- try catch介绍我们编译运行程序出错的时候,编译器就会抛出异常。抛出异常要比终止程序灵活许多,这是因为Java提供了一个“捕获”异常的
- 上一篇介绍了elasticsearch的client结构,client只是一个门面,在每个方法后面都有一个action来承接相应的功能。但是
- 本文实例讲述了java GUI编程之paint绘制操作。分享给大家供大家参考,具体如下:import java.awt.*;public c
- 前言:微信公众号提供了用户和用户组的管理,我们可以在微信公众号官方里面进行操作,添加备注和标签,以及移动用户组别,同时,微信公众号提供了相应
- 一、简述1、AOP的概念如果你用java做过后台开发,那么你一定知道AOP这个概念。如果不知道也无妨,套用百度百科的介绍,也能让你明白这玩意
- 前言Java17将是一个长期支持的LTS版本。Java采用了6个月的发布周期。也就是说,它将每6个月发布一个新版本的Java。每隔3年,LT
- 本文为大家分享了C# 7.0中的解构功能,供大家参考,具体内容如下解构元组C#7.0新增了诸多功能,其中有一项是新元组(ValueTuple
- Windows的画图板相信很多人都用过,这次我们就来讲讲Java版本的简易画板的实现。基本的思路是这样的:画板实现大致分三部分:一是画板界面
- 通常 Java 执行 Windows 或者 Linux 的命令时,都是使用 Runtime.getRuntime.exec(com
- iOS中有封装好的选择图片后长按出现动画删除效果,效果如下 而Android找了很久都没有找到有这样效果的第三方组件,
- 本文实例讲述了C#精确计算年龄的方法。分享给大家供大家参考。具体如下:该源码在vs2010测试通过using System;using Sy
- 在Android Studio中对一个自己库进行生成操作时将会同时生成*.jar与*.aar文件。分别存储位置: &n
- 最近解决了一个令我头疼好久的问题,就是三星手机拍照图片旋转的问题,项目中有上传图片的功能,那么涉及到拍照,从相册中选择图片,别的手机都ok没
- 1、匿名内部类内部类:在一个类的内部定义了另外的类,称为内部类,匿名内部类指的是没有名字的内部类。为了清楚内部类的主要作用,下面首先观察一个
- 引言float和double类型的主要设计目标是为了科学计算和工程计算。他们执行二进制浮点运算,这是为了在广域数值范围上提供较为精确的快速近
- java语言的输入输出功能是十分强大而灵活的,美中不足的是看上去输入输出的代码并不是很简洁,因为你往往需要包装许多不同的对象。在Java类库
- Android ViewGroup中的Scroller与computeScroll的有什么关系?答:没有直接的关系知道了答案,是不是意味着下
- mybatis if test判断入参的值1.第一种判断方式<if test=' requisition != null an