Bootstrap

Java项目:民宿管理系统(java+SSM+JSP+bootstrap+jQuery+mysql)

源码获取:博客首页 "资源" 里下载!

ssm民宿管理系统网页前后端

项目介绍

游客功能:用户注册、登录、登录权限拦截、按名称搜索房间、支付流程、查看订单信息和状态、评论预定过的房间,并自动修改订单状态、查看统计剩余房间数量,数量为0时不可预定
管理员功能:房间分类管理、房间管理、订单管理

高级功能:各种列表清单的导出和打印功能、订单组合条件查询

功能清单

游客功能

+ 用户注册、登录
+ 登录权限拦截
+ 按名称搜索房间
+ 支付流程
+ 查看订单信息和状态
+ 评论预定过的房间,并自动修改订单状态

+ 查看统计剩余房间数量,数量为0时不可预定

管理员功能

> 房间分类管理
+ 类型的删除、修改、查询(准备添加增添功能,即图片上传功能)
+ 类型所含属性的增删改查
+ 房间分类图片上传

> 房间管理
+ 房间增删改导印统
+ 查询已上传房间的所有照片
+ 房间的配套设施属性设置
+ 房间价格(原价、活动价)、名称、描述等属性设置
+ 房间存量统计

> 订单管理
+ 订单信息修改、删除
+ 订单组合条件查询

+ 筛选出超时未评论的订单

高级功能
+ 各种列表清单的导出和打印功能

+ 订单组合条件查询

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 5.7版本;

技术栈

1. 后端:Spring SpringMVC MyBatis

2. 前端:JSP+bootstrap+jQuery

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 将项目中applicationContext.xml配置文件中的数据库配置改为自己的配置;
3. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行;

4. 运行项目,输入localhost:8080/ 登录

 

 

 

 

 

 

订单管理控制层: 

@RestController
public class OrderController
{
	private final OrderService orderservice;

	private final OrderRoomService orderroomservice;

	private final RoomidService roomidservice;

	private final RoomService roomservice;

	private final OrderHistoryService orderHistoryService;

	private final FinanceService financeService;

	@Autowired
	public OrderController(OrderService orderservice,OrderRoomService orderroomservice,RoomidService roomidservice,
						   RoomService roomservice,OrderHistoryService orderHistoryService,
						   FinanceService financeService)
	{
		this.orderservice=orderservice;
		this.orderroomservice=orderroomservice;
		this.roomidservice=roomidservice;
		this.roomservice=roomservice;
		this.orderHistoryService=orderHistoryService;
		this.financeService=financeService;
	}

	/**
	 * 查找所有订单
	 *
	 * @return 返回现有的全部订单
	 */
	@RequestMapping("/order/orderlist")
	public Result<List<Order>> orderList()
	{
		return ResultReturn.success(orderservice.findAll());
	}

	/**
	 * 根据订单号查找对应订单信息
	 *
	 * @param orderno 订单号
	 * @return 返回订单号对应的订单
	 */
	@RequestMapping("/order/searchOne/{orderno}")
	public Result<Order> orderSearchOne(@PathVariable("orderno") int orderno)
	{
		return ResultReturn.success(orderservice.findByOrderNo(orderno));
	}

	/**
	 * 更新订单信息
	 *
	 * @param orderno 订单号
	 * @param name    姓名
	 * @param id      身份证
	 * @param phone   电话号码
	 * @param isenter 是否入住
	 * @return 返回更新后的订单
	 */
	@RequestMapping("/order/update/{orderno}")
	public Result<Order> orderUpdate(@PathVariable("orderno") int orderno,@RequestParam("name") String name,
							  @RequestParam("id") String id,@RequestParam("phone") String phone,
							  @RequestParam("isenter") int isenter)
	{
		Order o=orderservice.findByOrderNo(orderno);
		o.setName(name);
		o.setId(id);
		o.setPhone(phone);
		o.setIsenter(isenter);
		return ResultReturn.success(orderservice.save(o));
	}

