哈喽~大家好呀,时隔一个月,这次的一个小项目来喽,这次的 “二嗨租车项目” 使用的是的 oracle + JDBC + 集合 + 面向对象 + 分层思想(MVC),接下来就来看看吧。
🥇个人主页:个人主页
🥈 系列专栏:【JAVASE开发】
🥉与这篇相关的文章:
【JAVASE开发】带你零基础学JAVA项目(学生管理系统篇) 【JAVASE开发】带你零基础学JAVA项目(学生管理系统篇)_程序猿追的博客-CSDN博客
目录
首先是用户登入界面,账号登录总界面部分分为登入与注册选择,账号分为管理员和普通用户,如果是管理员(admin)那么进入到另一个界面(与普通用户不同可以对汽车的一些信息进行修改,eg:上架汽车与删除汽车信息等操作),如果是普通用户的话,也是进入到不一样的界面(对汽车进行租借与还车支付金额等操作)




三层架构设计思想
通常意义上的三层架构就是将整个业务应用划分为:表现层、业务逻辑层、数据访问层。区分层次的目的即为了“高内聚,低耦合”的思想。
表现层(View):通俗讲就是展现给用户的界面,即用户在使用一个系统的时候他的所见所得。
业务逻辑层(Control):针对具体问题的操作,也可以说是对数据层的操作,对数据业务逻辑处理。
数据访问层(Model):该层所做事务直接操作数据库,针对数据的增添、删除、修改、更新、查找等。
在 V 层输入访问条件(操作1),条件传到 C 层(操作2),然后 C 层调用 M 层里面的方法直接访问数据库(DB)(操作3),然后 DB 返回的结果集转到 M 层(操作4),M 返回到C层(操作5),最后回到 V 层(操作6),然后依次在界面上显示出来.

工具:IntelliJ IDEA 2021.3 + oracle 12e + PLSQL Developer 13 (64 bit)
数据库部分:数据表(T_BRAND(品牌表)、汽车表(T_CAR)、类型表(T_CATEGORY)、租车记录表(T_RECORD)、用户表(T_USER))




