基于springboot房屋租赁管理系统源码

本文介绍了一款使用JSP、SpringBoot、SpringMVC和Mybatis开发的房屋租赁管理平台,实现了现代化的租赁流程,包括用户管理、房源管理、订单处理等功能,旨在提升效率和办公自动化。
摘要由CSDN通过智能技术生成

随着我国市场经济的快速增长和生活中各行各业都向着互联网发展,一般的房屋服务已经不能满足人们的需要,现在年轻人工作租房占很大一部分,年轻人不爱出门,每天对着电脑手机工作、学习、娱乐等,不在是传统的租房方式。如何利用先进的管理手段,提高房屋租赁水平,是当今社会所面临的一个重要问题。本文通过用JSP技术并采用Springboot、SpringMVC、Mybatis的Java流行框架开发出一款房屋租赁管理平台,利用开发技术原理,采用面向对象的编程方法,其开发主要包括后台数据库的建立和后台框架的应用以及前端开发三个方面,实现了高效地房屋租赁管理的现代化和信息化。

整个租房平台从操作方面来说,符合操作简便、界面友好美观、灵活、实用、安全的要求,租房平台分为管理员、房东和租客端,管理员操作的系统完成基本房子管理、管理登录、用户管理、新闻资讯、用户反馈列表、房子管理、订单管理。普通用户:用户的登录注册、个人信息管理、用户房子搜索、收藏房子、租房操作。用户租房和房东发布房子,在一定程度上实现自动化。此系统开发的目的是为了进一步实现办公自动化,减少人力投资和办公费用,提高办公效率。

【623】基于springboot房屋租赁管理系统源码和设计与实现文档

关键词:房租赁平台;JSP;SpringBoot;MYSQL数据库

Abstract

With the rapid growth of China's market economy and the development of all walks of life towards the Internet, general housing services can no longer meet people's needs. Now young people work and rent a large proportion of houses. Young people do not like to go out. They work, study and play with computers and mobile phones every day, which is no longer the traditional way of renting houses. How to use advanced management means to improve the level of housing lease is an important issue facing the society today. This paper develops a housing lease management platform by using JSP technology and the popular Java framework of Springboot, SpringMVC, Mybatis. It uses the principle of development technology and the object-oriented programming method. Its development mainly includes the establishment of the background database, the application of the background framework, and the front-end development. It realizes the modernization and informatization of efficient housing lease management.

In terms of operation, the whole rental platform meets the requirements of simple operation, friendly and beautiful interface, flexibility, practicality and security. The rental platform is divided into administrator, landlord and tenant. The system operated by the administrator completes basic house management, management login, user management, news, user feedback list, house management and order management. Ordinary users: login and registration of users, personal information management, user house search, favorite house, and rental operation. Users rent houses and landlords publish houses, realizing automation to a certain extent. The purpose of this system development is to further realize office automation, reduce human investment and office expenses, and improve office efficiency.

Key words: house leasing platform; JSP; SpringBoot; MYSQL database

package com.javaDemo.houserent.controller.front;

import com.javaDemo.houserent.common.base.BaseController;
import com.javaDemo.houserent.common.constant.Constant;
import com.javaDemo.houserent.common.dto.JsonResult;
import com.javaDemo.houserent.common.enums.HouseStatusEnum;
import com.javaDemo.houserent.common.utils.DateUtil;
import com.javaDemo.houserent.entity.House;
import com.javaDemo.houserent.entity.Order;
import com.javaDemo.houserent.entity.User;
import com.javaDemo.houserent.service.HouseService;
import com.javaDemo.houserent.service.OrderService;
import com.javaDemo.houserent.service.UserService;
import com.javaDemo.houserent.common.enums.OrderStatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

/**
 * 前端订单控制器
 */