	/**
	 * 插入订单
	 *
	 * @param
	 * @return
	 */
	@RequestMapping("/order/insert")
	public Result orderInsert(@RequestParam("name") String name,
							  @RequestParam("id") String id, @RequestParam("phone") String phone,
							  @RequestParam("starttime") String starttime, @RequestParam("endtime") String endtime,
							  @RequestParam("isenter") int isenter, @RequestParam("ismenber") int ismenber,
							  @RequestParam("roomcount") int roomcount, @RequestParam("roomnos") String roomnos,
							  @RequestParam("price") int price)
	{
		Order o = new Order();
		o.setName(name);
		o.setId(id);
		o.setPhone(phone);

		// 将String类型格式化为timestamp
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		try {
			Date startT = sdf.parse(starttime);
			Date endT = sdf.parse(endtime);
			o.setStarttime(new Timestamp(startT.getTime()));
			o.setEndtime(new Timestamp(endT.getTime()));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		o.setIsenter(isenter);
		o.setIsmenber(ismenber);
		o.setRoomcount(roomcount);
		o.setPrice(price);
		Order saveO = orderservice.save(o);

		List<Order> orderList = orderservice.findAllSortByOrderNo();
		Order lastOrder = orderList.get(0);

		// 房间号处理
		String roomStrArray[] = roomnos.split("\\|"); //“.”和“|”都是转义字符,必须得加”\\”;
		for (int i=0;i<roomStrArray.length;i++){
			System.out.println(roomStrArray[i]);
			OrderRoom orderRoom = new OrderRoom();
			orderRoom.setOrderno(lastOrder.getOrderno());
			orderRoom.setRoomno(Integer.parseInt(roomStrArray[i]));
			orderroomservice.save(orderRoom);
		}

		return ResultReturn.success(saveO);
	}

	/**
	 * 删除订单
	 *
	 * @param orderno 订单号
	 * @return 返回成功
	 */
	@RequestMapping("/order/delete/{orderno}")
	public Result orderDelete(@PathVariable("orderno") int orderno)
	{
		Order o=orderservice.findByOrderNo(orderno);
		orderservice.delete(o);
		return ResultReturn.success();
	}

	/**
	 * 根据订单号查找所有的订单中的所有房间
	 *
	 * @param orderno 订单号
	 * @return 返回房间列表
	 */
	@RequestMapping("/order/orderroom/{orderno}")
	public Result<List<OrderRoom>> orderroomList(@PathVariable("orderno") int orderno)
	{
		return ResultReturn.success(orderroomservice.findAll(orderno));
	}

	/**
	 * 根据订单-房间序号查找对应记录
	 *
	 * @param orno 订单-房间表的序号
	 * @return 返回对应的订单-房间信息
	 */
	@RequestMapping("/order/orderroom/orderroomSearchOne/{orno}")
	public Result<OrderRoom> orderroomSearchOne(@PathVariable("orno") int orno)
	{
		return ResultReturn.success(orderroomservice.findOne(orno));
	}

	/**
	 * OrderRoom表更新
	 *
	 * @param orno         编号
	 * @param brand        车牌号
	 * @param roomnoAfter  之前的房间号
	 * @param roomnoBefore 现在重新设定的房间号(计算价格需要)
	 * @param orderno      订单号(保存当前订单的价格需要)
	 * @return 返回保存的orderroom对象
	 */
	@RequestMapping("/order/orderroom/update/{orno}")
	public Result orderroomUpdate(@PathVariable("orno") int orno,@RequestParam("brand") String brand,
								  @RequestParam("roomnoAfter") int roomnoAfter,
								  @RequestParam("roomnoBefore") int roomnoBefore,@RequestParam("orderno") int orderno)
	{
		OrderRoom or=orderroomservice.findOne(orno);
		or.setBrand(brand);
		or.setRoomno(roomnoAfter);

		List<Roomid> ri=roomidservice.findAll(roomnoBefore);
		for (Roomid aRi : ri)
		{
			aRi.setRoomno(roomnoAfter);
		}
		roomidservice.saveAll(ri);

		Order order=orderservice.findByOrderNo(orderno);
		Room roomAfter=roomservice.findByRoom(roomnoAfter);
		Room roomBefore=roomservice.findByRoom(roomnoBefore);
		order.setPrice(order.getPrice()+roomAfter.getPrice()-roomBefore.getPrice());
		orderservice.save(order);

		return ResultReturn.success(orderroomservice.save(or));
	}

	//roomid表查看
	@RequestMapping("/order/orderroom/roomid/list/{roomno}")
	public Result<List<Roomid>> roomidList(@PathVariable("roomno") int roomno)
	{
		return ResultReturn.success(roomidservice.findAll(roomno));
	}

	/**
	 * 根据房间-身份证表的序号查找对应信息
	 *
	 * @param rino 房间-身份证表的序号
	 * @return 返回对应信息
	 */
	@RequestMapping("/order/orderroom/roomid/roomidSearchOne/{rino}")
	public Result<Roomid> roomidSearchOne(@PathVariable("rino") int rino)
	{
		return ResultReturn.success(roomidservice.findByRino(rino));
	}

	/**
	 * 房间-身份证表更新
	 *
	 * @param rino 房间-身份证表的序号
	 * @param name 姓名
	 * @param id   身份证
	 * @return 返回更改后的信息
	 */
	@RequestMapping("/order/orderroom/roomid/update/{rino}")
	public Result roomidUpdate(@PathVariable("rino") int rino,@RequestParam("name") String name,
							   @RequestParam("id") String id)
	{
		Roomid ri=roomidservice.findByRino(rino);
		ri.setId(id);
		ri.setName(name);
		return ResultReturn.success(roomidservice.save(ri));
	}

	/**
	 * 寻找未入住的房间号列表
	 *
	 * @return 返回房间号列表
	 */
	@RequestMapping("/order/orderroom/roomid/getEmptyRoomno")
	public Result<List<Integer>> getEmptyRoomno()
	{
		List<Roomid> ri=roomidservice.findAllWithoutparam();
		List<Integer> q=new ArrayList<>(ri.size());
		for (Roomid aRi : ri)
		{
			q.add(aRi.getRoomno());
		}
		List<Room> r=roomservice.getEmpty(q);
		List<Integer> sum=new ArrayList<>();
		for (Room aR : r)
		{
			sum.add(aR.getRoomno());
		}
		return ResultReturn.success(sum);
	}

	/**
	 * 结算订单
	 *
	 * @param orderno 订单号
	 * @return 返回订单结算结果
	 * @throws HotelException 抛出订单未入住异常 code: 601
	 */
	@RequestMapping("/order/settle/{orderno}")
	public Result<OrderHistory> orderSettle(@PathVariable("orderno") int orderno) throws HotelException
	{
		Order order=orderservice.findByOrderNo(orderno);
		if(order.getIsenter()==1)
		{
			Order orderTemp=new Order(order);
			orderservice.delete(order);

			return new OrderHistoryController(orderHistoryService,financeService).orderHistoryInsert(orderTemp);
		}
		else
		{
			throw new HotelException(ExceptionType.ORDER_ISENTER_ERROR.getCode(),
					ExceptionType.ORDER_ISENTER_ERROR.getMsg());
		}

	}
}

房间信息管理控制层:

@RestController
public class RoomInformationController {
    private final StandardService standservice;

