Get the source code: Download it from "Resources" on the homepage of the blog!
Features
springboot hotel hotel management system. The system is a rear tube system and has no front desk. Mainly divided into three roles: manager / staff / front desk staff.
The main functions are:
guest room: room standard, room information;
order: check-in order;
employee: employee information;
affairs: transaction information;
parking: parking space information;
finance: financial information;
history: order history, garage history;
member: member information;
environmental needs
1. Operating environment: preferably java jdk 1.8, we are running on this platform. Other versions are also theoretically possible.
2. IDE environment: IDEA, Eclipse, Myeclipse can be used. IDEA is recommended;
3. Tomcat environment: Tomcat 7.x, 8.x, 9.x versions are available
4. Hardware environment: Windows 7/8/10 with more than 1G memory; or Mac OS;
5. Maven project: Yes; Check whether pom.xml is included in the source code directory; if so, it is a maven project, otherwise it is a non-maven project
6. Database: MySql version 8.0;
technology stack
1. Backend: SpringBoot
2. Front end: html+layui+jQuery
Instructions for use
1. Use IDEA/Eclipse/MyEclipse to import the project. When importing from Eclipse/MyEclipse, if it is a maven project, please select maven; if it is a maven project, after the import is successful, please execute the maven clean;maven install command to download the required jar package;
2. Use Navicat or other tools to create a database with the corresponding name in mysql, and import the sql file of
the project; 3. Change the database configuration in the db.properties configuration file in the project to your own configuration
4. Configure tomcat, and then run project, enter localhost:8888 to log
in
Front desk staff: sever1 Password: worker1
User Management Controller:
/**
* 用户管理控制器
* @author yy
*
*/
@RequestMapping("/admin/user")
@Controller
public class UserController {
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
/**
* 用户列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
Map<String, Object> queryMap = new HashMap<String, Object>();
model.addObject("roleList", roleService.findList(queryMap));
model.setViewName("user/list");
return model;
}
/**
* 获取用户列表
* @param page
* @param username
* @param roleId
* @param sex
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.POST)
@ResponseBody
public Map<String, Object> getList(Page page,
@RequestParam(name="username",required=false,defaultValue="") String username,
@RequestParam(name="roleId",required=false) Long roleId,
@RequestParam(name="sex",required=false) Integer sex
){
Map<String, Object> ret = new HashMap<String, Object>();
Map<String, Object> queryMap = new HashMap<String, Object>();
queryMap.put("username", username);
queryMap.put("roleId", roleId);
queryMap.put("sex", sex);
queryMap.put("offset", page.getOffset());
queryMap.put("pageSize", page.getRows());
ret.put("rows", userService.findList(queryMap));
ret.put("total", userService.getTotal(queryMap));
return ret;
}
/**
* 添加用户
* @param user
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> add(User user){
Map<String, String> ret = new HashMap<String, String>();
if(user == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的用户信息!");
return ret;
}
if(StringUtils.isEmpty(user.getUsername())){
ret.put("type", "error");
ret.put("msg", "请填写用户名!");
return ret;
}
if(StringUtils.isEmpty(user.getPassword())){
ret.put("type", "error");
ret.put("msg", "请填写密码!");
return ret;
}
if(user.getRoleId() == null){
ret.put("type", "error");
ret.put("msg", "请选择所属角色!");
return ret;
}
if(isExist(user.getUsername(), 0l)){
ret.put("type", "error");
ret.put("msg", "该用户名已经存在,请重新输入!");
return ret;
}
if(userService.add(user) <= 0){
ret.put("type", "error");
ret.put("msg", "用户添加失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "角色添加成功!");
return ret;
}
/**
* 编辑用户
* @param user
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> edit(User user){
Map<String, String> ret = new HashMap<String, String>();
if(user == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的用户信息!");
return ret;
}
if(StringUtils.isEmpty(user.getUsername())){
ret.put("type", "error");
ret.put("msg", "请填写用户名!");
return ret;
}
// if(StringUtils.isEmpty(user.getPassword())){
// ret.put("type", "error");
// ret.put("msg", "请填写密码!");
// return ret;
// }
if(user.getRoleId() == null){
ret.put("type", "error");
ret.put("msg", "请选择所属角色!");
return ret;
}
if(isExist(user.getUsername(), user.getId())){
ret.put("type", "error");
ret.put("msg", "该用户名已经存在,请重新输入!");
return ret;
}
if(userService.edit(user) <= 0){
ret.put("type", "error");
ret.put("msg", "用户添加失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "角色添加成功!");
return ret;
}
/**
* 批量删除用户
* @param ids
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> delete(String ids){
Map<String, String> ret = new HashMap<String, String>();
if(StringUtils.isEmpty(ids)){
ret.put("type", "error");
ret.put("msg", "选择要删除的数据!");
return ret;
}
if(ids.contains(",")){
ids = ids.substring(0,ids.length()-1);
}
if(userService.delete(ids) <= 0){
ret.put("type", "error");
ret.put("msg", "用户删除失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "用户删除成功!");
return ret;
}
/**
* 上传图片
* @param photo
* @param request
* @return
*/
@RequestMapping(value="/upload_photo",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> uploadPhoto(MultipartFile photo,HttpServletRequest request){
Map<String, String> ret = new HashMap<String, String>();
if(photo == null){
ret.put("type", "error");
ret.put("msg", "选择要上传的文件!");
return ret;
}
if(photo.getSize() > 1024*1024*1024){
ret.put("type", "error");
ret.put("msg", "文件大小不能超过10M!");
return ret;
}
//获取文件后缀
String suffix = photo.getOriginalFilename().substring(photo.getOriginalFilename().lastIndexOf(".")+1,photo.getOriginalFilename().length());
if(!"jpg,jpeg,gif,png".toUpperCase().contains(suffix.toUpperCase())){
ret.put("type", "error");
ret.put("msg", "请选择jpg,jpeg,gif,png格式的图片!");
return ret;
}
String savePath = request.getServletContext().getRealPath("/") + "/resources/upload/";
File savePathFile = new File(savePath);
if(!savePathFile.exists()){
//若不存在改目录,则创建目录
savePathFile.mkdir();
}
String filename = new Date().getTime()+"."+suffix;
try {
//将文件保存至指定目录
photo.transferTo(new File(savePath+filename));
}catch (Exception e) {
// TODO Auto-generated catch block
ret.put("type", "error");
ret.put("msg", "保存文件异常!");
e.printStackTrace();
return ret;
}
ret.put("type", "success");
ret.put("msg", "用户删除成功!");
ret.put("filepath",request.getServletContext().getContextPath() + "/resources/upload/" + filename );
return ret;
}
/**
* 判断该用户名是否存在
* @param username
* @param id
* @return
*/
private boolean isExist(String username,Long id){
User user = userService.findByUsername(username);
if(user == null)return false;
if(user.getId().longValue() == id.longValue())return false;
return true;
}
}
Role controller:
/**
* 角色role控制器
* @author yy
*
*/
@RequestMapping("/admin/role")
@Controller
public class RoleController {
@Autowired
private RoleService roleService;
@Autowired
private AuthorityService authorityService;
@Autowired
private MenuService menuService;
/**
* 角色列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.setViewName("/role/list");
return model;
}
/**
* 获取角色列表
* @param page
* @param name
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.POST)
@ResponseBody
public Map<String, Object> getList(Page page,
@RequestParam(name="name",required=false,defaultValue="") String name
){
Map<String, Object> ret = new HashMap<String, Object>();
Map<String, Object> queryMap = new HashMap<String, Object>();
queryMap.put("name", name);
queryMap.put("offset", page.getOffset());
queryMap.put("pageSize", page.getRows());
ret.put("rows", roleService.findList(queryMap));
ret.put("total", roleService.getTotal(queryMap));
return ret;
}
/**
* 角色添加
* @param role
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> add(Role role){
Map<String, String> ret = new HashMap<String, String>();
if(role == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的角色信息!");
return ret;
}
if(StringUtils.isEmpty(role.getName())){
ret.put("type", "error");
ret.put("msg", "请填写角色名称!");
return ret;
}
if(roleService.add(role) <= 0){
ret.put("type", "error");
ret.put("msg", "角色添加失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "角色添加成功!");
return ret;
}
/**
* 角色修改
* @param role
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> edit(Role role){
Map<String, String> ret = new HashMap<String, String>();
if(role == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的角色信息!");
return ret;
}
if(StringUtils.isEmpty(role.getName())){
ret.put("type", "error");
ret.put("msg", "请填写角色名称!");
return ret;
}
if(roleService.edit(role) <= 0){
ret.put("type", "error");
ret.put("msg", "角色修改失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "角色修改成功!");
return ret;
}
/**
* 删除角色信息
* @param id
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> delete(Long id){
Map<String, String> ret = new HashMap<String, String>();
if(id == null){
ret.put("type", "error");
ret.put("msg", "请选择要删除的角色!");
return ret;
}
try {
if(roleService.delete(id) <= 0){
ret.put("type", "error");
ret.put("msg", "删除失败,请联系管理员!");
return ret;
}
} catch (Exception e) {
// TODO: handle exception
ret.put("type", "error");
ret.put("msg", "该角色下存在权限或者用户信息,不能删除!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "角色删除成功!");
return ret;
}
/**
* 获取所有的菜单信息
* @return
*/
@RequestMapping(value="/get_all_menu",method=RequestMethod.POST)
@ResponseBody
public List<Menu> getAllMenu(){
Map<String, Object> queryMap = new HashMap<String, Object>();
queryMap.put("offset", 0);
queryMap.put("pageSize", 99999);
return menuService.findList(queryMap);
}
/**
* 添加权限
* @param ids
* @return
*/
@RequestMapping(value="/add_authority",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> addAuthority(
@RequestParam(name="ids",required=true) String ids,
@RequestParam(name="roleId",required=true) Long roleId
){
Map<String,String> ret = new HashMap<String, String>();
if(StringUtils.isEmpty(ids)){
ret.put("type", "error");
ret.put("msg", "请选择相应的权限!");
return ret;
}
if(roleId == null){
ret.put("type", "error");
ret.put("msg", "请选择相应的角色!");
return ret;
}
if(ids.contains(",")){
ids = ids.substring(0,ids.length()-1);
}
String[] idArr = ids.split(",");
if(idArr.length > 0){
authorityService.deleteByRoleId(roleId);
}
for(String id:idArr){
Authority authority = new Authority();
authority.setMenuId(Long.valueOf(id));
authority.setRoleId(roleId);
authorityService.add(authority);
}
ret.put("type", "success");
ret.put("msg", "权限编辑成功!");
return ret;
}
/**
* 获取某个角色的所有权限
* @param roleId
* @return
*/
@RequestMapping(value="/get_role_authority",method=RequestMethod.POST)
@ResponseBody
public List<Authority> getRoleAuthority(
@RequestParam(name="roleId",required=true) Long roleId
){
return authorityService.findListByRoleId(roleId);
}
}
Room management background controller:
/**
* 房间管理后台控制器
* @author yy
*
*/
@RequestMapping("/admin/room")
@Controller
public class RoomController {
@Autowired
private RoomTypeService roomTypeService;
@Autowired
private RoomService roomService;
@Autowired
private FloorService floorService;
/**
* 房间管理列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.addObject("roomTypeList", roomTypeService.findAll());
model.addObject("floorList", floorService.findAll());
model.setViewName("room/list");
return model;
}
/**
* 房间信息添加操作
* @param roomType
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> add(Room room){
Map<String, String> ret = new HashMap<String, String>();
if(room == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的房间信息!");
return ret;
}
if(StringUtils.isEmpty(room.getSn())){
ret.put("type", "error");
ret.put("msg", "房间编号不能为空!");
return ret;
}
if(room.getRoomTypeId() == null){
ret.put("type", "error");
ret.put("msg", "请选择房间类型!");
return ret;
}
if(room.getFloorId() == null){
ret.put("type", "error");
ret.put("msg", "请选择房间所属楼层!");
return ret;
}
if(isExist(room.getSn(), 0l)){
ret.put("type", "error");
ret.put("msg", "该房间编号已经存在!");
return ret;
}
if(roomService.add(room) <= 0){
ret.put("type", "error");
ret.put("msg", "添加失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "添加成功!");
return ret;
}
/**
* 房间信息编辑操作
* @param roomType
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> edit(Room room){
Map<String, String> ret = new HashMap<String, String>();
if(room == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的房间信息!");
return ret;
}
if(StringUtils.isEmpty(room.getSn())){
ret.put("type", "error");
ret.put("msg", "房间编号不能为空!");
return ret;
}
if(room.getRoomTypeId() == null){
ret.put("type", "error");
ret.put("msg", "请选择房间类型!");
return ret;
}
if(room.getFloorId() == null){
ret.put("type", "error");
ret.put("msg", "请选择房间所属楼层!");
return ret;
}
if(isExist(room.getSn(), room.getId())){
ret.put("type", "error");
ret.put("msg", "该房间编号已经存在!");
return ret;
}
if(roomService.edit(room) <= 0){
ret.put("type", "error");
ret.put("msg", "修改失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "修改成功!");
return ret;
}
/**
* 分页查询房间信息
* @param sn
* @param page
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.POST)
@ResponseBody
public Map<String,Object> list(
@RequestParam(name="sn",defaultValue="") String sn,
@RequestParam(name="status",required=false) Integer status,
@RequestParam(name="roomTypeId",required=false) Long roomTypeId,
@RequestParam(name="floorId",required=false) Long floorId,
Page page
){
Map<String,Object> ret = new HashMap<String, Object>();
Map<String,Object> queryMap = new HashMap<String, Object>();
queryMap.put("sn", sn);
queryMap.put("status", status);
queryMap.put("roomTypeId", roomTypeId);
queryMap.put("floorId", floorId);
queryMap.put("offset", page.getOffset());
queryMap.put("pageSize", page.getRows());
ret.put("rows", roomService.findList(queryMap));
ret.put("total", roomService.getTotal(queryMap));
return ret;
}
/**
* 房间信息删除操作
* @param id
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> delete(Long id){
Map<String, String> ret = new HashMap<String, String>();
if(id == null){
ret.put("type", "error");
ret.put("msg", "请选择要删除的信息!");
return ret;
}
try {
if(roomService.delete(id) <= 0){
ret.put("type", "error");
ret.put("msg", "删除失败,请联系管理员!");
return ret;
}
} catch (Exception e) {
// TODO: handle exception
ret.put("type", "error");
ret.put("msg", "该房间下存在订单信息,请先删除该房间下的所有订单信息!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "删除成功!");
return ret;
}
/**
* 判断房间编号是否存在
* @param sn
* @param id
* @return
*/
private boolean isExist(String sn,Long id){
Room findBySn = roomService.findBySn(sn);
if(findBySn == null)return false;
if(findBySn.getId().longValue() == id.longValue())return false;
return true;
}
}
Front page home controller:
/**
* 前台首页控制器
* @author yy
*
*/
@RequestMapping("/home")
@Controller
public class HomeController {
@Autowired
private RoomTypeService roomTypeService;
@Autowired
private AccountService accountService;
/**
* 前台首页
* @param model
* @param name
* @return
*/
@RequestMapping(value="/index",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model,
@RequestParam(name="name",defaultValue="") String name
){
Map<String,Object> queryMap = new HashMap<String, Object>();
queryMap.put("name", name);
queryMap.put("offset", 0);
queryMap.put("pageSize", 999);
model.addObject("roomTypeList", roomTypeService.findList(queryMap));
model.setViewName("home/index/index");
model.addObject("kw", name);
return model;
}
/**
* 登录页面
* @param model
* @return
*/
@RequestMapping(value="/login",method=RequestMethod.GET)
public ModelAndView login(ModelAndView model
){
model.setViewName("home/index/login");
return model;
}
/**
* 注册页面
* @param model
* @return
*/
@RequestMapping(value="/reg",method=RequestMethod.GET)
public ModelAndView reg(ModelAndView model
){
model.setViewName("home/index/reg");
return model;
}
/**
* 登录信息提交
* @param account
* @return
*/
@RequestMapping(value="/login",method=RequestMethod.POST)
@ResponseBody
public Map<String,String> loginAct(Account account,String vcode,HttpServletRequest request){
Map<String,String> retMap = new HashMap<String, String>();
if(account == null){
retMap.put("type", "error");
retMap.put("msg", "请填写正确的用户信息!");
return retMap;
}
if(StringUtils.isEmpty(account.getName())){
retMap.put("type", "error");
retMap.put("msg", "用户名不能为空!");
return retMap;
}
if(StringUtils.isEmpty(account.getPassword())){
retMap.put("type", "error");
retMap.put("msg", "密码不能为空!");
return retMap;
}
if(StringUtils.isEmpty(vcode)){
retMap.put("type", "error");
retMap.put("msg", "验证码不能为空!");
return retMap;
}
Object attribute = request.getSession().getAttribute("accountLoginCpacha");
if(attribute == null){
retMap.put("type", "error");
retMap.put("msg", "验证码过期,请刷新!");
return retMap;
}
if(!vcode.equalsIgnoreCase(attribute.toString())){
retMap.put("type", "error");
retMap.put("msg", "验证码错误!");
return retMap;
}
Account findByName = accountService.findByName(account.getName());
if(findByName == null){
retMap.put("type", "error");
retMap.put("msg", "用户名不存在!");
return retMap;
}
if(!account.getPassword().equals(findByName.getPassword())){
retMap.put("type", "error");
retMap.put("msg", "密码错误!");
return retMap;
}
if(findByName.getStatus() == -1){
retMap.put("type", "error");
retMap.put("msg", "该用户已被禁用,请联系管理员!");
return retMap;
}
request.getSession().setAttribute("account", findByName);
request.getSession().setAttribute("accountLoginCpacha", null);
retMap.put("type", "success");
retMap.put("msg", "登录成功!");
return retMap;
}
/**
* 注册信息提交
* @param account
* @return
*/
@RequestMapping(value="/reg",method=RequestMethod.POST)
@ResponseBody
public Map<String,String> regAct(Account account){
Map<String,String> retMap = new HashMap<String, String>();
if(account == null){
retMap.put("type", "error");
retMap.put("msg", "请填写正确的用户信息!");
return retMap;
}
if(StringUtils.isEmpty(account.getName())){
retMap.put("type", "error");
retMap.put("msg", "用户名不能为空!");
return retMap;
}
if(StringUtils.isEmpty(account.getPassword())){
retMap.put("type", "error");
retMap.put("msg", "密码不能为空!");
return retMap;
}
if(StringUtils.isEmpty(account.getMobile())){
retMap.put("type", "error");
retMap.put("msg", "手机号不能为空!");
return retMap;
}
if(isExist(account.getName())){
retMap.put("type", "error");
retMap.put("msg", "该用户名已经存在!");
return retMap;
}
if(accountService.add(account) <= 0){
retMap.put("type", "error");
retMap.put("msg", "注册失败,请联系管理员!");
return retMap;
}
retMap.put("type", "success");
retMap.put("msg", "注册成功!");
return retMap;
}
/**
* 退出登录
* @param request
* @return
*/
@RequestMapping(value="/logout",method=RequestMethod.GET)
public String logout(HttpServletRequest request){
request.getSession().setAttribute("account", null);
return "redirect:login";
}
private boolean isExist(String name){
Account account = accountService.findByName(name);
if(account == null)return false;
return true;
}
}
Room type management background controller:
/**
* 房间类型管理后台控制器
* @author yy
*
*/
@RequestMapping("/admin/room_type")
@Controller
public class RoomTypeController {
@Autowired
private RoomTypeService roomTypeService;
/**
* 房间类型管理列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.setViewName("room_type/list");
return model;
}
/**
* 房间类型信息添加操作
* @param roomType
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> add(RoomType roomType){
Map<String, String> ret = new HashMap<String, String>();
if(roomType == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的房间类型信息!");
return ret;
}
if(StringUtils.isEmpty(roomType.getName())){
ret.put("type", "error");
ret.put("msg", "房间类型名称不能为空!");
return ret;
}
roomType.setAvilableNum(roomType.getRoomNum());//默认房间数等于可用房间数
roomType.setBookNum(0);//设置预定数0
roomType.setLivedNum(0);//设置已入住数0
if(roomTypeService.add(roomType) <= 0){
ret.put("type", "error");
ret.put("msg", "添加失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "添加成功!");
return ret;
}
/**
* 房间类型信息编辑操作
* @param roomType
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> edit(RoomType roomType){
Map<String, String> ret = new HashMap<String, String>();
if(roomType == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的房间类型信息!");
return ret;
}
if(StringUtils.isEmpty(roomType.getName())){
ret.put("type", "error");
ret.put("msg", "房间类型名称不能为空!");
return ret;
}
RoomType existRoomType = roomTypeService.find(roomType.getId());
if(existRoomType == null){
ret.put("type", "error");
ret.put("msg", "未找到该数据!");
return ret;
}
int offset = roomType.getRoomNum() - existRoomType.getRoomNum();
roomType.setAvilableNum(existRoomType.getAvilableNum() + offset);
if(roomType.getAvilableNum() <= 0){
roomType.setAvilableNum(0);//没有可用房间
roomType.setStatus(0);//房型已满
if(roomType.getAvilableNum() + existRoomType.getLivedNum() + existRoomType.getBookNum() > roomType.getRoomNum()){
ret.put("type", "error");
ret.put("msg", "房间数设置不合理!");
return ret;
}
}
if(roomTypeService.edit(roomType) <= 0){
ret.put("type", "error");
ret.put("msg", "修改失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "修改成功!");
return ret;
}
/**
* 分页查询房间类型信息
* @param name
* @param page
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.POST)
@ResponseBody
public Map<String,Object> list(
@RequestParam(name="name",defaultValue="") String name,
@RequestParam(name="status",required=false) Integer status,
Page page
){
Map<String,Object> ret = new HashMap<String, Object>();
Map<String,Object> queryMap = new HashMap<String, Object>();
queryMap.put("name", name);
queryMap.put("status", status);
queryMap.put("offset", page.getOffset());
queryMap.put("pageSize", page.getRows());
ret.put("rows", roomTypeService.findList(queryMap));
ret.put("total", roomTypeService.getTotal(queryMap));
return ret;
}
/**
* 房间类型信息删除操作
* @param id
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> delete(Long id){
Map<String, String> ret = new HashMap<String, String>();
if(id == null){
ret.put("type", "error");
ret.put("msg", "请选择要删除的信息!");
return ret;
}
try {
if(roomTypeService.delete(id) <= 0){
ret.put("type", "error");
ret.put("msg", "删除失败,请联系管理员!");
return ret;
}
} catch (Exception e) {
// TODO: handle exception
ret.put("type", "error");
ret.put("msg", "该房间类型下存在房间信息,请先删除该房间类型下的所有房间信息!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "删除成功!");
return ret;
}
}
Get the source code: Download it from "Resources" on the homepage of the blog!