基于javaweb+mysql的springboot+mybatis酒店管理系统(JavaWeb JSP MySQL Servlet SSM SpringBoot Layui Ajax)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
技术框架
JavaBean MVC JSP SpringBoot MyBatis MySQL CSS JavaScript Layui Ajax
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
登录、注册、退出、用户模块、公告模块、商品模块、住宿模块、客房模块的增删改查管理
eclipse/MyEclipse运行:
idea运行:
response.sendRedirect("room_" + to + ".jsp");
}
/**
* 根据条件查询客房的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("roomList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(roomService.list(params).get("list")));
}
}
package com.demo.controller;
@Controller
@RequestMapping
public class UserController {
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(roomService.list(params).get("list")));
}
}
package com.demo.controller;
@Controller
@RequestMapping
public class UserController {
@Autowired
private UserService userService;
/**
* 增加用户
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(lodgingService.list(params).get("list")));
}
}
package com.demo.controller;
@Controller
@RequestMapping
public class NoticeController {
@Autowired
private NoticeService noticeService;
/**
* 增加公告
*
* @param response
* @param request
* @throws IOException
*/
}
request.getSession().setAttribute("alert_msg", msg);
request.getRequestDispatcher("reset_password.jsp").forward(request, response);
}
// 返回一个随机颜色(Color对象)
private Color getRandomColor(int minColor, int maxColor) {
Random random = new Random();
// 保存minColor最大不会超过255
if (minColor > 255)
minColor = 255;
// 保存minColor最大不会超过255
if (maxColor > 255)
maxColor = 255;
// 获得红色的随机颜色值
int red = minColor + random.nextInt(maxColor - minColor);
// 获得绿色的随机颜色值
int green = minColor + random.nextInt(maxColor - minColor);
// 获得蓝色的随机颜色值
int blue = minColor + random.nextInt(maxColor - minColor);
return new Color(red, green, blue);
}
}
package com.demo.controller;
@Controller
@RequestMapping
public class LodgingController {
@Autowired
private LodgingService lodgingService;
/**
* 增加住宿
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(goodService.list(params).get("list")));
}
}
package com.demo.controller;
@Controller
@RequestMapping
public class RoomController {
@Autowired
private RoomService roomService;
/**
* 增加客房
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("roomAdd")
public void add(Room vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
//调用Service层的增加(insert)方法
roomService.insert(vo);
this.redirectList(request, response);
}
/**
* 删除客房
*
* @param response
}
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(noticeService.list(params).get("list")));
}
}
package com.demo.controller;
@Controller
@RequestMapping
public class GoodController {
@Autowired
private GoodService goodService;
/**
* 增加商品
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("goodAdd")
public void add(Good vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
@Controller
public class AuthController extends HttpServlet {
@Autowired
private UserService userService;
@RequestMapping("authLogin")
public void login(HttpServletResponse response, HttpServletRequest request) throws IOException, ServletException {
String username = request.getParameter("username");
String password = request.getParameter("password");
String validationCode = request.getParameter("validationCode");
if (validationCode != null && !validationCode.equals(request.getSession().getAttribute("validationCode"))) {//验证码不通过
request.getSession().setAttribute("alert_msg", "错误:验证码不正确!");
request.getRequestDispatcher("login.jsp").forward(request, response);
return;
}
Map<String, Object> params = new HashMap();
List<User> list = (List<User>) userService.list(params).get("list");
for (User user : list) {
if (user.getUsername().equals(username) && user.getPassword().equals(password)) {//找到这个管理员了
request.getSession().setAttribute("loginUser", user);
request.getSession().setMaxInactiveInterval(Integer.MAX_VALUE);
request.getRequestDispatcher("user_list.jsp").forward(request, response);
return;
}
}
request.getSession().setAttribute("alert_msg", "错误:用户名或密码错误!");
request.getRequestDispatcher("login.jsp").forward(request, response);
/**
* 获取公告的详细信息(详情页面与编辑页面要显示该公告的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"noticeGet", "noticeEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
Notice vo = noticeService.get(id);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("notice_" + to + ".jsp");
}
/**
* 根据条件查询公告的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("noticeList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(noticeService.list(params).get("list")));
}
}
package com.demo.controller;
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("userEdit")
public void edit(User vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
userService.update(vo);
this.redirectList(request, response);
}
/**
* 获取用户的详细信息(详情页面与编辑页面要显示该用户的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"userGet", "userEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
User vo = userService.get(id);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("user_" + to + ".jsp");
}
/**
* 根据条件查询用户的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("userList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
}
/**
* 编辑用户
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("userEdit")
public void edit(User vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
userService.update(vo);
this.redirectList(request, response);
}
/**
* 获取用户的详细信息(详情页面与编辑页面要显示该用户的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"userGet", "userEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
User vo = userService.get(id);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("user_" + to + ".jsp");
}
/**
* 根据条件查询用户的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("userList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
* @param request
* @throws IOException
*/
@RequestMapping("userDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
userService.delete(Arrays.asList(id));
this.redirectList(request, response);
}
/**
* 编辑用户
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("userEdit")
public void edit(User vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
userService.update(vo);
this.redirectList(request, response);
}
/**
* 获取用户的详细信息(详情页面与编辑页面要显示该用户的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"userGet", "userEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
User vo = userService.get(id);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("user_" + to + ".jsp");
}
/**
* 根据条件查询用户的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("userList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"roomGet", "roomEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
Room vo = roomService.get(id);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("room_" + to + ".jsp");
}
/**
* 根据条件查询客房的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("roomList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(roomService.list(params).get("list")));
}
}
package com.demo.controller;
return;
}
}
request.getSession().setAttribute("alert_msg", "错误:用户名或密码错误!");
request.getRequestDispatcher("login.jsp").forward(request, response);
}
@RequestMapping("authRegister")
public void register(HttpServletResponse response, HttpServletRequest request) throws IOException, ServletException {
String username = request.getParameter("username");
String password = request.getParameter("password");
System.out.println("username=" + username);
System.out.println("password=" + password);
Map<String, Object> params = new HashMap();
params.put("startIndex", 0);
params.put("pageSize", Long.MAX_VALUE);
List<User> list = (List<User>) userService.list(params).get("list");
for (User user : list) {
if (user.getUsername().equals(username) /*&& user.getPassword().equals(password)*/) {//说明该用户名已存在,必须换个用户名才能注册
request.getSession().setAttribute("alert_msg", "错误:用户名已存在!");
request.getRequestDispatcher("register.jsp").forward(request, response);
return;
}
}
User vo = new User();
vo.setUsername(username);
vo.setPassword(password);
//vo.setUserType("普通用户");//需要设置一个默认值
userService.insert(vo);
request.getSession().setAttribute("alert_msg", "注册成功!用户名:[" + username + "]");
request.getRequestDispatcher("login.jsp").forward(request, response);
}
@RequestMapping("authLogout")
public void logout(HttpServletResponse response, HttpServletRequest request) throws IOException {
HttpSession session = request.getSession();
User user = (User) session.getAttribute("loginUser");
if (user != null) {
session.removeAttribute("loginUser");
}
response.sendRedirect("login.jsp");
}
@RequestMapping("authValidationCode")
public void validationCode(HttpServletResponse response, HttpServletRequest request) throws IOException {
String codeChars = "0123456789";// 图形验证码的字符集合,系统将随机从这个字符串中选择一些字符作为验证码
// 获得验证码集合的长度
@Controller
@RequestMapping
public class RoomController {
@Autowired
private RoomService roomService;
/**
* 增加客房
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("roomAdd")
public void add(Room vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
//调用Service层的增加(insert)方法
roomService.insert(vo);
this.redirectList(request, response);
}
/**
* 删除客房
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("roomDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
roomService.delete(Arrays.asList(id));
this.redirectList(request, response);
}
/**
* 编辑客房
@RequestMapping
public class UserController {
@Autowired
private UserService userService;
/**
* 增加用户
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("userAdd")
public void add(User vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
//调用Service层的增加(insert)方法
userService.insert(vo);
this.redirectList(request, response);
}
/**
* 删除用户
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("userDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
userService.delete(Arrays.asList(id));
this.redirectList(request, response);
}
/**
* 编辑用户
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("userEdit")
public void edit(User vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
userService.update(vo);
this.redirectList(request, response);
}
/**
* 获取用户的详细信息(详情页面与编辑页面要显示该用户的详情)并跳转回页面
@RequestMapping("userDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
userService.delete(Arrays.asList(id));
this.redirectList(request, response);
}
/**
* 编辑用户
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("userEdit")
public void edit(User vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
userService.update(vo);
this.redirectList(request, response);
}
/**
* 获取用户的详细信息(详情页面与编辑页面要显示该用户的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"userGet", "userEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
User vo = userService.get(id);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("user_" + to + ".jsp");
}
/**
* 根据条件查询用户的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("userList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("userList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(userService.list(params).get("list")));
}
}
package com.demo.util;
@Configuration
public class CustomWebMvcConfigurer implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/*");
}
public class LoginInterceptor implements HandlerInterceptor {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
HttpSession session = request.getSession();
//移除错误提示
session.removeAttribute("alert_msg");
//登录拦截
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("goodAdd")
public void add(Good vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
//调用Service层的增加(insert)方法
goodService.insert(vo);
this.redirectList(request, response);
}
/**
* 删除商品
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("goodDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
goodService.delete(Arrays.asList(id));
this.redirectList(request, response);
}
/**
* 编辑商品
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("goodEdit")
public void edit(Good vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
goodService.update(vo);
this.redirectList(request, response);
}
/**
* 获取商品的详细信息(详情页面与编辑页面要显示该商品的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"goodGet", "goodEditPre"})
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("userAdd")
public void add(User vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
//调用Service层的增加(insert)方法
userService.insert(vo);
this.redirectList(request, response);
}
/**
* 删除用户
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("userDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
userService.delete(Arrays.asList(id));
this.redirectList(request, response);
}
/**
* 编辑用户
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("userEdit")
public void edit(User vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
userService.update(vo);
this.redirectList(request, response);
}
/**
* 获取用户的详细信息(详情页面与编辑页面要显示该用户的详情)并跳转回页面
*
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(noticeService.list(params).get("list")));
}
}
package com.demo.controller;
@Controller
@RequestMapping
public class GoodController {
@Autowired
private GoodService goodService;
/**
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(roomService.list(params).get("list")));
}
}
package com.demo.controller;
@Controller
@RequestMapping
public class UserController {
@Autowired
private UserService userService;
/**
* 增加用户
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("userAdd")
public void add(User vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
//调用Service层的增加(insert)方法
/**
* 删除商品
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("goodDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
goodService.delete(Arrays.asList(id));
this.redirectList(request, response);
}
/**
* 编辑商品
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("goodEdit")
public void edit(Good vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
goodService.update(vo);
this.redirectList(request, response);
}
/**
* 获取商品的详细信息(详情页面与编辑页面要显示该商品的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"goodGet", "goodEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
Good vo = goodService.get(id);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("good_" + to + ".jsp");
}
/**
* 根据条件查询商品的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("goodList")
@Controller
@RequestMapping
public class RoomController {
@Autowired
private RoomService roomService;
/**
* 增加客房
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("roomAdd")
public void add(Room vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
//调用Service层的增加(insert)方法
roomService.insert(vo);
this.redirectList(request, response);
}
/**
* 删除客房
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("roomDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
/**
* 删除公告
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("noticeDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
noticeService.delete(Arrays.asList(id));
this.redirectList(request, response);
}
/**
* 编辑公告
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("noticeEdit")
public void edit(Notice vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
noticeService.update(vo);
this.redirectList(request, response);
}
/**
* 获取公告的详细信息(详情页面与编辑页面要显示该公告的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"noticeGet", "noticeEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
Notice vo = noticeService.get(id);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("notice_" + to + ".jsp");
}
/**
* 根据条件查询公告的列表并跳转回页面
*
Serializable id = request.getParameter("id");//取出主键id
Good vo = goodService.get(id);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("good_" + to + ".jsp");
}
/**
* 根据条件查询商品的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("goodList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(goodService.list(params).get("list")));
}
}
package com.demo.controller;