@Controller
public class OrderController extends BaseController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private HouseService houseService;

    @Autowired
    private UserService userService;


    /**
     * 创建订单
     */
    @RequestMapping("/order/create")
    @ResponseBody
    public JsonResult createOrder(
            @RequestParam("houseId") Long houseId,
            @RequestParam("endDate") String endDateStr) {
        if (getLoginUser() == null) {//用户未登录
            return JsonResult.error("用户未登录");
        }
        House house = houseService.get(houseId);
        if (house == null) { //房子不存在
            return JsonResult.error("房子不存在");
        }
        if (Objects.equals(house.getStatus(), HouseStatusEnum.HAS_RENT.getValue())) {
            return JsonResult.error("房子已租出或未释放");
        }
        //是否出游有效的订单范围
        Order checkOrser = orderService.getCurrentEffectiveOrder(houseId);
        if (checkOrser != null) {
            return JsonResult.error("房子已租出或未释放");
        }
        User ownerUser = userService.get(house.getUserId());
        if (ownerUser == null) {
            return JsonResult.error("房东用户不存在");
        }

        //处理退租日期
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
        Date endDate;
        try {
            endDate = sdf.parse(endDateStr);
        } catch (ParseException e) {
            e.printStackTrace();
            return JsonResult.error("退租日期格式不合法");
        }

        Date startDate = new Date();
        // 计算总共多少天
        Integer dayNum = DateUtil.daysBetween(startDate, endDate);
        if (dayNum < Constant.MIN_RENT_DAYS) {
            return JsonResult.error("最少租住" + Constant.MIN_RENT_DAYS + "天");
        }
        //创建订单
        Order order = new Order();
        order.setCreateTime(new Date());
        order.setCustomerUserId(getLoginUserId());
        order.setOwnerUserId(house.getUserId());
        order.setHouseId(houseId);
        order.setStatus(OrderStatusEnum.NOT_PAY.getValue());
        order.setMonthRent(house.getMonthRent());
        order.setDayNum(dayNum);
        order.setTotalAmount(house.getMonthRent() / 30 * dayNum);
        order.setStartDate(startDate);
        order.setEndDate(endDate);
        orderService.insert(order);
        return JsonResult.success("订单创建成功,支付订单", order.getId());
    }

    /**
     * 支付页面
     */
    @RequestMapping("/order/pay")
    public String pay(
            @RequestParam(value = "orderId") Long orderId, Model model) {
        if (getLoginUser() == null) {//用户未登录
            return "redirect:/";
        }
        //订单不存在
        Order order = orderService.get(orderId);
        if (order == null) {
            return renderNotFond();
        }
        //登录用户既不是该订单的租客,也不是房东或者管理员,就不能看
        if (!Objects.equals(getLoginUserId(), order.getCustomerUserId()) &&
                !Objects.equals(getLoginUserId(), order.getOwnerUserId()) &&
                !loginUserIsAdmin()){
            return renderNotAllowAccsee();
        }
        House house = houseService.get(order.getHouseId());
        if (house == null) { //房子不存在
            return renderNotFond();
        }
        //该订单的房子信息
        order.setHouse(houseService.get(order.getHouseId()));
        model.addAttribute("order",order);
        return "front/pay";
    }

    /**
     * 模拟支付
     */
    @RequestMapping("/order/pay/submit")
    public JsonResult paySubmit(
            @RequestParam(value = "orderId") Long orderId) {
        //用户未登录
        if (getLoginUser() == null) {
            return JsonResult.error("用户未登录");
        }
        //订单不存在
        Order order = orderService.get(orderId);
        if (order == null) {
            return JsonResult.error("订单不存在");
        }

        House house = houseService.get(order.getHouseId());
        //房子不存在
        if (house == null) {
            return JsonResult.error("房子不存在");
        }
        //登录用户既不是该订单的租客,也不是房东或者管理员,就不能看
        if (!Objects.equals(getLoginUserId(), order.getCustomerUserId()) &&
                !Objects.equals(getLoginUserId(), order.getOwnerUserId()) &&
                !loginUserIsAdmin()){
            return JsonResult.error("没有权限");
        }
        if (Objects.equals(house.getStatus(), HouseStatusEnum.HAS_RENT.getValue())) {
            return JsonResult.error("房子已租出或未释放");
        }
        //是否出有效的订单范围
        Order checkOrser = orderService.getCurrentEffectiveOrder(order.getHouseId());
        if (checkOrser != null) {
            return JsonResult.error("房子已租出或未释放");
        }
        User ownerUser = userService.get(house.getUserId());
        if (ownerUser == null) {
            return JsonResult.error("房东用户不存在");
        }
        order.setStatus(OrderStatusEnum.NORMAL.getValue());
        orderService.update(order);

        //更新房子状态 和 开始结束的时间
        house.setStatus(HouseStatusEnum.HAS_RENT.getValue());
        house.setLastOrderStartTime(order.getStartDate());
        house.setLastOrderEndTime(order.getEndDate());

        houseService.update(house);

        return JsonResult.success("支付成功");
    }

}
package com.javaDemo.houserent.controller.backend;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.javaDemo.houserent.common.base.BaseController;
import com.javaDemo.houserent.common.constant.Constant;
import com.javaDemo.houserent.common.dto.JsonResult;
import com.javaDemo.houserent.common.enums.HouseStatusEnum;
import com.javaDemo.houserent.common.utils.PageUtil;
import com.javaDemo.houserent.entity.House;
import com.javaDemo.houserent.service.HouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * 房子控制器
 */