    private final RoomService roomservice;

    @Autowired
    public RoomInformationController(StandardService standservice,RoomService roomservice)
    {
        this.standservice=standservice;
        this.roomservice=roomservice;
    }

    //查询房间标准列表
    @RequestMapping("/standard")
    public Result<List<Standard>> standardList() {
        return ResultReturn.success(standservice.getAll());
    }

    //添加客房标准
    @RequestMapping("/standard/add")
    public Result standardAdd(@RequestParam("stdname") String stdname,
                              @RequestParam("roomarea") int roomarea,@RequestParam("bedno") int bedno,
                              @RequestParam("equip1") String equip1,@RequestParam("equip2") String equip2) {
        Standard standard = saveStandard(stdname,roomarea,bedno,equip1,equip2);
        return ResultReturn.success(standservice.save(standard));
    }

    //删除客房标准
    @RequestMapping("/standard/deletebystdno")
    public Result deleteByStdNo(@RequestParam("stdno") int stdno){
        standservice.delete(standservice.findByStandard(stdno));
        return ResultReturn.success();
    }
    //查询客房信息列表
    @RequestMapping("/room/roomlist")
    public Result<List<Room>> roomList() {
        return ResultReturn.success(roomservice.getAll()) ;
    }

    //添加客房信息
    @PostMapping("/room/add")
    public Result roomAdd(@RequestParam("roomno") int roomno,@RequestParam("type") int type,
						  @RequestParam("price") int price,@RequestParam("ifwindow") int ifwindow,
						  @RequestParam("comment") String comment) {
        System.out.println("qian"+roomno+"   "+roomservice.findByRoom(roomno));
        //需要做检测
        if(roomservice.findByRoom(roomno)==null) {
            System.out.println(roomno);
            Room r = saveRoom(roomno, type, price, ifwindow, comment);
            return ResultReturn.success(roomservice.save(r));
        }
        else
            return ResultReturn.error(2,"客房编号已存在!");
    }

