源码获取:博客首页 "资源" 里下载!
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax 等等
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
/**
* 注册
* @param user
* @return
*/
@RequestMapping("/register")
@ResponseBody
public String register(User user){
Map map = new HashMap();
//调用注册的方法
if(userService.addUser(user)>0){
map.put(SystemConstant.SUCCESS,true);
map.put(SystemConstant.MESSAGE,"恭喜你,注册成功!");
}else{
map.put(SystemConstant.SUCCESS,false);
map.put(SystemConstant.MESSAGE,"很遗憾,注册失败,请重新尝试!");
}
return JSON.toJSONString(map);
}
/**
* 登录
* @param
* @return
*/
@RequestMapping("/login")
@ResponseBody
public String login(String loginName, String password, HttpSession Session){
Map map = new HashMap();
//调用注册的方法
User loginUser = userService.login(loginName, password);
//登录判断
if(loginUser!=null){
//将密码清空
loginUser.setPassword(null);
map.put(SystemConstant.SUCCESS,true);
//保存登录用户信息到session中
Session.setAttribute(SystemConstant.FRONT_LOGIN_USER,loginUser);
}else{
map.put(SystemConstant.SUCCESS,false);
map.put(SystemConstant.MESSAGE,"用户名或密码错误,请重新登录!");
}
return JSON.toJSONString(map);
}
/**
* 根据用户名查询用户信息
* @param loginName
* @return
*/
@RequestMapping("/checkName")
@ResponseBody
public String checkName(String loginName){
Map map = new HashMap();
//调用注册的方法
if(userService.findUserByName(loginName)!=null){
map.put(SystemConstant.EXISI,true);
map.put(SystemConstant.MESSAGE,"用户名存在,请重新输入");
}else{
map.put(SystemConstant.EXISI,false);
}
return JSON.toJSONString(map);
}
}
@Controller
@RequestMapping("/room")
public class RoomController {
@Resource
private RoomService roomService;
@Resource
private RoomTypeService roomTypeService;
/**
* 查询房间详情
* @param id
* @param model
* @return
*/
@RequestMapping("/{id}.html")
public String detail(@PathVariable Integer id, Model model){
//调用查询房间详情的方法
Room room = roomService.findById(id);
//将数据放到模型中
model.addAttribute("room",room);
return "detail";
}
/**
* 查询全部房间列表
* @param model
* @return
*/
@RequestMapping("/list.html")
public String list(Model model){
//调用查询所有房型列表的方法
List roomTypeList = roomTypeService.findRoomTypeList(null);
//创建查询条件类
RoomVo roomVo = new RoomVo();
roomVo.setStatus(3);//可预订
//查询房间列表
List roomList = roomService.findRoomListByPage(roomVo);
//将数据放到模型中
model.addAttribute("roomTypeList",roomTypeList);
model.addAttribute("roomList",roomList);
return "hotelList";
}
/**
* 根据房型查询房间列表
* @param model
* @return
*/
@RequestMapping("/list/{id}")
public String list(@PathVariable Integer id,Model model){
//调用查询所有房型列表的方法
List roomTypeList = roomTypeService.findRoomTypeList(null);
//创建查询条件类
RoomVo roomVo = new RoomVo();
roomVo.setRoomtypeid(id);//房型ID
roomVo.setStatus(3);//可预订
//查询房间列表
List roomList = roomService.findRoomListByPage(roomVo);
//将数据放到模型中
model.addAttribute("roomTypeList",roomTypeList);
model.addAttribute("roomList",roomList);
model.addAttribute("typeId",id);//将当前选中的房型ID保存到模型中,目的是在页面中回显选中的文本(改变选中的颜色)
return "hotelList";
}
}
@Controller
@RequestMapping("/orders")
public class OrdersController {
@Resource
private OrdersService ordersService;
/**
* 添加订单
* @param orders
* @return
*/
@RequestMapping("/addOrders")
@ResponseBody
public String addOrders(Orders orders){
Map map = new HashMap();
//调用添加订单的方法
if(ordersService.addOrders(orders)>0){
map.put(SystemConstant.SUCCESS,true);
map.put(SystemConstant.MESSAGE,"酒店预订成功");
}else{
map.put(SystemConstant.SUCCESS,false);
map.put(SystemConstant.MESSAGE,"酒店预订失败,请重试!");
}
return JSON.toJSONString(map);
}
}
/**
* 角色管理
*/
@RequestMapping("/admin/role")
@RestController
public class RoleController {
@Autowired
private RoleService roleService;
@Autowired
private EmployeeService employeeService;
@Autowired
private MenuService menuService;
/**
* 角色列表查询
* @return
*/
@RequestMapping("/list")
public DataGridViewResult list(RoleVo roleVo){
//设置分页信息
PageHelper.startPage(roleVo.getPage(),roleVo.getLimit());
//调用分页查询的方法
List roleList = roleService.findRoleList(roleVo);
//创建分页对象
PageInfo pageInfo = new PageInfo(roleList);
//返回数据
return new DataGridViewResult(pageInfo.getTotal(),pageInfo.getList());
}
//添加部门信息
@RequestMapping("/addRole")
public String addRole(Role role){
//创建map存放信息
Map map = new HashMap();
int addRole = roleService.addRole(role);
if(addRole>0){
map.put(SystemConstant.SUCCESS,true);
map.put(SystemConstant.MESSAGE,"添加成功");
}else{
map.put(SystemConstant.SUCCESS,false);
map.put(SystemConstant.MESSAGE,"添加失败");
}
//map中存放的信息已json形式返回
return JSON.toJSONString(map);
}
//修改角色信息
@RequestMapping("/updateRole")
public String updateRole(Role role){
Map map = new HashMap();
int updateRole = roleService.updateRole(role);
if(updateRole>0){
map.put(SystemConstant.SUCCESS,true);
map.put(SystemConstant.MESSAGE,"修改成功");
}else{
map.put(SystemConstant.SUCCESS,false);
map.put(SystemConstant.MESSAGE,"修改失败");
}
//map中存放的信息已json形式返回
return JSON.toJSONString(map);
}
//删除角色信息
@RequestMapping("/deleteById")
public String deleteById(Integer id){
Map map = new HashMap();
int deleteById = roleService.deleteById(id);
if (deleteById>0){
map.put(SystemConstant.SUCCESS,true);//删除成功
map.put(SystemConstant.MESSAGE,"删除成功");
}else{
map.put(SystemConstant.SUCCESS,false);//删除失败
map.put(SystemConstant.MESSAGE,"删除失败");
}
return JSON.toJSONString(map);
}
//查看该角色编号下是否有员工
@RequestMapping("/checkRoleHasEmployee")
public String checkDeptHasEmployee(Integer id){
Map map = new HashMap();
int countById = employeeService.getEmployeeCountByRoleId(id);
if (countById>0){
//该角色是否有员工在用
map.put(SystemConstant.EXISI,true);//存在
map.put(SystemConstant.MESSAGE,"该角色有员工使用,不能删除");
}else{
map.put(SystemConstant.EXISI,false);//存在
}
return JSON.toJSONString(map);
}
/**
* 初始化菜单
* @return
*/
@RequestMapping("/initMenuTree")
public DataGridViewResult initMenuTree(Integer roleId){
//调用查询菜单列表的方法
List
源码获取:博客首页 "资源" 里下载!