首先先完成普通用户,完成之后直接复制到管理员在进行修改,这里就写一个查看所有汽车信息的操作吧。
View层
- package com.itxzw.view.main;
-
- public class CarGeneralViewInterface {
-
- public void showCarGeneralViewInterface(){
-
- System.out.println("----------------------------------------------------------------------------");
- System.out.println("登录成功!你是普通用户,请选择服务:");
-
- System.out.println("1、查看所有汽车");
- System.out.println("2、按照价格来升序或降序查询汽车");
- System.out.println("3、按照类别查看汽车");
- System.out.println("4、按照品牌查看汽车");
- System.out.println("5、查看本人所有租车记录");
- System.out.println("6、租车");
- System.out.println("7、还车");
- System.out.println("8、退出");
- System.out.println("----------------------------------------------------------------------------");
-
- }
-
- public void showAdminCarGeneralViewInterface(){
-
- System.out.println("----------------------------------------------------------------------------");
- System.out.println("登录成功!你是管理员,请选择服务:");
-
- System.out.println("1、查看所有汽车信息");
- System.out.println("2、根据指定编号查看汽车信息");
- System.out.println("3、添加汽车");
- System.out.println("4、修改汽车信息");
- System.out.println("5、查看所有用户全部租车记录");
- System.out.println("6、查看指定用户租车记录");
- System.out.println("7、查看指定汽车租车记录");
- System.out.println("8、退出");
- System.out.println("----------------------------------------------------------------------------");
-
- }
-
- public void LoginAndRegister(){
-
- System.out.println("----------------------------------------------------------------------------");
- System.out.println("尊敬的用户,您好!!");
-
- System.out.println("欢迎使用二嗨租车系统,请输入数字来进行操作:");
- System.out.println("说明:输入数字1是进行登录,输入数字2进行注册");
- System.out.println("1、登录");
- System.out.println("2、注册");
- System.out.println("----------------------------------------------------------------------------");
-
- }
-
- }
TextMain.java
- carGeneralViewInterface.showCarGeneralViewInterface();
- System.out.println("请输入数字来进行操作:");
- int scan = Scan.scan.nextInt();
- if (scan == 1) {
- System.out.println("所有的汽车信息是:");
- carControl.viewAllCars();
- }
C层
- // 查看所有汽车
- public void viewAllCars() throws SQLException {
- carService.viewAllCars();
- }
接口
public void viewAllCars() throws SQLException;
相对应的实现方法
- @Override
- public void viewAllCars() throws SQLException {
- conn = JdbcUtil.getConnection();
- stmt = conn.createStatement();
- String sql = "select * from T_CAR";
- rs = stmt.executeQuery(sql);
-
- ArrayList
list = new ArrayList(); - while (rs.next()) {
- Integer id = ((BigDecimal) rs.getObject("id")).intValue();
- String Car_Number = rs.getString("Car_Number");
- Integer Brand_Id = ((BigDecimal) rs.getObject("Brand_Id")).intValue();
- String model = rs.getString("model");
- String Color = rs.getString("Color");
- Integer Category_Id = ((BigDecimal) rs.getObject("Category_Id")).intValue();
- String T_Comments = rs.getString("T_Comments");
- Double price = rs.getDouble("price");
- Double rent = rs.getDouble("rent");
- Integer status = ((BigDecimal) rs.getObject("status")).intValue();
- Integer useable = ((BigDecimal) rs.getObject("useable")).intValue();
-
- car = new Car(id, Car_Number, Brand_Id, model, Color, Category_Id, T_Comments, price, rent, status, useable);
-
- list.add(car);
- }
-
- for (int i = 0; i < list.size(); i++) {
- System.out.println(list.get(i));
- }
- }
Car.java 实体类
- package com.itxzw.client.model;
-
- public class Car {
-
- private int id;
- private String Car_Number;
- private int Brand_Id;
- private String model;
- private String Color;
- private int Category_Id;
- private String T_Comments;
- private double price;
- private double rent;
- private int status;
- private int useable;
-
- public Car() {
- }
-
- public Car(int id, String car_Number, int brand_Id, String model, String color, int category_Id, String t_Comments, double price, double rent, int status, int useable) {
- this.id = id;
- Car_Number = car_Number;
- Brand_Id = brand_Id;
- this.model = model;
- Color = color;
- Category_Id = category_Id;
- T_Comments = t_Comments;
- this.price = price;
- this.rent = rent;
- this.status = status;
- this.useable = useable;
- }
-
- public int getId() {
- return id;
- }
-
- public void setId(int id) {
- this.id = id;
- }
-
- public String getCar_Number() {
- return Car_Number;
- }
-
- public void setCar_Number(String car_Number) {
- Car_Number = car_Number;
- }
-
- public int getBrand_Id() {
- return Brand_Id;
- }
-
- public void setBrand_Id(int brand_Id) {
- Brand_Id = brand_Id;
- }
-
- public String getModel() {
- return model;
- }
-
- public void setModel(String model) {
- this.model = model;
- }
-
- public String getColor() {
- return Color;
- }
-
- public void setColor(String color) {
- Color = color;
- }
-
- public int getCategory_Id() {
- return Category_Id;
- }
-
- public void setCategory_Id(int category_Id) {
- Category_Id = category_Id;
- }
-
- public String getT_Comments() {
- return T_Comments;
- }
-
- public void setT_Comments(String t_Comments) {
- T_Comments = t_Comments;
- }
-
- public double getPrice() {
- return price;
- }
-
- public void setPrice(double price) {
- this.price = price;
- }
-
- public double getRent() {
- return rent;
- }
-
- public void setRent(double rent) {
- this.rent = rent;
- }
-
- public int getStatus() {
- return status;
- }
-
- public void setStatus(int status) {
- this.status = status;
- }
-
- public int getUseable() {
- return useable;
- }
-
- public void setUseable(int useable) {
- this.useable = useable;
- }
-
- @Override
- public String toString() {
- return "Car{" +
- "id=" + id +
- ", Car_Number='" + Car_Number + '\'' +
- ", Brand_Id=" + Brand_Id +
- ", model='" + model + '\'' +
- ", Color='" + Color + '\'' +
- ", Category_Id=" + Category_Id +
- ", T_Comments='" + T_Comments + '\'' +
- ", price=" + price +
- ", rent=" + rent +
- ", status=" + status +
- ", useable=" + useable +
- '}';
- }
- }
运行一下没有问题,其他的都差不多,改一下 sql 语句操作。
不积跬步无以至千里,趁年轻,使劲拼,给未来的自己一个交代!向着明天更好的自己前进吧!