    //更新已有信息
    @RequestMapping("/room/update/{roomno}")
    public Result roomUpdate(@PathVariable("roomno") int roomno,@RequestParam("type") int type,
							 @RequestParam("price") int price,@RequestParam("ifwindow") int ifwindow,
							 @RequestParam("comment") String comment) {
        //需要先查询是否存在
        if(roomservice.findByRoom(roomno)==null) {
            return ResultReturn.error(1,"cant't find roomno!");
        }
        else {
            Room r = saveRoom(roomno, type, price, ifwindow, comment);
            return ResultReturn.success(roomservice.save(r));
        }
    }

    @RequestMapping("/room/searchOne/{roomno}")
    public Result roomSerchOne(@PathVariable("roomno") int roomno) {
        Room r = roomservice.findByRoom(roomno);
        if(r == null) {
            return ResultReturn.error(1,"it's not exist!");
        }
        else {
            return ResultReturn.success(r);
        }
    }

    @RequestMapping("/room/delete/{roomno}")
    public Result roomDelete(@PathVariable("roomno") int roomno) {
        //需要先查询是否存在
        Room r = roomservice.findByRoom(roomno);
        if(r == null) {
            return ResultReturn.error(1,"it's not exist, you can't delete!");
        }
        else {
            roomservice.delete(r);
            return ResultReturn.success(r);
        }
    }

    public Room saveRoom(int roomno,int type,int price,int ifwindow,String comment) {
        Room r = new Room();
        r.setRoomno(roomno);
        r.setType(type);
        r.setPrice(price);
        r.setIfwindow(ifwindow);
        r.setComment(comment);
        return r;
    }

    public Standard saveStandard(String stdname,int roomarea,int bedno,String equip1,String equip2){
        Standard s = new Standard();
        s.setStdname(stdname);
        s.setRoomerea(roomarea);
        s.setBedno(bedno);
        s.setEquip1(equip1);
        s.setEquip2(equip2);
        return s;
    }
}
@RestController
public class MemberController
{
	private final MemberService memberService;

	@Autowired
	public MemberController(MemberService memberService)
	{
		this.memberService=memberService;
	}

	/**
	 *
	 * @return 返回会员列表
	 */
	@RequestMapping("/member/getall")
	public Result<List<Member>> getAll()
	{
		return ResultReturn.success(memberService.findAll());
	}

	/**
	 *
	 * @param phone 手机号码
	 * @return 返回对应会员
	 */
	@RequestMapping("/member/getbyphone")
	public Result<Member> getByPhone(@RequestParam("phone") String phone)
	{
		return ResultReturn.success(memberService.findByPhone(phone));
	}

	/**
	 *
	 * @param id 身份证
	 * @return 返回对应会员
	 */
	@RequestMapping("/member/getbyid")
	public Result<Member> getByID(@RequestParam("id") String id)
	{
		return ResultReturn.success(memberService.findByID(id));
	}

	/**
	 *
	 * @param phone 电话号码
	 * @param name 姓名
	 * @param id 身份证
	 * @return 返回对应会员
	 */
	@RequestMapping("/member/insert")
	public Result<Member> insert(@RequestParam("phone") String phone,
								 @RequestParam("name") String name,
								 @RequestParam("id") String id)
	{
		Member member=new Member();

		member.setPhone(phone);
		member.setName(name);
		member.setId(id);
		member.setEntertime(new Timestamp(System.currentTimeMillis()));

		return ResultReturn.success(memberService.save(member));
	}

	/**
	 *
	 * @param phone 电话号码
	 * @return 返回成功
	 */
	@RequestMapping("/member/deletebyphone")
	public Result deleteByPhone(@RequestParam("phone") String phone)
	{
		memberService.delete(memberService.findByPhone(phone));
		return ResultReturn.success();
	}

	/**
	 *
	 * @param id 身份证
	 * @return 返回成功
	 */
	@RequestMapping("/member/deletebyid")
	public Result deleteByID(@RequestParam("id") String id)
	{
		memberService.delete(memberService.findByID(id));
		return ResultReturn.success();
	}
}

用户管理控制器:

/**
 * 用户管理控制器
 */
@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;
	}
}

源码获取:博客首页 "资源" 里下载! 

;