博主主页:Java旅途
简介:分享计算机知识、学习路线、系统源码及教程
文末获取源码
教室预约管理系统使用SpringBoot+Mybatis进行开发,系统整体分为前台和后台,后台主要对教室,用户等信息进行管理,前台总共分为学生、教室、辅导员、楼长四种角色,通过预约教室,多层审批完成教室预约功能。系统详细功能如下
后台功能:
前台功能:
学生
教师
辅导员
楼长
后台管理员账号密码: admin/123456
前台学生账号密码:xx/123456
前台教师账号密码:lyc/123456
前台辅导员账号密码:zs/123456
前台楼长账号密码:wm/123456
RoomController
package edu.room.manage.controller.console;
import com.github.pagehelper.PageInfo;
import edu.room.manage.common.annotation.Operation;
import edu.room.manage.common.controller.BaseController;
import edu.room.manage.common.exception.MessageException;
import edu.room.manage.common.mybatis.condition.MybatisCondition;
import edu.room.manage.common.utils.ReturnUtils;
import edu.room.manage.domain.Room;
import edu.room.manage.dto.RoomDTO;
import edu.room.manage.service.FloorService;
import edu.room.manage.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import javax.validation.Valid;
/**
*/
@Controller
@RequestMapping("/console/room")
public class RoomController extends BaseController {
@Autowired
private RoomService roomService;
@Autowired
private FloorService floorService;
@Operation("查看教学楼")
@RequestMapping(value = "/index", method = {RequestMethod.GET})
public String index(Model model) {
return "console/room/index";
}
@Operation("教学楼详情")
@RequestMapping(value = "detail/{id}", method = {RequestMethod.GET})
public String from(@PathVariable Integer id, Model model) {
Room room;
if (id != 0) {
room = roomService.selectByPrimaryKey(id);
} else {
room = new Room();
}
model.addAttribute("room", room);
model.addAttribute("floorList", floorService.selectAll());
return "console/room/detail";
}
@Operation("添加更新教学楼")
@RequestMapping(value = "/merge", method = {RequestMethod.POST})
public String save(@Valid Room room, BindingResult result, RedirectAttributes attributes) {
if (result.hasErrors()) {
throw new MessageException(result.getAllErrors().get(0).getDefaultMessage());
}
roomService.merge(room);
return redirect("/console/room/index", "操作成功", attributes);
}
@Operation("删除教学楼")
@RequestMapping(value = "/delete", method = {RequestMethod.GET})
@ResponseBody
public ModelMap delete(Integer id) {
roomService.deleteByPrimaryKey(id);
return ReturnUtils.success("操作成功", null, null);
}
@ResponseBody
@RequestMapping(value = "/list", method = {RequestMethod.GET})
public ModelMap list(RoomDTO room) {
ModelMap map = new ModelMap();
MybatisCondition condition = new MybatisCondition()
.like("r.name", room.getName())
.like("f.name", room.getFloorName())
.like("r.floor", room.getFloor())
.page(room);
PageInfo<RoomDTO> pageInfo = roomService.selectDtoPage(condition);
map.put("pageInfo", pageInfo);
return ReturnUtils.success("加载成功", map);
}
}
HomeController
package edu.room.manage.controller.console;
import edu.room.manage.common.annotation.Operation;
import edu.room.manage.common.context.Constant;
import edu.room.manage.common.controller.BaseController;
import edu.room.manage.common.utils.Md5Utils;
import edu.room.manage.domain.Admin;
import edu.room.manage.domain.Floor;
import edu.room.manage.domain.Room;
import edu.room.manage.domain.User;
import edu.room.manage.service.AdminService;
import edu.room.manage.service.FloorService;
import edu.room.manage.service.RoomService;
import edu.room.manage.service.UserService;
import edu.room.manage.valid.ValidUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;
/**
*/
@Controller
@RequestMapping("console")
@Slf4j
public class HomeController extends BaseController {
@Autowired
private UserService userService;
@Autowired
private RoomService roomService;
@Autowired
private FloorService floorService;
@Autowired
private AdminService adminService;
/**
* 首页
*
* @param model
* @return
*/
@RequestMapping(value = "index", method = {RequestMethod.GET})
public String index(Model model) {
return "console/index";
}
/**
* 首页展示
*
* @param model
* @return
*/
@RequestMapping(value = "main", method = {RequestMethod.GET})
public String right(Model model) {
model.addAllAttributes(this.getTotal());
return "console/right";
}
/**
* 登录页
*
* @return
*/
@RequestMapping(value = "login", method = RequestMethod.GET)
public String loginForm() {
return "console/login";
}
@Operation("登录")
@RequestMapping(value = "login", method = RequestMethod.POST)
public String loginPost(@Valid ValidUser validUser, BindingResult bindingResult, RedirectAttributes redirectAttributes) {
if (bindingResult.hasErrors()) {
redirectAttributes.addFlashAttribute(Constant.ERROR_MESSAGE, bindingResult.getAllErrors().get(0).getDefaultMessage());
return "redirect:login";
}
String username = validUser.getUsername();
Admin admin = (Admin) userService.login(validUser.getUsername(), validUser.getPassword(), User.UserRoleEnum.ADMIN);
if (null == admin) {
redirectAttributes.addFlashAttribute(Constant.ERROR_MESSAGE, "用户名或密码不正确");
return "redirect:login";
} else {
logger.info("用户[" + username + "]登录认证通过");
session.setAttribute(Constant.SESSION_ADMIN, admin);
return "redirect:index";
}
}
/**
* 退出登录
*
* @param redirectAttributes
* @return
*/
@RequestMapping(value = "/logout", method = RequestMethod.GET)
public String logout(RedirectAttributes redirectAttributes) {
log.info("【退出登录】 {}", loginAdmin().getUsername());
session.removeAttribute(SESSION_ADMIN);
redirectAttributes.addFlashAttribute(Constant.ERROR_MESSAGE, "您已安全退出");
return "redirect:login";
}
/**
* 修改密码
*
* @return
*/
@RequestMapping(value = "/modifyPwd", method = {RequestMethod.GET})
public String modifyPwd() {
return "console/modify-pwd";
}
@Operation("修改用户密码")
@RequestMapping(value = "/modifyPwd", method = {RequestMethod.POST})
public String modifyPwd(String pwd, String password, String password2, RedirectAttributes attributes) {
if (!password.equals(password2)) {
return redirect("/console/modifyPwd", "两次密码不一样", attributes);
}
Admin user = adminService.selectByPrimaryKey(loginAdmin().getId());
if (null != user) {
if (!Md5Utils.encode(pwd).equalsIgnoreCase(user.getPassword())) {
return redirect("/console/modifyPwd", "原密码错误", attributes);
}
String newPassword = Md5Utils.encode(password);
user.setPassword(newPassword);
adminService.updateByPrimaryKeySelective(user);
return redirect("/console/modifyPwd", "修改成功", attributes);
} else {
return redirect("/console/modifyPwd", "用户不存在,修改失败", attributes);
}
}
/**
* 首页展示数据
*
* @return
*/
private Map<String, Object> getTotal() {
Integer userCount = userService.selectCount(new User());
Map<String, Object> mp = new HashMap<>(4);
mp.put("userCount", userCount);
mp.put("roomCount", roomService.selectCount(new Room()));
mp.put("floorCount", floorService.selectCount(new Floor()));
return mp;
}
}
大家点赞、收藏、关注、评论啦 、👇🏻点开下方卡片👇🏻关注后回复 106