基于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 + layui+ maven等等。
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
@Autowired
private OrdersService ordersService;
@Autowired
private HotelOrdersService hotel_ordersService;
@Autowired
private HotelService hotelService;
@Autowired
private ScenicService scenicService;
/**
* 查询全部数据
* @return
*/
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,"修改成功");
}
}
/**
* 修改
* @param user
*/
@ResponseBody
@RequestMapping(value="/{id}",method= RequestMethod.PUT)
public Result update(User user, @PathVariable Long id ){
User oldUser=userService.findById(id);
user.setId(id);
Hotel scenic = hotelService.findById(id);
if (scenic!=null){
int valuestar = (Integer.valueOf(start)+Integer.valueOf(scenic.getStar()))/2;
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
* @param id
* @return
*/
@RequestMapping("/oneAttr")
public String One_attr(Model model,Long id){
@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,"验证码错误!");
}
userService.add(user);
return new Result(true,StatusCode.OK,"注册成功");
}
/**
*判断账号是否存在
* @param user
* @return
*/
@RequestMapping(value = "/checkPhone",method = RequestMethod.POST)
@ResponseBody
public Result checkPhone(User user){
String phone = user.getMobile();
if(!StringUtil.isMobile(phone)){
return new Result(false,StatusCode.ERROR,"请填写正确的手机号!");
}
* 控制器层
*
*/
@Controller
@CrossOrigin
@RequestMapping("/orders")
public class OrdersController {
@Autowired
private OrdersService ordersService;
@Autowired
private HotelOrdersService hotel_ordersService;
@Autowired
private HotelService hotelService;
@Autowired
userService.add(user);
return new Result(true,StatusCode.OK,"注册成功");
}
/**
*判断账号是否存在
* @param user
* @return
*/
@RequestMapping(value = "/checkPhone",method = RequestMethod.POST)
@ResponseBody
public Result checkPhone(User user){
* @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");
}
}
景点星级控制层:
/**
if(hotel1==null){
return new Result(false,StatusCode.ERROR,"评分更新失败!");
}
return new Result(true,StatusCode.OK,"评价成功!");
}
/**
* 景点评分
* @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,"未找到该景点!");
}
Integer totalStar = newScenic.getStart();
Integer currentStar = scenic.getStart();
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private HttpServletRequest request;
@Autowired
BCryptPasswordEncoder encoder;
/**
* 查询全部数据
*
* @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
Scenic scenic=scenicService.findById(id);
System.out.println(scenic.toString());
List<Hotel> hotels=hotelService.findByCountryLike(scenic.getContry());
Collections.sort(hotels, new Comparator<Hotel>() {
@Override
public int compare(Hotel o1, Hotel o2) {
if (o1.getStar()<o2.getStar()){
return 2;
}
if (o1.getStar().equals(o2.getStar()) ){
@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,"该邮箱已经被注册");
}
/**
* 用户登录
* @param loginMap
* @return
*/
@ResponseBody
@RequestMapping(value="/login",method=RequestMethod.POST)
public String localRefresh(Model model,Long id) {
Scenic scenic=scenicService.findById(id);
System.out.println(scenic.toString());
List<Hotel> hotels=hotelService.findByCountryLike(scenic.getContry());
Collections.sort(hotels, new Comparator<Hotel>() {
@Override
public int compare(Hotel o1, Hotel o2) {
if (o1.getStar()<o2.getStar()){
return 2;
}
if (o1.getStar().equals(o2.getStar()) ){
return 1;
}
return -1;
}
if (o1.getStar().equals(o2.getStar()) ){
return 1;
}
return -1;
}
});
if (hotels.size()>=4){
List newList=hotels.subList(0,3);
model.addAttribute("scenics",newList);
System.out.println("个数:"+newList.size());
}else {
model.addAttribute("scenics",hotels);
System.out.println("个数2:"+hotels.size());
}
return "page/product::table_refresh";
}
}
订单管理控制层:
/**
* 控制器层
*
return new Result(true,StatusCode.OK,"查询成功",ordersService.findById(id));
}
/**
* 分页+多条件查询
* @param searchMap 查询条件封装
* @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()) );
}
/**
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){
User user= (User) session.getAttribute("user");
List<HotelOrders> hotel_orders=hotel_ordersService.hotel_orders(user.getId());
return hotel_orders;
}
/**
* 根据ID查询
* @param id ID
* @return
*/
@ResponseBody
return new Result(false,0,"","");
}
}
/**
* 查询单个景点
* @param model
* @param id
* @return
*/
@RequestMapping("/oneAttr")
public String One_attr(Model model,Long id){
* @param search_key
* @return
*/
@RequestMapping("/search_attrs")
public String search_attrs(Model model,@RequestParam(value = "start" ,defaultValue = "0")Integer start,
@RequestParam(value = "limit" ,defaultValue = "6")Integer limit,
@RequestParam String search_key){
start=start<0?0:start;
Sort sort=new Sort(Sort.Direction.DESC,"id");
Pageable pageable=PageRequest.of(start,limit,sort);
Specification specification=new Specification() {
@Override
public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) {
List<Predicate> scenics=new ArrayList<>();
* 查询全部订单
* @return
*/
@ResponseBody
@RequestMapping(value = "/allorders",method = RequestMethod.POST)
public String findAllOrders(HttpSession session, Model model) throws ParseException {
User user= (User) session.getAttribute("user");
model.addAttribute("orders",ordersService.findOrders(user.getId().toString()));
return "index_header::table_refresh";
}
/**
* 查询全部订单
* @return
*/
@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
*/
@RequestMapping("/oneAttr")
public String One_attr(Model model,Long id){
Scenic scenic=scenicService.findById(id);
model.addAttribute("oneAttr",scenic);
return "page/product";
}
/**
* 景点模糊查询分页
* @param model
* @param start
* @param limit
* @param search_key
* @return
*/
model.addAttribute("totalElements",page.getTotalElements());
model.addAttribute("totalPages",page.getTotalPages());
model.addAttribute("first",page.isFirst());
model.addAttribute("last",page.isLast());
return "page/travel";
}
@RequestMapping("/local")
public String localRefresh(Model model,Long id) {
Scenic scenic=scenicService.findById(id);
System.out.println(scenic.toString());
* 根据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 size 页大小
* @return 分页结果
*/
@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST)
public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
Page<User> pageList = userService.findSearch(searchMap, page, size);
model.addAttribute("number",page.getNumber());
model.addAttribute("numberOfElements",page.getNumberOfElements());
model.addAttribute("size",page.getSize());
model.addAttribute("totalElements",page.getTotalElements());
model.addAttribute("totalPages",page.getTotalPages());
model.addAttribute("first",page.isFirst());
model.addAttribute("last",page.isLast());
return "page/travel";
}
@RequestMapping("/local")
public String localRefresh(Model model,Long id) {
Scenic scenic=scenicService.findById(id);
System.out.println(scenic.toString());
List<Hotel> hotels=hotelService.findByCountryLike(scenic.getContry());
Collections.sort(hotels, new Comparator<Hotel>() {
@Override
if(newScenic==null){
return new Result(false,StatusCode.ERROR,"未找到该景点!");
}
Integer totalStar = newScenic.getStart();
Integer currentStar = scenic.getStart();
if(currentStar<0){
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,"评分更新失败!");
* 用户注册
* @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,"验证码错误!");
}
userService.add(user);
@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
public String One_attr(Model model,Long id){
Scenic scenic=scenicService.findById(id);
model.addAttribute("oneAttr",scenic);
return "page/product";
}
/**
* 景点模糊查询分页
* @param model
* @param start
* @param limit
* @param search_key
* @return
user.setPassword(oldUser.getPassword());
userService.update(user);
return new Result(true,StatusCode.OK,"修改成功");
}
/**
* 修改
* @param user
*/
@RequestMapping(value="/change",method= RequestMethod.POST,consumes = "application/json")
public Result update(@RequestBody User user, HttpSession session){
User us= (User) session.getAttribute("user");
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");
if(!sCode.equalsIgnoreCase(code)){
return new Result(false,StatusCode.ERROR,"验证码错误!");
}
userService.add(user);