@Controller
@RequestMapping("/admin")
public class HouseController extends BaseController {

    @Autowired
    private HouseService houseService;


    /**
     * 进入房子管理页面
     */
    @RequestMapping("/house")
    public String houseList(
            @RequestParam(value = "page",defaultValue = "1") Long pageNumber,
            @RequestParam(value = "size",defaultValue = "6") Long pageSize,
            Model model){
        Page page = PageUtil.initMpPage(pageNumber,pageSize);
        House condition = new House();
        //判断用户是否登录,拦截器
        if(getLoginUser()==null){
            return "front/index";
        }
        //如果登录用户时管理员,可以查询所有房子;如果登录用户不是管理员,只能查询自己的房子
        if(!loginUserIsAdmin()){
            condition.setUserId(getLoginUserId());
        }
        Page<House> housePage = houseService.findAll(page,condition);
        model.addAttribute("pageInfo",housePage);
        model.addAttribute("pagePrefix","/admin/house?");
        model.addAttribute("isAdmin",loginUserIsAdmin());
        model.addAttribute("tab","house-list");
        return "admin/house-list";
    }

    /**
     * 进入房子发布页面
     */
    @RequestMapping("/publish")
    public String publish(
            @RequestParam(value = "id",required = false) Long id,
            Model model){
        //判断用户是否登录,拦截器
        if(getLoginUser()==null){
            return "front/index";
        }
        House house = new House();
        //编辑页面
        if(id != null){
            house = houseService.get(id);
            if(house == null){
                return renderNotFond();
            }
            //如果编辑别人的房子,并且没有管理员权限,跳转403
            if(!loginUserIsAdmin() && Objects.equals(house.getUserId(), getLoginUserId())){
                return renderNotAllowAccsee();
            }

        }
        model.addAttribute("house",house);
        return "admin/house-publish";
    }

    /**
     * 发布房子提交
     */
    @RequestMapping("/publish/submit")
    @ResponseBody
    public JsonResult publishSubmit(House house,@RequestParam("key")String key,
                                    HttpSession session){
        try{
            if(house.getId() == null){  //新增
                house.setCreateTime(new Date());
                house.setUserId(getLoginUserId());
            }else {                     //修改
                House queryHouse = houseService.get(house.getId());
                if(queryHouse == null){
                    return JsonResult.error("修改失败,没有这个房子");
                }
                //如果编辑别人的房子,并且没有管理员权限,跳转403
                if(!loginUserIsAdmin() && !Objects.equals(house.getUserId(), getLoginUserId())){
                    return JsonResult.error("你不能编辑别人的房子");
                }
            }
            house.setStatus(HouseStatusEnum.NOT_CHECK.getValue());
            //获取轮播图
            String sessionKey = Constant.SESSION_IMG_PREFIX + key;
            List<String> imgList = (List<String>) session.getAttribute(sessionKey);
            if(imgList != null && imgList.size()>0){
                //把轮播图转换成json格式存储
                house.setSlideUrl(JSON.toJSONString(imgList));
                //把轮播图的第一个图放到缩略图中
                house.setThumbnailUrl(imgList.get(0));
            }
            houseService.insertOrUpdate(house);
        }catch (Exception e){
            return JsonResult.error("发布失败,请填写完整信息");
        }
        return JsonResult.success("发布成功",house.getId());
    }


    /**
     * 下架房子
     */
    @RequestMapping("/down")
    @ResponseBody
    public JsonResult downHouse(@RequestParam("id")long id){
        try{
            House house = houseService.get(id);
            if(house == null){
                return JsonResult.error("没有这个房子");
            }
            //如果下架别人的房子,并且没有管理员权限,跳转403
            if(!loginUserIsAdmin() && !Objects.equals(house.getUserId(), getLoginUserId())){
                return JsonResult.error("你不能下架别人的房子");
            }
            if(Objects.equals(house.getStatus(), HouseStatusEnum.HAS_RENT.getValue())){
                return JsonResult.error("房子正在租住中,不能下架");
            }
            house.setStatus(HouseStatusEnum.HAS_DOWN.getValue());
            houseService.update(house);
        }catch (Exception e){
            return JsonResult.error("下架失败");
        }
        return JsonResult.success("下架成功");
    }

