基于javaweb+jsp的酒店管理系统(前台预定+后台管理)(java+SSM+jsp+mysql+maven)
一、项目简述
功能介绍: 前台用户端:用户注册登录,房间展示,房间分类,房间 按价格区间查询,房间评论,房间预订等等 后台管理端:用户信息查询,房间分类管理,房间信息维 护,用户评论查看,入住结账等等
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + maven等等。
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
/**
*查询星级
* @return
*/
@ResponseBody
@RequestMapping(value = "/star",method = RequestMethod.POST)
public Result judgeStar(String id,String start){
System.out.println(id+"===="+start);
Optional<Scenic> s = scenicDao.findById(id);
if (s.isPresent()){
Scenic scenic = s.get();
int valuestar = (Integer.valueOf(start)+Integer.valueOf(scenic.getStart()))/2;
scenic.setStart(valuestar);
scenicDao.save(scenic);
System.out.println("数据不为空!");
return new Result(true,1,"","");
}else {
System.out.println("数据为空!");
return new Result(false,0,"","");
}
}
}
/**
* 酒店评分
* @param hotel
* @return
*/
@ResponseBody
@PostMapping("/hotelOrderStar")
public Result hotelOrderStar(Hotel hotel,@RequestParam("orderId")Long orderId){
Long id = hotel.getId();
Hotel newHotel = hotelService.findById(id);
if(newHotel==null){
return new Result(false,StatusCode.ERROR,"未找到该酒店!");
@ResponseBody
@RequestMapping(value = "/star",method = RequestMethod.POST)
public Result judgeStar(String id,String start){
System.out.println(id+"===="+start);
Optional<Scenic> s = scenicDao.findById(id);
if (s.isPresent()){
Scenic scenic = s.get();
int valuestar = (Integer.valueOf(start)+Integer.valueOf(scenic.getStart()))/2;
scenic.setStart(valuestar);
scenicDao.save(scenic);
System.out.println("数据不为空!");
return new Result(true,1,"","");
}else {
System.out.println("数据为空!");
return new Result(false,0,"","");
}
}
/**
* 删除
* @param id
*/
@RequestMapping(value="/{id}",method= RequestMethod.DELETE)
public Result delete(@PathVariable String id ){
userService.deleteById(id);
return new Result(true,StatusCode.OK,"删除成功");
}
/**
* 用户注册
* @param code
* @param user
* @return
*/
@ResponseBody
@RequestMapping(value = "/register/",method = RequestMethod.POST)
@ResponseBody
@RequestMapping(value ="/add",method=RequestMethod.POST)
public Result add(Orders orders, HttpSession session){
//获取数量
User user = (User) session.getAttribute("user");
if (user == null){
return new Result(false,StatusCode.ACCESSERROR,"请登录");
}
return ordersService.add(orders,user.getId(),orders.getId(),orders.getQty());
}
/**
* 修改
* @param
*/
@ResponseBody
@RequestMapping(value="/{id}",method= RequestMethod.PUT)
public Result update(@PathVariable Long id){
ordersService.updateStatus(id);
return new Result(true,StatusCode.OK,"修改成功");
if(!StringUtil.isMobile(phone)){
return new Result(false,StatusCode.ERROR,"请填写正确的手机号!");
}
User userphone= userService.findByMobile(phone);
if (userphone == null){
return new Result(true,StatusCode.OK,"该手机号可以注册");
}
return new Result(false,StatusCode.ERROR,"该手机号已经被注册");
}
/**
* 邮箱验证
* @param user
}else {
User user = userService.findByNameAndPassword(loginMap.get("login"),loginMap.get("password"));
if(user!=null){
request.getSession().setAttribute("user",user);
Map map=new HashMap();
map.put("name",user.getName());//姓名
return new Result(true,StatusCode.OK,"登陆成功",map);
}else{
return new Result(false,StatusCode.LOGINERROR,"用户名或密码错误");
}
}
}
*/
@RequestMapping(value = "/email",method = RequestMethod.POST)
@ResponseBody
public Result findemail(User user){
String email = user.getEmail();
if(!StringUtil.emailFormat(email)){
return new Result(true,StatusCode.ERROR,"请填写正确的邮箱格式");
}
User useremail= userService.findByEmail(email);
if (useremail == null){
return new Result(true,StatusCode.OK,"该邮箱可以注册");
}
return new Result(false,StatusCode.ERROR,"该邮箱已经被注册");
}
/**
* 用户登录
return 2;
}
if (o1.getStar().equals(o2.getStar()) ){
return 1;
}
return -1;
}
});
if (hotels.size()>=4){
List newList=hotels.subList(0,3);
hotelDao.save(scenic);
System.out.println("数据不为空!");
return new Result(true,1,"","");
}else {
System.out.println("数据为空!");
return new Result(false,0,"","");
}
}
/**
* 查询单个景点
* @param model
* @param id
* @return
@ResponseBody
@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST)
public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
Page<Orders> pageList = ordersService.findSearch(searchMap, page, size);
return new Result(true,StatusCode.OK,"查询成功", new PageResult<Orders>(pageList.getTotalElements(), pageList.getContent()) );
}
/**
* 根据条件查询
* @param searchMap
* @return
*/
@ResponseBody
@RequestMapping(value="/search",method = RequestMethod.POST)
public Result findSearch( @RequestBody Map searchMap){
* 用户注销
* @param request
* @param response
* @throws IOException
*/
@RequestMapping(value="/logout",method=RequestMethod.GET)
public void logout(HttpServletRequest request,HttpServletResponse response) throws IOException {
request.getSession().setAttribute("user", null);
response.sendRedirect(request.getContextPath() + "/dist/view");
}
}
星级景点控制层:
/**
* 星级景点控制层
*/
@Controller
}
}
星级景点控制层:
/**
* 星级景点控制层
*/
@Controller
@CrossOrigin
@RequestMapping("/travel")
public class RecomTravelController {
@Autowired
private ScenicService scenicService;
@Autowired
private ScenicDao scenicDao;
@Autowired
private HotelService hotelService;
@Autowired
private HotelDao hotelDao;
/**
*查询星级
* @return
totalStar=currentStar+totalStar;
int avgStar = totalStar / commentCount;
hotel.setCommentCount(commentCount);
hotel.setStar(avgStar);
Integer hotel1 = hotelService.updateStar(hotel);
hotel_ordersService.updateStarStatus(orderId);
if(hotel1==null){
return new Result(false,StatusCode.ERROR,"评分更新失败!");
}
return new Result(true,StatusCode.OK,"评价成功!");
}
/**
/**
* 用户注销
* @param request
* @param response
* @throws IOException
*/
@RequestMapping(value="/logout",method=RequestMethod.GET)
public void logout(HttpServletRequest request,HttpServletResponse response) throws IOException {
request.getSession().setAttribute("user", null);
response.sendRedirect(request.getContextPath() + "/dist/view");
}
}
星级景点控制层:
/**
* 星级景点控制层
*/
@Controller
@CrossOrigin
* @param page 页码
* @param size 页大小
* @return 分页结果
*/
@ResponseBody
@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST)
public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
Page<Orders> pageList = ordersService.findSearch(searchMap, page, size);
return new Result(true,StatusCode.OK,"查询成功", new PageResult<Orders>(pageList.getTotalElements(), pageList.getContent()) );
}
/**
* 根据条件查询
* @param searchMap
* @return
*/
@ResponseBody
@RequestMapping(value="/search",method = RequestMethod.POST)
public Result findSearch( @RequestBody Map searchMap){
return new Result(true,StatusCode.OK,"查询成功",ordersService.findSearch(searchMap));
}
return new Result(true,StatusCode.OK,"修改成功");
}
/**
* 删除
* @param id
*/
@RequestMapping(value="/{id}",method= RequestMethod.DELETE)
public Result delete(@PathVariable String id ){
userService.deleteById(id);
return new Result(true,StatusCode.OK,"删除成功");
}
/**
* 用户注册
* @param code
* @param user
* @return
*/
@ResponseBody
@RequestMapping(value = "/register/",method = RequestMethod.POST)
public Result regist(@RequestParam(name = "code") String code,User user,HttpServletRequest request){
String sCode = (String) request.getSession().getAttribute("user_register_email_code");
return new Result(false,StatusCode.ERROR,"该邮箱已经被注册");
}
/**
* 用户登录
* @param loginMap
* @return
*/
@ResponseBody
@RequestMapping(value="/login",method=RequestMethod.POST)
public Result login(@RequestParam Map<String,String> loginMap,HttpServletRequest request){
String mobile = loginMap.get("login");
if (StringUtil.isMobile(mobile)){
User user = userService.findByMobileAndPassword(loginMap.get("login"),loginMap.get("password"));
if(user!=null){
request.getSession().setAttribute("user",user);
Map map=new HashMap();
return new Result(true,StatusCode.OK,"登陆成功");
}else{
return new Result(false,StatusCode.LOGINERROR,"用户名或密码错误");
}
return new Result(false,StatusCode.ERROR,"请选择评分!");
}
Integer commentCount = newScenic.getCommentCount();
commentCount=commentCount+1;
totalStar=currentStar+totalStar;
int avgStar = totalStar / commentCount;
scenic.setCommentCount(commentCount);
scenic.setStart(avgStar);
Integer scenic1 = scenicService.updateStar(scenic);
ordersService.updateStarStatus(orderId);
if(scenic1==null){
return new Result(false,StatusCode.ERROR,"评分更新失败!");
}
return new Result(true,StatusCode.OK,"评价成功!");
}
}
用户控制器层:
/**
* 控制器层
*
* @param model
* @param id
* @return
*/
@RequestMapping("/oneAttr")
public String One_attr(Model model,Long id){
Scenic scenic=scenicService.findById(id);
model.addAttribute("oneAttr",scenic);
return "page/product";
}
/**
if(newHotel==null){
return new Result(false,StatusCode.ERROR,"未找到该酒店!");
}
Integer currentStar = hotel.getStar();
Integer totalStar = newHotel.getStar();
if(currentStar<0){
return new Result(false,StatusCode.ERROR,"请选择评分!");
}
Integer commentCount = newHotel.getCommentCount();
commentCount=commentCount+1;
totalStar=currentStar+totalStar;
int avgStar = totalStar / commentCount;
hotel.setCommentCount(commentCount);
hotel.setStar(avgStar);
Integer hotel1 = hotelService.updateStar(hotel);
hotel_ordersService.updateStarStatus(orderId);
if(hotel1==null){
return new Result(false,StatusCode.ERROR,"评分更新失败!");
}
return new Result(true,StatusCode.OK,"评价成功!");
}
/**
* 景点评分
* @param scenic
scenic.setStar(valuestar);
hotelDao.save(scenic);
System.out.println("数据不为空!");
return new Result(true,1,"","");
}else {
System.out.println("数据为空!");
return new Result(false,0,"","");
}
}
/**
* 查询单个景点
* @param model
/**
* 查询全部数据
*
* @return
*/
@RequestMapping(value = "userList",method = RequestMethod.GET)
public Result findAll() {
List<User> all = userService.findAll();
return new Result(true, StatusCode.OK, "查询成功",all,all.size());
}
/**
* 根据ID查询
*
* @param id ID
* @return
*/
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public Result findById(@PathVariable Long id) {
return new Result(true, StatusCode.OK, "查询成功", userService.findById(id));
}
/**
* 分页+多条件查询
* @param searchMap 查询条件封装
* @param page 页码
* @param loginMap
* @return
*/
@ResponseBody
@RequestMapping(value="/login",method=RequestMethod.POST)
public Result login(@RequestParam Map<String,String> loginMap,HttpServletRequest request){
String mobile = loginMap.get("login");
if (StringUtil.isMobile(mobile)){
User user = userService.findByMobileAndPassword(loginMap.get("login"),loginMap.get("password"));
if(user!=null){
request.getSession().setAttribute("user",user);
Map map=new HashMap();
return new Result(true,StatusCode.OK,"登陆成功");
}else{
return new Result(false,StatusCode.LOGINERROR,"用户名或密码错误");
}
}
}
/**
* 用户注销
* @param request
* @param response
* @throws IOException
*/
@RequestMapping(value="/logout",method=RequestMethod.GET)
public void logout(HttpServletRequest request,HttpServletResponse response) throws IOException {
request.getSession().setAttribute("user", null);
response.sendRedirect(request.getContextPath() + "/dist/view");
}
}
星级景点控制层:
/**
* 星级景点控制层
*/
@Controller
@CrossOrigin
* @param scenic
* @return
*/
@ResponseBody
@PostMapping("/travelOrderStar")
public Result travelOrderStar(Scenic scenic,@RequestParam("orderId")Long orderId){
Long id = scenic.getId();
Scenic newScenic = scenicService.findById(id);
if(newScenic==null){
return new Result(false,StatusCode.ERROR,"未找到该景点!");
@ResponseBody
@RequestMapping(value = "/allorder",method = RequestMethod.POST)
public List<Orders> findAllOrder(HttpSession session) throws ParseException {
User user= (User) session.getAttribute("user");
return ordersService.findOrders(user.getId().toString());
}
/**
* 查询全部订单
* @return
*/
@ResponseBody
@RequestMapping(value = "/allorderhotel",method = RequestMethod.POST)
public List<HotelOrders> findAllOrderHotel(HttpSession session){
/**
* 用户注册
* @param code
* @param user
* @return
*/
@ResponseBody
@RequestMapping(value = "/register/",method = RequestMethod.POST)
public Result regist(@RequestParam(name = "code") String code,User user,HttpServletRequest request){
String sCode = (String) request.getSession().getAttribute("user_register_email_code");
if(!sCode.equalsIgnoreCase(code)){
return new Result(false,StatusCode.ERROR,"验证码错误!");
}
适用
课程设计,大作业,毕业设计,项目练习,学习演示等