一、项目介绍
基于SSM框架的房屋租赁系统,系统分为租客和管理员两个角色,主要功能如下
租客:
房源信息:房源列表
租赁信息:在租列表、已退租列表
租金信息:代缴租金、已缴租金
报障模块:我要报障、未处理报障、已处理报障
管理员:
房源信息:房源列表、添加房源
租赁及合同信息:在租列表、已退租列表
申请列表:看房申请、退租申请
报障模块:待处理报障、已处理报障
租金信息:我要收租、租客代缴租金、租客已缴租金
我的日程:查看日程、添加日程
二、项目技术
编程语言:Java
数据库:MySQL
前端技术:Html、CSS、JavaScript、JSP
后端技术:Spring、SpringMVC、MyBatis
三、运行环境
JDK版本:1.8及以上都可以
操作系统:Windows7/10、MacOS
开发工具:IDEA、Ecplise、MyEclipse都可以
数据库: MySQL5.5/5.7/8.0版本都可以
Tomcat:7.0及以上版本都可以
四、运行截图
五、主要功能代码
在一个简单的Java房屋租赁系统中,可以设计三个主要功能:添加房源、查看房源列表、和租赁房屋。以下是每个功能的简要描述和相应的代码示例。
1. 添加房源
这个功能允许用户添加新的房源信息,如地址、租金和房屋描述。
代码示例:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class House {
private String address;
private double rent;
private String description;
public House(String address, double rent, String description) {
this.address = address;
this.rent = rent;
this.description = description;
}
public String getAddress() {
return address;
}
public double getRent() {
return rent;
}
public String getDescription() {
return description;
}
@Override
public String toString() {
return "Address: " + address + ", Rent: " + rent + ", Description: " + description;
}
}
class RentalSystem {
private List<House> houseList = new ArrayList<>();
public void addHouse(House house) {
houseList.add(house);
System.out.println("House added successfully.");
}
public List<House> getHouseList() {
return houseList;
}
}
public class Main {
public static void main(String[] args) {
RentalSystem rentalSystem = new RentalSystem();
Scanner scanner = new Scanner(System.in);
System.out.println("Enter house address:");
String address = scanner.nextLine();
System.out.println("Enter house rent:");
double rent = scanner.nextDouble();
scanner.nextLine(); // Consume newline
System.out.println("Enter house description:");
String description = scanner.nextLine();
House house = new House(address, rent, description);
rentalSystem.addHouse(house);
}
}
2. 查看房源列表
这个功能允许用户查看当前所有可供租赁的房源信息。
代码示例:
public class Main {
public static void main(String[] args) {
RentalSystem rentalSystem = new RentalSystem();
// Assuming some houses have been added already
rentalSystem.addHouse(new House("123 Main St", 1200, "2 bed, 1 bath apartment"));
rentalSystem.addHouse(new House("456 Oak St", 1500, "3 bed, 2 bath house"));
System.out.println("Available houses:");
for (House house : rentalSystem.getHouseList()) {
System.out.println(house);
}
}
}
3. 租赁房屋
这个功能允许用户选择一个房源进行租赁,并将该房源从可供租赁的列表中移除。
代码示例:
public class Main {
public static void main(String[] args) {
RentalSystem rentalSystem = new RentalSystem();
Scanner scanner = new Scanner(System.in);
// Adding some houses
rentalSystem.addHouse(new House("123 Main St", 1200, "2 bed, 1 bath apartment"));
rentalSystem.addHouse(new House("456 Oak St", 1500, "3 bed, 2 bath house"));
System.out.println("Available houses:");
List<House> houses = rentalSystem.getHouseList();
for (int i = 0; i < houses.size(); i++) {
System.out.println((i + 1) + ". " + houses.get(i));
}
System.out.println("Enter the number of the house you want to rent:");
int houseNumber = scanner.nextInt();
if (houseNumber > 0 && houseNumber <= houses.size()) {
House rentedHouse = houses.remove(houseNumber - 1);
System.out.println("You have rented: " + rentedHouse);
} else {
System.out.println("Invalid selection.");
}
}
}