    /**
     * 上架房子
     */
    @RequestMapping("/up")
    @ResponseBody
    public JsonResult upHouse(@RequestParam("id")long id){
        try{
            House house = houseService.get(id);
            if(house == null){
                return JsonResult.error("没有这个房子");
            }
            //如果下架别人的房子,并且没有管理员权限,跳转403
            if(!loginUserIsAdmin() && !Objects.equals(house.getUserId(), getLoginUserId())){
                return JsonResult.error("你不能上架别人的房子");
            }
            if(Objects.equals(house.getStatus(), HouseStatusEnum.HAS_RENT.getValue())){
                return JsonResult.error("房子正在租住中,不能上架");
            }
            house.setStatus(HouseStatusEnum.NOT_RENT.getValue());
            houseService.update(house);
        }catch (Exception e){
            return JsonResult.error("上架失败");
        }
        return JsonResult.success("上架成功");
    }

    /**
     * 房子审核通过
     */
    @RequestMapping("/checkPass")
    @ResponseBody
    public JsonResult checkPassHouse(@RequestParam("id")long id){
        try{
            House house = houseService.get(id);
            if(house == null){
                return JsonResult.error("没有这个房子");
            }
            //只有管理员有权限审核
            if(!loginUserIsAdmin()){
                return JsonResult.error("你没有权限审核");
            }
            if(!Objects.equals(house.getStatus(), HouseStatusEnum.NOT_CHECK.getValue())){
                return JsonResult.error("只能审核待审核的房子");
            }
            house.setStatus(HouseStatusEnum.NOT_RENT.getValue());
            houseService.update(house);
        }catch (Exception e){
            return JsonResult.error("审核失败");
        }
        return JsonResult.success("审核成功");
    }

    /**
     * 房子审核不通过
     */
    @RequestMapping("/checkReject")
    @ResponseBody
    public JsonResult checkRejectHouse(@RequestParam("id")long id){
        try{
            House house = houseService.get(id);
            if(house == null){
                return JsonResult.error("没有这个房子");
            }
            //只有管理员有权限审核
            if(!loginUserIsAdmin()){
                return JsonResult.error("你没有权限审核");
            }
            if(!Objects.equals(house.getStatus(), HouseStatusEnum.NOT_CHECK.getValue())){
                return JsonResult.error("只能审核待审核的房子");
            }
            house.setStatus(HouseStatusEnum.CHECK_REJECT.getValue());
            houseService.update(house);
        }catch (Exception e){
            return JsonResult.error("审核失败");
        }
        return JsonResult.success("驳回成功");
    }


    /**
     * 删除房子
     */
    @RequestMapping("/delete")
    @ResponseBody
    public JsonResult deleteHouse(@RequestParam("id")long id){
        try{
            House house = houseService.get(id);
            if(house == null){
                return JsonResult.error("没有这个房子");
            }
            //如果删除别人的房子,并且没有管理员权限,跳转403
            if(!loginUserIsAdmin() && !Objects.equals(house.getUserId(), getLoginUserId())){
                return JsonResult.error("这不是你的房子,你没有权限删除");
            }
            if(Objects.equals(house.getStatus(), HouseStatusEnum.HAS_RENT.getValue())){
                return JsonResult.error("房子正在租住中,不能删除");
            }
            houseService.delete(id);
        }catch (Exception e){
            return JsonResult.error("删除房子失败");
        }
        return JsonResult.success("删除成功");
    }
}

一、项目简介本课程演示的是一套基于SSM实现的房屋租赁系统,主要针对计算机相关专业的正在做毕设的学生与需要项目实战练习的Java学习者。课程包含: 1. 项目源码、项目文档、数据库脚本、软件工具等所有资料2. 带你从零开始部署运行本套系统3. 该项目附带的源码资料可作为毕设使用4. 提供技术答疑和远程协助指导二、技术实现 后台框架:SpringSpringMVC、MyBatisUI界面:jQuery 、JSP数据库:MySQL 三、系统功能系统分为前台用户界面和后台系统管理:1. 前台用户界面    用户注册、用户登录、用户中心、浏览房源、房源搜索    查看房源明细、发布房源、提交合同、新闻公告、留言交流2. 后台系统管理    用户管理:用户列表、用户删除、用户查询    新闻管理:新闻列表、添加新闻、修改新闻、删除新闻、查询新闻    房屋管理:房屋列表、房屋删除、分页查看    留言管理:留言列表、留言删除、留言查询、留言回复列表、回复查询    租赁合同管理:合同列表、查看合同、删除合同    管理员管理:管理员管理、新增管理员、编辑管理员、删除管理员等 四、项目截图1)前台用户界面 2)后台系统管理    更多Java毕设项目请关注【毕设系列课程】https://edu.csdn.net/lecturer/2104   点击 我的百科 ,通过百度百科更多了解我 ^_^ 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序猿毕业分享网

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值