租车系统

为了资源的节约有效利用,使车辆发挥更大的作用,我在此做了一个租车系统。

功能分析:
1:登录功能
2:后台管理功能
3:车辆管理功能
4:用户管理功能
5:前台用户功能
6:查看可租车辆信息功能
7:查看已租记录功能

图片效果

主界面
在这里插入图片描述
输入1时候
在这里插入图片描述
输入2的时候
在这里插入图片描述
选择角色后会让你输入账户和密码(输入的账户密码不对会让你重新输入)
在这里插入图片描述

实现此程序数据库使必不可少的

下面看SQLServer数据库构成(三个表

1 . 用户表(user)
在这里插入图片描述
2 . 车辆表(vehicle)
在这里插入图片描述
3 . 租赁记录表(rent_relation)
在这里插入图片描述
在程序正式开始之前我们先看一下**目录结构图**

由于结构图较长分为二部分展示

一:
在这里插入图片描述
二:
在这里插入图片描述
相信你们已经迫不及待想要看代码了,下面就让我们一起来分析欣赏代码.

代码演示

一 :model包里包含copy包和jdbc包

model包里的copy包:
model.copy.Car.java代码

package com.zsh.model.copy;/*** 客车* @author zsh**/
public class Car extends Vehicle {/*** 车辆准乘人数*/private int vehiclePeopleNumber;public int getVehiclePeopleNumber() {return vehiclePeopleNumber;}public void setVehiclePeopleNumber(int vehiclePeopleNumber) {this.vehiclePeopleNumber = vehiclePeopleNumber;}}

model.copy.PickupTruck.java代码

package com.zsh.model.copy;
/*** 皮卡车* @author zsh*/
public class PickupTruck extends Vehicle {/*** 车辆准乘人数*/private int vehiclePeopleNumber;public int getVehiclePeopleNumber() {return vehiclePeopleNumber;}public void setVehiclePeopleNumber(int vehiclePeopleNumber) {this.vehiclePeopleNumber = vehiclePeopleNumber;}/*** 车辆载重(吨)*/private int vehivleLoad;public int getVehivleLoad() {return vehivleLoad;}public void setVehivleLoad(int vehivleLoad) {this.vehivleLoad = vehivleLoad;}
}

model.copy.Truck.java代码

package com.zsh.model.copy;/*** 货车* @author zsh**/
public class Truck extends Vehicle {/*** 车辆载重(吨)*/private int vehivleLoad;public int getVehivleLoad() {return vehivleLoad;}public void setVehivleLoad(int vehivleLoad) {this.vehivleLoad = vehivleLoad;}}

model.copy.Vehicle.java代码

package com.zsh.model.copy;/*** 车辆抽象类* @author zsh**/
public abstract class Vehicle {/*** 车辆ID*/private int vehicleId;/*** 车辆分类ID*/private int classifyId;/*** 车辆名称*/private String vehicleName;/*** 车辆牌照*/private String vehicleNumber;/*** 车辆vin码*/private String vehicleVin;/*** 车辆属性(客车,货车,皮卡)*/private String vehicleProperty;public int getVehicleId() {return vehicleId;}public void setVehicleId(int vehicleId) {this.vehicleId = vehicleId;}public int getClassifyId() {return classifyId;}public void setClassifyId(int classifyId) {this.classifyId = classifyId;}public String getVehicleName() {return vehicleName;}public void setVehicleName(String vehicleName) {this.vehicleName = vehicleName;}public String getVehicleNumber() {return vehicleNumber;}public void setVehicleNumber(String vehicleNumber) {this.vehicleNumber = vehicleNumber;}public String getVehicleVin() {return vehicleVin;}public void setVehicleVin(String vehicleVin) {this.vehicleVin = vehicleVin;}public String getVehicleProperty() {return vehicleProperty;}public void setVehicleProperty(String vehicleProperty) {this.vehicleProperty = vehicleProperty;}}

model包里的jdbc包:
model.jdbc.RentRecord.java

package com.zsh.model.jdbc;public class RentRecord {/*** 车辆ID*/private int vehicleId;private String vehicleName;private String vehicleVin;private String classify;private int vehicleLoad;private int vehiclePeople;private int vehicleMoney;private int vehicleDays;	/*** 租赁日期时间*/private String rentTime;/*** 租期 小时*/private int rentTenancy;public int getVehicleId() {return vehicleId;}public void setVehicleId(int vehicleId) {this.vehicleId = vehicleId;}public String getVehicleName() {return vehicleName;}public void setVehicleName(String vehicleName) {this.vehicleName = vehicleName;}public String getVehicleVin() {return vehicleVin;}public void setVehicleVin(String vehicleVin) {this.vehicleVin = vehicleVin;}public String getClassify() {return classify;}public void setClassify(String classify) {this.classify = classify;}public int getVehicleLoad() {return vehicleLoad;}public void setVehicleLoad(int vehicleLoad) {this.vehicleLoad = vehicleLoad;}public int getVehiclePeople() {return vehiclePeople;}public void setVehiclePeople(int vehiclePeople) {this.vehiclePeople = vehiclePeople;}public int getVehicleMoney() {return vehicleMoney;}public void setVehicleMoney(int vehicleMoney) {this.vehicleMoney = vehicleMoney;}public int getVehicleDays() {return vehicleDays;}public void setVehicleDays(int vehicleDays) {this.vehicleDays = vehicleDays;}public String getRentTime() {return rentTime;}public void setRentTime(String rentTime) {this.rentTime = rentTime;}public int getRentTenancy() {return rentTenancy;}public void setRentTenancy(int rentTenancy) {this.rentTenancy = rentTenancy;}
}

model.jdbc.RentRelationView.java

package com.zsh.model.jdbc;public class RentRelationView {private int userId;private int vehicleId;/*** 租赁日期时间*/private String rentTime;/*** 租期 小时*/private int rentTenancy;public int getUserId() {return userId;}public void setUserId(int userId) {this.userId = userId;}public int getVehicleId() {return vehicleId;}public void setVehicleId(int vehicleId) {this.vehicleId = vehicleId;}public String getRentTime() {return rentTime;}public void setRentTime(String rentTime) {this.rentTime = rentTime;}public int getRentTenancy() {return rentTenancy;}public void setRentTenancy(int rentTenancy) {this.rentTenancy = rentTenancy;}}

model.jdbc.UserView.java

package com.zsh.model.jdbc;/*** 数据库中用户实体* @author zsh**/
public class UserView {private int userId;private String userName;private String pwd;private String sex;private int age;private String driverNumber;private String icNumber;private String phone;public int getUserId() {return userId;}public void setUserId(int userId) {this.userId = userId;}public String getUserName() {return userName;}public void setUserName(String userName) {this.userName = userName;}public String getPwd() {return pwd;}public void setPwd(String pwd) {this.pwd = pwd;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public String getDriverNumber() {return driverNumber;}public void setDriverNumber(String driverNumber) {this.driverNumber = driverNumber;}public String getIcNumber() {return icNumber;}public void setIcNumber(String icNumber) {this.icNumber = icNumber;}public String getPhone() {return phone;}public void setPhone(String phone) {this.phone = phone;}}

model.jdbc.VehicleView.java

package com.zsh.model.jdbc;/*** 数据库中车辆对象* @author zsh**/
public class VehicleView {/*** 车辆ID*/private int vehicleId;/*** 车辆分类*/private String classify;/*** 车辆名称*/private String vehicleName;/*** 车辆牌照*/private String vehicleNumber;/*** 车辆vin码*/private String vehicleVin;/*** 车辆准乘人数*/private int vehiclePeopleNumber;/*** 车辆载重(吨)*/private int vehicleLoad;private int vehicleIsRent;private int vehicleMoney;private int vehicleDays;public int getVehicleIsRent() {return vehicleIsRent;}public void setVehicleIsRent(int vehicleIsRent) {this.vehicleIsRent = vehicleIsRent;}public int getVehicleMoney() {return vehicleMoney;}public void setVehicleMoney(int vehicleMoney) {this.vehicleMoney = vehicleMoney;}public int getVehicleDays() {return vehicleDays;}public void setVehicleDays(int vehicleDays) {this.vehicleDays = vehicleDays;}public int getVehicleLoad() {return vehicleLoad;}public void setVehicleLoad(int vehicleLoad) {this.vehicleLoad = vehicleLoad;}public int getVehiclePeopleNumber() {return vehiclePeopleNumber;}public void setVehiclePeopleNumber(int vehiclePeopleNumber) {this.vehiclePeopleNumber = vehiclePeopleNumber;}public int getVehicleId() {return vehicleId;}public void setVehicleId(int vehicleId) {this.vehicleId = vehicleId;}public String getClassify() {return classify;}public void setClassify(String classify) {this.classify = classify;}public String getVehicleName() {return vehicleName;}public void setVehicleName(String vehicleName) {this.vehicleName = vehicleName;}public String getVehicleNumber() {return vehicleNumber;}public void setVehicleNumber(String vehicleNumber) {this.vehicleNumber = vehicleNumber;}public String getVehicleVin() {return vehicleVin;}public void setVehicleVin(String vehicleVin) {this.vehicleVin = vehicleVin;}@Overridepublic String toString() {return "VehicleView [vehicleId=" + vehicleId + ", classify="+ classify + ", vehicleName=" + vehicleName+ ", vehicleNumber=" + vehicleNumber + ", vehicleVin="+ vehicleVin+ ", vehiclePeopleNumber=" + vehiclePeopleNumber+ ", vehicleLoad=" + vehicleLoad + ", vehicleIsRent="+ vehicleIsRent + ", vehicleMoney=" + vehicleMoney+ ", vehicleDays=" + vehicleDays + "]";}}

model包:
model.Car.java

package com.zsh.model;/*** 客车* @author zsh**/
public class Car extends Vehicle {/*** 车辆准乘人数*/private int vehiclePeopleNumber;public int getVehiclePeopleNumber() {return vehiclePeopleNumber;}public void setVehiclePeopleNumber(int vehiclePeopleNumber) {this.vehiclePeopleNumber = vehiclePeopleNumber;}}

model.PickupTruck.java

package com.zsh.model;
/*** 皮卡车* @author zsh*/
public class PickupTruck extends Vehicle {/*** 车辆准乘人数*/private int vehiclePeopleNumber;public int getVehiclePeopleNumber() {return vehiclePeopleNumber;}public void setVehiclePeopleNumber(int vehiclePeopleNumber) {this.vehiclePeopleNumber = vehiclePeopleNumber;}/*** 车辆载重(吨)*/private int vehivleLoad;public int getVehivleLoad() {return vehivleLoad;}public void setVehivleLoad(int vehivleLoad) {this.vehivleLoad = vehivleLoad;}
}

model.Truck.java

package com.zsh.model;/*** 货车* @author zsh**/
public class Truck extends Vehicle {/*** 车辆载重(吨)*/private int vehivleLoad;public int getVehivleLoad() {return vehivleLoad;}public void setVehivleLoad(int vehivleLoad) {this.vehivleLoad = vehivleLoad;}}

model.Vehicle.java

package com.zsh.model;/*** 车辆抽象类* @author zsh**/
public abstract class Vehicle {/*** 车辆ID*/private int vehicleId;/*** 车辆分类ID*/private int classifyId;/*** 车辆名称*/private String vehicleName;/*** 车辆牌照*/private String vehicleNumber;/*** 车辆vin码*/private String vehicleVin;/*** 车辆属性(客车,货车,皮卡)*/private String vehicleProperty;public int getVehicleId() {return vehicleId;}public void setVehicleId(int vehicleId) {this.vehicleId = vehicleId;}public int getClassifyId() {return classifyId;}public void setClassifyId(int classifyId) {this.classifyId = classifyId;}public String getVehicleName() {return vehicleName;}public void setVehicleName(String vehicleName) {this.vehicleName = vehicleName;}public String getVehicleNumber() {return vehicleNumber;}public void setVehicleNumber(String vehicleNumber) {this.vehicleNumber = vehicleNumber;}public String getVehicleVin() {return vehicleVin;}public void setVehicleVin(String vehicleVin) {this.vehicleVin = vehicleVin;}public String getVehicleProperty() {return vehicleProperty;}public void setVehicleProperty(String vehicleProperty) {this.vehicleProperty = vehicleProperty;}}

二 : service包里包含copy包和impl包

service包里的copy包:
service.copy.ClassifyService.java

package com.zsh.service.copy;public interface ClassifyService {/*** 返回新增数据的ID* @return*/int insertClsssify(String classifyName);
}

service.copy.RentRelationService.java

package com.zsh.service.copy;import java.util.List;import com.zsh.model.jdbc.RentRecord;public interface RentRelationService {/*** 新增租车记录* * @return*/int insertRentRelation(int userId, int vehicleId, String rentTime,int rentTenancy);/*** 查询某个用户的租车记录* @return*/List<RentRecord> selectRentRecord(int userId);/*** 查询租车记录* @return*/List<RentRecord> selectAllRentRecord();/*** 根据用户ID 车辆ID查询租车记录* @param userId* @param vehicleId* @return*/int selectRelationByUserIdAndVehicleId(int userId,int vehicleId);/*** 删除租车记录 退租车辆* @param relationId* @return*/int  deleteRentRelation(int relationId);}

service.copy.UserService.java

package com.zsh.service.copy;import java.util.List;import com.zsh.model.jdbc.UserView;public interface UserService {/*** 新增用户*/int insertUser(UserView userView);/*** 删除用户*/int deleteUser(int userId);/*** 登录* @param userName* @param pwd* @return*/UserView login(String userName,String pwd);/*** 查询所有用户* @return*/List<UserView> listUser();
}

service.copy.VehicleService.java

package com.zsh.service.copy;import java.util.List;import com.zsh.model.jdbc.VehicleView;public interface VehicleServie {List<VehicleView> selectAll();/*** 新增车辆信息* @param vehicleView* @return*/int addVehicle(VehicleView vehicle);/*** 更新车辆信息* @param vehicleView* @return*/int updateVehicle(VehicleView vehicle);/*** 删除车辆信息* @param vehicleView* @return*/int deleteVehicle(int vehicleId);/*** 查询可租车辆信息* @return*/List<VehicleView> selectCanRentVehicles();/*** 根据车辆ID查找车辆信息* @param vehicleId* @return*/VehicleView getVehicleById(int vehicleId);
}

service包里的impl包:
service.impl.ClassifyServiceImpl.java

package com.zsh.service.impl;import java.sql.PreparedStatement;import com.alibaba.druid.pool.DruidPooledConnection;
import com.zsh.service.ClassifyService;
import com.zsh.util.DBPoolConnection;public class ClassifyServiceImpl implements ClassifyService {public int insertClsssify(String classifyName) {int result = -1;DBPoolConnection dbPoolConnection = DBPoolConnection.getInstance();DruidPooledConnection connection = null;PreparedStatement preparedStatement = null;String insertSql = "insert into user (classify_name) values (?)";try {connection = dbPoolConnection.getConnection();connection.setAutoCommit(true);preparedStatement = connection.prepareStatement(insertSql);preparedStatement.setString(1, classifyName);result = preparedStatement.executeUpdate();} catch (Exception e) {e.printStackTrace();} finally {DBPoolConnection.close(connection, preparedStatement);}return result;}}

service.impl.RentRelationServiceImpl.java

package com.zsh.service.impl;import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;import com.alibaba.druid.pool.DruidPooledConnection;
import com.zsh.model.jdbc.RentRecord;
import com.zsh.service.RentRelationService;
import com.zsh.util.DBPoolConnection;public class RentRelationServiceImpl implements RentRelationService {public int insertRentRelation(int userId, int vehicleId, String rentTime,int rentTenancy) {int result = -1;DBPoolConnection dbPoolConnection = DBPoolConnection.getInstance();DruidPooledConnection connection = null;PreparedStatement preparedStatement = null;String insertSql = "insert into rent_relation (user_id,vehicle_id,rent_time,rent_tenancy) values (?,?,?,?)";try {connection = dbPoolConnection.getConnection();connection.setAutoCommit(true);preparedStatement = connection.prepareStatement(insertSql);preparedStatement.setInt(1, userId);preparedStatement.setInt(2, vehicleId);preparedStatement.setString(3, rentTime);preparedStatement.setInt(4, rentTenancy);result = preparedStatement.executeUpdate();} catch (Exception e) {e.printStackTrace();} finally {DBPoolConnection.close(connection, preparedStatement);}return result;}public List<RentRecord> selectRentRecord(int userId) {DBPoolConnection dbPoolConnection = DBPoolConnection.getInstance();DruidPooledConnection connection = null;PreparedStatement preparedStatement = null;ResultSet resultSet = null;String selectSql = "select a.vehicle_id, a.rent_time,a.rent_tenancy,b.vehicle_name, "+ " b.vehicle_vin,b.classify,b.vehicle_load, "+ " b.vehicle_people_number,b.vehicle_money,b.vehicle_days "+ " from rent_relation a ,vehicle b "+ " where a.vehicle_id = b.vehicle_id and a.user_id = ? ";List<RentRecord> records = new ArrayList<RentRecord>();try {connection = dbPoolConnection.getConnection();preparedStatement = connection.prepareStatement(selectSql);preparedStatement.setInt(1, userId);resultSet = preparedStatement.executeQuery();while (resultSet.next()) {RentRecord view = new RentRecord();view.setVehicleId(resultSet.getInt("vehicle_id"));view.setRentTime(resultSet.getString("rent_time"));view.setRentTenancy(resultSet.getInt("rent_tenancy"));view.setVehicleName(resultSet.getString("vehicle_name"));view.setVehicleVin(resultSet.getString("vehicle_vin"));view.setClassify(resultSet.getString("classify"));view.setVehicleLoad(resultSet.getInt("vehicle_load"));view.setVehiclePeople(resultSet.getInt("vehicle_people_number"));view.setVehicleMoney(resultSet.getInt("vehicle_money"));view.setVehicleDays(resultSet.getInt("vehicle_days"));records.add(view);}} catch (Exception e) {e.printStackTrace();} finally {DBPoolConnection.close(connection, preparedStatement);}return records;}public List<RentRecord> selectAllRentRecord() {DBPoolConnection dbPoolConnection = DBPoolConnection.getInstance();DruidPooledConnection connection = null;PreparedStatement preparedStatement = null;ResultSet resultSet = null;String selectSql = "select a.vehicle_id, a.rent_time,a.rent_tenancy,b.vehicle_name,"+ "b.vehicle_vin,b.classify,b.vehicle_load,"+ "b.vehicle_people_number,b.vehicle_money,b.vehicle_days"+ "from rent_relation a ,vehicle b"+ "where a.vehicle_id = b.vehicle_id";List<RentRecord> records = new ArrayList<RentRecord>();try {connection = dbPoolConnection.getConnection();preparedStatement = connection.prepareStatement(selectSql);resultSet = preparedStatement.executeQuery();while (resultSet.next()) {RentRecord view = new RentRecord();view.setVehicleId(resultSet.getInt("vehicle_id"));view.setRentTime(resultSet.getString("rent_time"));view.setRentTenancy(resultSet.getInt("rent_tenancy"));view.setVehicleName(resultSet.getString("vehicle_name"));view.setVehicleVin(resultSet.getString("vehicle_vin"));view.setClassify(resultSet.getString("classify"));view.setVehicleLoad(resultSet.getInt("vehicle_load"));view.setVehiclePeople(resultSet.getInt("vehicle_people_number"));view.setVehicleMoney(resultSet.getInt("vehicle_money"));view.setVehicleDays(resultSet.getInt("vehicle_days"));records.add(view);}} catch (Exception e) {e.printStackTrace();} finally {DBPoolConnection.close(connection, preparedStatement);}return records;}public int selectRelationByUserIdAndVehicleId(int userId, int vehicleId) {DBPoolConnection dbPoolConnection = DBPoolConnection.getInstance();DruidPooledConnection connection = null;PreparedStatement preparedStatement = null;ResultSet resultSet = null;String selectSql = "select relation_id from rent_relation "+ "where vehicle_id = ?  and user_id =?";int recourdId=-1;try {connection = dbPoolConnection.getConnection();preparedStatement = connection.prepareStatement(selectSql);preparedStatement.setInt(1, vehicleId);preparedStatement.setInt(2, userId);resultSet = preparedStatement.executeQuery();if (resultSet.next()) {recourdId = resultSet.getInt(1);}} catch (Exception e) {e.printStackTrace();} finally {DBPoolConnection.close(connection, preparedStatement);}return recourdId;}public int deleteRentRelation(int relationId) {DBPoolConnection dbPoolConnection = DBPoolConnection.getInstance();DruidPooledConnection connection = null;PreparedStatement preparedStatement = null;ResultSet resultSet = null;String selectSql = "delete  from rent_relation "+ "where relation_id = ? ";int count=-1;try {connection = dbPoolConnection.getConnection();preparedStatement = connection.prepareStatement(selectSql);preparedStatement.setInt(1, relationId);		count = preparedStatement.executeUpdate();} catch (Exception e) {e.printStackTrace();} finally {DBPoolConnection.close(connection, preparedStatement);}return count;}}

service.impl.UserServiceImpl.java

package com.zsh.service.impl;import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;import com.alibaba.druid.pool.DruidPooledConnection;
import com.zsh.model.jdbc.RentRecord;
import com.zsh.service.RentRelationService;
import com.zsh.util.DBPoolConnection;public class RentRelationServiceImpl implements RentRelationService {public int insertRentRelation(int userId, int vehicleId, String rentTime,int rentTenancy) {int result = -1;DBPoolConnection dbPoolConnection = DBPoolConnection.getInstance();DruidPooledConnection connection = null;PreparedStatement preparedStatement = null;String insertSql = "insert into rent_relation (user_id,vehicle_id,rent_time,rent_tenancy) values (?,?,?,?)";try {connection = dbPoolConnection.getConnection();connection.setAutoCommit(true);preparedStatement = connection.prepareStatement(insertSql);preparedStatement.setInt(1, userId);preparedStatement.setInt(2, vehicleId);preparedStatement.setString(3, rentTime);preparedStatement.setInt(4, rentTenancy);result = preparedStatement.executeUpdate();} catch (Exception e) {e.printStackTrace();} finally {DBPoolConnection.close(connection, preparedStatement);}return result;}public List<RentRecord> selectRentRecord(int userId) {DBPoolConnection dbPoolConnection = DBPoolConnection.getInstance();DruidPooledConnection connection = null;PreparedStatement preparedStatement = null;ResultSet resultSet = null;String selectSql = "select a.vehicle_id, a.rent_time,a.rent_tenancy,b.vehicle_name, "+ " b.vehicle_vin,b.classify,b.vehicle_load, "+ " b.vehicle_people_number,b.vehicle_money,b.vehicle_days "+ " from rent_relation a ,vehicle b "+ " where a.vehicle_id = b.vehicle_id and a.user_id = ? ";List<RentRecord> records = new ArrayList<RentRecord>();try {connection = dbPoolConnection.getConnection();preparedStatement = connection.prepareStatement(selectSql);preparedStatement.setInt(1, userId);resultSet = preparedStatement.executeQuery();while (resultSet.next()) {RentRecord view = new RentRecord();view.setVehicleId(resultSet.getInt("vehicle_id"));view.setRentTime(resultSet.getString("rent_time"));view.setRentTenancy(resultSet.getInt("rent_tenancy"));view.setVehicleName(resultSet.getString("vehicle_name"));view.setVehicleVin(resultSet.getString("vehicle_vin"));view.setClassify(resultSet.getString("classify"));view.setVehicleLoad(resultSet.getInt("vehicle_load"));view.setVehiclePeople(resultSet.getInt("vehicle_people_number"));view.setVehicleMoney(resultSet.getInt("vehicle_money"));view.setVehicleDays(resultSet.getInt("vehicle_days"));records.add(view);}} catch (Exception e) {e.printStackTrace();} finally {DBPoolConnection.close(connection, preparedStatement);}return records;}public List<RentRecord> selectAllRentRecord() {DBPoolConnection dbPoolConnection = DBPoolConnection.getInstance();DruidPooledConnection connection = null;PreparedStatement preparedStatement = null;ResultSet resultSet = null;String selectSql = "select a.vehicle_id, a.rent_time,a.rent_tenancy,b.vehicle_name,"+ "b.vehicle_vin,b.classify,b.vehicle_load,"+ "b.vehicle_people_number,b.vehicle_money,b.vehicle_days"+ "from rent_relation a ,vehicle b"+ "where a.vehicle_id = b.vehicle_id";List<RentRecord> records = new ArrayList<RentRecord>();try {connection = dbPoolConnection.getConnection();preparedStatement = connection.prepareStatement(selectSql);resultSet = preparedStatement.executeQuery();while (resultSet.next()) {RentRecord view = new RentRecord();view.setVehicleId(resultSet.getInt("vehicle_id"));view.setRentTime(resultSet.getString("rent_time"));view.setRentTenancy(resultSet.getInt("rent_tenancy"));view.setVehicleName(resultSet.getString("vehicle_name"));view.setVehicleVin(resultSet.getString("vehicle_vin"));view.setClassify(resultSet.getString("classify"));view.setVehicleLoad(resultSet.getInt("vehicle_load"));view.setVehiclePeople(resultSet.getInt("vehicle_people_number"));view.setVehicleMoney(resultSet.getInt("vehicle_money"));view.setVehicleDays(resultSet.getInt("vehicle_days"));records.add(view);}} catch (Exception e) {e.printStackTrace();} finally {DBPoolConnection.close(connection, preparedStatement);}return records;}public int selectRelationByUserIdAndVehicleId(int userId, int vehicleId) {DBPoolConnection dbPoolConnection = DBPoolConnection.getInstance();DruidPooledConnection connection = null;PreparedStatement preparedStatement = null;ResultSet resultSet = null;String selectSql = "select relation_id from rent_relation "+ "where vehicle_id = ?  and user_id =?";int recourdId=-1;try {connection = dbPoolConnection.getConnection();preparedStatement = connection.prepareStatement(selectSql);preparedStatement.setInt(1, vehicleId);preparedStatement.setInt(2, userId);resultSet = preparedStatement.executeQuery();if (resultSet.next()) {recourdId = resultSet.getInt(1);}} catch (Exception e) {e.printStackTrace();} finally {DBPoolConnection.close(connection, preparedStatement);}return recourdId;}public int deleteRentRelation(int relationId) {DBPoolConnection dbPoolConnection = DBPoolConnection.getInstance();DruidPooledConnection connection = null;PreparedStatement preparedStatement = null;ResultSet resultSet = null;String selectSql = "delete  from rent_relation "+ "where relation_id = ? ";int count=-1;try {connection = dbPoolConnection.getConnection();preparedStatement = connection.prepareStatement(selectSql);preparedStatement.setInt(1, relationId);		count = preparedStatement.executeUpdate();} catch (Exception e) {e.printStackTrace();} finally {DBPoolConnection.close(connection, preparedStatement);}return count;}}

service.impl.VehicleServiceImpl.java

package com.zsh.service.impl;import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;import com.alibaba.druid.pool.DruidPooledConnection;
import com.zsh.model.jdbc.VehicleView;
import com.zsh.service.VehicleServie;
import com.zsh.util.DBPoolConnection;public class VehicleServiceImpl implements VehicleServie {public int addVehicle(VehicleView vehicle) {int result = -1;DBPoolConnection dbPoolConnection = DBPoolConnection.getInstance();DruidPooledConnection connection = null;PreparedStatement preparedStatement = null;String insertSql = "insert into vehicle (classify,vehicle_name,vehicle_number,vehicle_vin,vehicle_load,vehicle_people_number,vehicle_is_rent,vehicle_money,vehicle_days) values (?,?,?,?,?,?,?,?,?)";try {connection = dbPoolConnection.getConnection();connection.setAutoCommit(true);preparedStatement = connection.prepareStatement(insertSql);preparedStatement.setString(1, vehicle.getClassify());preparedStatement.setString(2, vehicle.getVehicleName());preparedStatement.setString(3, vehicle.getVehicleNumber());preparedStatement.setString(4, vehicle.getVehicleVin());preparedStatement.setInt(5, vehicle.getVehicleLoad());preparedStatement.setInt(6, vehicle.getVehiclePeopleNumber());preparedStatement.setInt(7, vehicle.getVehicleIsRent());preparedStatement.setInt(8, vehicle.getVehicleMoney());preparedStatement.setInt(9, vehicle.getVehicleDays());result = preparedStatement.executeUpdate();} catch (Exception e) {e.printStackTrace();} finally {DBPoolConnection.close(connection, preparedStatement);}return result;}public int updateVehicle(VehicleView vehicle) {int result = -1;DBPoolConnection dbPoolConnection = DBPoolConnection.getInstance();DruidPooledConnection connection = null;PreparedStatement preparedStatement = null;String insertSql = "update vehicle set  classify= ? ,vehicle_name= ? ,vehicle_number= ? ,vehicle_vin= ? ,vehicle_load= ? ,vehicle_people_number= ? ,vehicle_is_rent= ? ,vehicle_money= ? ,vehicle_days=? where vehicle_id = ?";try {connection = dbPoolConnection.getConnection();connection.setAutoCommit(true);preparedStatement = connection.prepareStatement(insertSql);preparedStatement.setString(1, vehicle.getClassify());preparedStatement.setString(2, vehicle.getVehicleName());preparedStatement.setString(3, vehicle.getVehicleNumber());preparedStatement.setString(4, vehicle.getVehicleVin());          preparedStatement.setInt(5, vehicle.getVehicleLoad());preparedStatement.setInt(6, vehicle.getVehiclePeopleNumber());preparedStatement.setInt(7, vehicle.getVehicleIsRent());preparedStatement.setInt(8, vehicle.getVehicleMoney());preparedStatement.setInt(9, vehicle.getVehicleDays());preparedStatement.setInt(10, vehicle.getVehicleId());result = preparedStatement.executeUpdate();} catch (Exception e) {e.printStackTrace();} finally {DBPoolConnection.close(connection, preparedStatement);}return result;}public int deleteVehicle(int vehicleId) {int result = -1;DBPoolConnection dbPoolConnection = DBPoolConnection.getInstance();DruidPooledConnection connection = null;PreparedStatement preparedStatement = null;String insertSql = "delete from vehicle where vehicle_id = ?";try {connection = dbPoolConnection.getConnection();connection.setAutoCommit(true);preparedStatement = connection.prepareStatement(insertSql);preparedStatement.setInt(1, vehicleId);result = preparedStatement.executeUpdate();} catch (Exception e) {e.printStackTrace();} finally {DBPoolConnection.close(connection, preparedStatement);}return result;}public List<VehicleView> selectAll() {DBPoolConnection dbPoolConnection = DBPoolConnection.getInstance();DruidPooledConnection connection = null;PreparedStatement preparedStatement = null;ResultSet resultSet = null;String selectSql = "select * from vehicle";List<VehicleView> vehicleViews = new ArrayList<VehicleView>();try {connection = dbPoolConnection.getConnection();preparedStatement = connection.prepareStatement(selectSql);resultSet = preparedStatement.executeQuery();while (resultSet.next()) {VehicleView view = new VehicleView();view.setVehicleId(resultSet.getInt("vehicle_id"));view.setClassify(resultSet.getString("classify"));view.setVehicleName(resultSet.getString("vehicle_name"));view.setVehicleNumber(resultSet.getString("vehicle_number"));view.setVehicleVin(resultSet.getString("vehicle_vin"));view.setVehicleLoad(resultSet.getInt("vehicle_load"));view.setVehiclePeopleNumber(resultSet.getInt("vehicle_people_number"));view.setVehicleIsRent(resultSet.getInt("vehicle_is_rent"));view.setVehicleMoney(resultSet.getInt("vehicle_money"));view.setVehicleDays(resultSet.getInt("vehicle_days"));vehicleViews.add(view);}} catch (Exception e) {e.printStackTrace();} finally {DBPoolConnection.close(connection, preparedStatement);}return vehicleViews;}public List<VehicleView> selectCanRentVehicles() {DBPoolConnection dbPoolConnection = DBPoolConnection.getInstance();DruidPooledConnection connection = null;PreparedStatement preparedStatement = null;ResultSet resultSet = null;String selectSql = "select * from vehicle where vehicle_is_rent = 1";List<VehicleView> vehicleViews = new ArrayList<VehicleView>();try {connection = dbPoolConnection.getConnection();preparedStatement = connection.prepareStatement(selectSql);resultSet = preparedStatement.executeQuery();while (resultSet.next()) {VehicleView view = new VehicleView();view.setVehicleId(resultSet.getInt("vehicle_id"));view.setClassify(resultSet.getString("classify"));view.setVehicleName(resultSet.getString("vehicle_name"));view.setVehicleNumber(resultSet.getString("vehicle_number"));view.setVehicleVin(resultSet.getString("vehicle_vin"));	            	view.setVehicleLoad(resultSet.getInt("vehicle_load"));view.setVehiclePeopleNumber(resultSet.getInt("vehicle_people_number"));view.setVehicleIsRent(resultSet.getInt("vehicle_is_rent"));view.setVehicleMoney(resultSet.getInt("vehicle_money"));view.setVehicleDays(resultSet.getInt("vehicle_days"));vehicleViews.add(view);}} catch (Exception e) {e.printStackTrace();} finally {DBPoolConnection.close(connection, preparedStatement);}return vehicleViews;}public VehicleView getVehicleById(int vehicleId) {DBPoolConnection dbPoolConnection = DBPoolConnection.getInstance();DruidPooledConnection connection = null;PreparedStatement preparedStatement = null;ResultSet resultSet = null;String selectSql = "select * from vehicle where vehicle_id = ?";VehicleView view =null;try {connection = dbPoolConnection.getConnection();preparedStatement = connection.prepareStatement(selectSql);preparedStatement.setInt(1, vehicleId);resultSet = preparedStatement.executeQuery();if (resultSet.next()) {view = new VehicleView();view.setVehicleId(resultSet.getInt("vehicle_id"));view.setClassify(resultSet.getString("classify"));view.setVehicleName(resultSet.getString("vehicle_name"));view.setVehicleNumber(resultSet.getString("vehicle_number"));view.setVehicleVin(resultSet.getString("vehicle_vin"));            	view.setVehicleLoad(resultSet.getInt("vehicle_load"));view.setVehiclePeopleNumber(resultSet.getInt("vehicle_people_number"));view.setVehicleIsRent(resultSet.getInt("vehicle_is_rent"));view.setVehicleMoney(resultSet.getInt("vehicle_money"));view.setVehicleDays(resultSet.getInt("vehicle_days"));}} catch (Exception e) {e.printStackTrace();} finally {DBPoolConnection.close(connection, preparedStatement);}return view;}}

service包:
ClassifyService.java

package com.zsh.service;public interface ClassifyService {/*** 返回新增数据的ID* @return*/int insertClsssify(String classifyName);
}

RentRelationService.java

package com.zsh.service;import java.util.List;import com.zsh.model.jdbc.RentRecord;public interface RentRelationService {/*** 新增租车记录* * @return*/int insertRentRelation(int userId, int vehicleId, String rentTime,int rentTenancy);/*** 查询某个用户的租车记录* @return*/List<RentRecord> selectRentRecord(int userId);/*** 查询租车记录* @return*/List<RentRecord> selectAllRentRecord();/*** 根据用户ID 车辆ID查询租车记录* @param userId* @param vehicleId* @return*/int selectRelationByUserIdAndVehicleId(int userId,int vehicleId);/*** 删除租车记录 退租车辆* @param relationId* @return*/int  deleteRentRelation(int relationId);}

UserService.java

package com.zsh.service;import java.util.List;import com.zsh.model.jdbc.UserView;public interface UserService {/*** 新增用户*/int insertUser(UserView userView);/*** 删除用户*/int deleteUser(int userId);/*** 登录* @param userName* @param pwd* @return*/UserView login(String userName,String pwd);/*** 查询所有用户* @return*/List<UserView> listUser();
}

VehicleService.java

package com.zsh.service;import java.util.List;import com.zsh.model.jdbc.VehicleView;public interface VehicleServie {List<VehicleView> selectAll();/*** 新增车辆信息* @param vehicleView* @return*/int addVehicle(VehicleView vehicle);/*** 更新车辆信息* @param vehicleView* @return*/int updateVehicle(VehicleView vehicle);/*** 删除车辆信息* @param vehicleView* @return*/int deleteVehicle(int vehicleId);/*** 查询可租车辆信息* @return*/List<VehicleView> selectCanRentVehicles();/*** 根据车辆ID查找车辆信息* @param vehicleId* @return*/VehicleView getVehicleById(int vehicleId);
}

三 : util包

util.DateUtil.java

package com.zsh.util;import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;/*** 日期工具类* * */
public class DateUtil {/** yyyy-MM-dd HH:mm:ss */public static final String date_mask_ss = "yyyy-MM-dd HH:mm:ss";/** yyyy-MM-dd HH:mm */public static final String date_mask_mm = "yyyy-MM-dd HH:mm";/** yyyy-MM-dd */public static final String date_mask_dd = "yyyy-MM-dd";/*** 获取日期格式 yyyy-MM-dd HH:mm:ss* * @return*/private static SimpleDateFormat getDateFormat() {SimpleDateFormat df = new SimpleDateFormat(date_mask_ss);return df;}/*** 获取指定日期格式* * @param date_mask* @return*/private static SimpleDateFormat getDateFormat(String date_mask) {SimpleDateFormat df;if (StringUtil.isEmpty(date_mask)) {df = getDateFormat();} else {df = new SimpleDateFormat(date_mask);}return df;}/*** * Date类型转换为String类型 yyyy-MM-dd HH:mm:ss* * @param date* */public static String formatDate(Date date) {if (date != null) {return getDateFormat().format(date);} else {return null;}}/*** Date类型转换为String类型* @param date* @param mask* @return*/public static String formatDate(Date date, String date_mask) {if (StringUtil.isEmpty(date_mask)) {date_mask = "yyyy-MM-dd HH:mm:ss";}if (date != null) {SimpleDateFormat df = getDateFormat(date_mask);return df.format(date);} else {return null;}}/*** Date类型转换为String类型* @param date* @param mask* @return*/public static String formatDate(Date date, String date_mask,String id) {if (StringUtil.isEmpty(date_mask)) {date_mask = "yyyy-MM-dd HH:mm:ss";}if (date != null) {SimpleDateFormat df = getDateFormat(date_mask);df.setTimeZone(TimeZone.getTimeZone(id));return df.format(date);} else {return null;}}/*** * 字符串类型转为Date类型* * @param time* */public static Date parseDate(String time) {try {return getDateFormat().parse(time);} catch (ParseException e) {e.printStackTrace();}return null;}public static Date parseDate(String time, String date_mask) {try {return getDateFormat(date_mask).parse(time);} catch (ParseException e) {e.printStackTrace();}return null;}public static Date endDate(String time, String date_mask){Date date=parseDate(time,date_mask);date.setHours(23);date.setMinutes(59);date.setSeconds(59);return date;}public static void main(String[] args) {System.out.println(formatDate(null));}}

util.DBPoolConnection.java

package com.zsh.util;import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Properties;import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.alibaba.druid.pool.DruidPooledConnection;
/*** Created by zsh on 2019/8/7.*/
public class DBPoolConnection {private static DBPoolConnection dbPoolConnection = null;private static DruidDataSource druidDataSource = null;//初始化配置文件及数据源static {Properties properties = PropertiesUtil.loadPropertiesFile("info.properties");try {druidDataSource = (DruidDataSource)DruidDataSourceFactory.createDataSource(properties); //DruidDataSrouce工厂模式} catch (Exception e) {e.printStackTrace();}}/*** 数据库连接池单例* @return*/public static synchronized DBPoolConnection getInstance(){if (null == dbPoolConnection){dbPoolConnection = new DBPoolConnection();}return dbPoolConnection;}/*** 返回druid数据库连接* @return* @throws SQLException*/public DruidPooledConnection getConnection() throws SQLException{return druidDataSource.getConnection();} /*** 关闭连接* @param connection* @param preparedStatement*/public static void close(DruidPooledConnection connection, PreparedStatement preparedStatement){if (preparedStatement != null) {try {preparedStatement.close();} catch (SQLException sqlException) {sqlException.printStackTrace();System.out.println("preparedStatement closed by some exception");}}if (connection != null) {try {connection.close();} catch (SQLException sqlException) {sqlException.printStackTrace();System.out.println("connection closed by some exception");}}}
}

util.PropertiesUtil.java

package com.zsh.util;
import java.io.InputStream;
import java.util.Properties;
/*** Created by zsh on 2018/8/8.*/
public class PropertiesUtil {/*** @param fullFile 配置文件名* @return Properties 对象*/public static Properties loadPropertiesFile(String fullFile) {if (null == fullFile || fullFile.equals("")){throw new IllegalArgumentException("Properties file path can not be null" + fullFile);}InputStream inputStream = null;Properties p =null;try {inputStream = PropertiesUtil.class.getClassLoader().getResourceAsStream(fullFile);p = new Properties();p.load(inputStream);} catch (Exception e) {e.printStackTrace();} finally {try {if (null != inputStream){inputStream.close();}} catch (Exception e) {e.printStackTrace();}}return p;}
}

util.StringUtil.java

package com.zsh.util;
import java.util.Collection;
/*** 字符串工具类* @author zsh**/
public class StringUtil {/*** 判断字符串时候为null或空字符串** @param str*            需要判断的字符串* @return 为null或空字符串返回true,否则返回false*/public static boolean isEmpty(String str) {return str == null || str.trim().length() == 0;}/*** 单个数组转字符串.* * @param arr*            需要转换的数组* @param separator*            分隔符* @return 转换之后的字符串*/public static String arrToString(Object[] arr, String separator) {StringBuilder sb = new StringBuilder();for (Object object : arr) {sb.append(object).append(separator);}return sb.substring(0, sb.length() - 1);}/*** 两个数组转字符串.* @param arr1数组1* @param arr2数组2* @param separator1分隔符1* @param separator2分隔符2* @return 转换之后的字符串*/public static String doubleArrToString(Object[] arr1, Object[] arr2,String separator1, String separator2) {StringBuilder sb = new StringBuilder();for (int i = 0; i < arr1.length; i++) {sb.append(arr1[i]).append(separator1).append(arr2[i]).append(separator2);}return sb.substring(0, sb.length() - 1);}/*** Collection 转字符串.* @param collection需要转换的Collection* @param separator分隔符* @return 转换之后的字符串*/public static String collectionToString(Collection<?> collection,String separator) {StringBuilder sb = new StringBuilder();for (Object object : collection) {sb.append(object).append(separator);}return sb.substring(0, sb.length() - 1);}/*** 判断两字符串是不是相同* @param argStr1* @param argStr2* @return*/public static boolean equalsString(String argStr1, String argStr2) {if ((argStr1 == null) && (argStr2 == null)) {return true;}if ((argStr1 == null) || (argStr2 == null)) {return false;}return argStr1.equals(argStr2);}public static void main(String[] args) {String str = "张叔行/123/男/20/410327199911157766/15054376562134245654/13824993670";String[] userArray = str.split("/");for (String string : userArray) {System.out.println(string);}}
}

四 : view包

view.Manager.java

package com.zsh.view;import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.Scanner;import com.zsh.model.jdbc.RentRecord;
import com.zsh.model.jdbc.UserView;
import com.zsh.model.jdbc.VehicleView;
import com.zsh.service.RentRelationService;
import com.zsh.service.UserService;
import com.zsh.service.VehicleServie;
import com.zsh.service.impl.RentRelationServiceImpl;
import com.zsh.service.impl.UserServiceImpl;
import com.zsh.service.impl.VehicleServiceImpl;
import com.zsh.util.DateUtil;
import com.zsh.util.PropertiesUtil;
import com.zsh.util.StringUtil;/*** 程序入口程序* * @author zsh* */
public class Manage {static Properties properties = PropertiesUtil.loadPropertiesFile("config.properties");public static void main(String[] args) {enter();}/*** 程序业务逻辑入口*/public static void enter() {System.out.print("------------欢迎进入租车系统!------------\r\n【1】管理人员   【2】用户\r\n请输入:");Scanner sc = new Scanner(System.in);int opt = sc.nextInt();System.out.println();if (opt == 1) {// 管理员System.out.println("----管理员-----");System.out.print("账户名:");String adminName = sc.next();System.out.print("密码:");String adminPwd = sc.next();System.out.println("-------------");System.out.println();adminManage(adminName, adminPwd);} else {// 用户System.out.println("-----用户-----");System.out.print("账户名:");String userName = sc.next();System.out.print("密码:");String userPwd = sc.next();System.out.println("-------------");System.out.println();userManage(userName, userPwd);}}public static void exit() {System.out.println("您已成功退出租车管理系统!");System.exit(0);}/*** 后台管理员功能* * @param adminName* @param adminPwd*/public static void adminManage(String adminName, String adminPwd) {// 0:登录String name = properties.getProperty("adminName");String pwd = properties.getProperty("adminPwd");if (StringUtil.equalsString(name, adminName)&& StringUtil.equalsString(pwd, adminPwd)) {System.out.println("----管理员-----");System.out.print(name+ " 已登录成功,\r\n1:车辆列表\r\n2:用户列表\r\n3:租车记录表\r\n4:注销账户\r\n0:退出系统\r\n请输入编号进入相应的功能:");Scanner sc = new Scanner(System.in);int opt = sc.nextInt();if (opt == 1) {// 车辆列表listVehicle(adminName, adminPwd);}if (opt == 2) {// 用户列表userList(adminName, adminPwd);}if (opt == 3) {// 租车记录表rentRecord(adminName, adminPwd);}if (opt == 4) {// 注销账户enter();}if (opt == 0) {// 退出系统exit();}} else {// 返回入口页面enter();}}/*** 用户表* * @param adminName* @param adminPwd*/private static void userList(String adminName, String adminPwd) {Scanner sc = new Scanner(System.in);UserService userService = (UserService) new UserServiceImpl();// 1:用户列表// 1.1:新增用户// 1.2:删除用户List<UserView> users = null;users = userService.listUser();String listStr = "";for (UserView user : users) {listStr += user.getUserId() + "\t";listStr += user.getUserName() + "\t";listStr += user.getSex() + "\t";listStr += user.getAge() + "\t";listStr += user.getDriverNumber() + "\t";listStr += user.getIcNumber() + "\t";listStr += user.getPhone() + "\t";listStr += "\r\n";}System.out.println(listStr+ "请输入编号进入相应的功能:\r\n1:新增用户\r\n2:删除用户\r\n3:返回上一步\r\n4:注销账户\r\n0:退出系统");int opt = sc.nextInt();if (opt == 1) {System.out.println("新增用户,请按照如下格式输入用户信息:\r\n用户姓名/密码/性别/年龄/驾驶证号/身份证号/手机号");String formatStr = sc.next();String[] userArray = formatStr.split("/");UserView user = new UserView();user.setUserName(userArray[0]);user.setPwd(userArray[1]);user.setSex(userArray[2]);user.setAge(Integer.parseInt(userArray[3]));user.setDriverNumber(userArray[4]);user.setIcNumber(userArray[5]);user.setPhone(userArray[6]);if (userService.insertUser(user) > 0)System.out.println("新增用户成功!");userList(adminName, adminPwd);}if (opt == 2) {System.out.println("输入要删除的用户的编号:");int userId = sc.nextInt();if (userService.deleteUser(userId) > 0)System.out.println("编号为" + userId + "的用户信息已删除!");elseSystem.out.println("输入编号为" + userId + "的用户未删除成功!");userList(adminName, adminPwd);}if (opt == 3) {// 返回上一部adminManage(adminName, adminPwd);}if (opt == 4) {// 注销账户enter();}if (opt == 0) {// 退出系统exit();}}/*** 租车记录表* * @param adminName* @param adminPwd*/private static void rentRecord(String adminName, String adminPwd) {Scanner sc = new Scanner(System.in);RentRelationService rentService = new RentRelationServiceImpl();List<RentRecord> records = rentService.selectAllRentRecord();String listStr = "车辆名称\t车辆识别码\t车辆类别\t载重(吨)\t可乘人数\t租金(元/天)\t可租天数\t租赁日期\t租期(小时) \r\n";for (RentRecord rentRecord : records) {listStr += rentRecord.getVehicleName() + "\t";listStr += rentRecord.getVehicleVin() + "\t";listStr += rentRecord.getClassify() + "\t";listStr += rentRecord.getVehicleLoad() + "\t";listStr += rentRecord.getVehiclePeople() + "\t";listStr += rentRecord.getVehicleMoney() + "\t";listStr += rentRecord.getVehicleDays() + "\t";listStr += rentRecord.getRentTime() + "\t";listStr += rentRecord.getRentTenancy() + "\t";listStr += "\r\n";}System.out.println(listStr+ "请输入编号进入相应的功能:\r\n1:返回上一层\r\n2:注销账户\r\n0:退出系统");int opt = sc.nextInt();if (opt == 1) {adminManage(adminName, adminPwd);}if (opt == 4) {// 注销账户enter();}if (opt == 0) {// 退出系统exit();}}/*** 车辆列表*/private static void listVehicle(String userName, String pwd) {Scanner sc = new Scanner(System.in);VehicleServie vehicleServie = new VehicleServiceImpl();List<VehicleView> list = vehicleServie.selectAll();System.out.println("----管理员-----");String listStr = "编号\t分类\t车辆名称\t车辆牌照\t车辆识别码\t\t载重(吨)\t可乘人数\t是否可租\t租金(元/天)\t可租天数 \r\n";for (VehicleView vehicleView : list) {listStr += vehicleView.getVehicleId() + "\t";listStr += vehicleView.getClassify() + "\t";listStr += vehicleView.getVehicleName() + "\t";listStr += vehicleView.getVehicleNumber() + "\t";listStr += vehicleView.getVehicleVin() + "\t";listStr += vehicleView.getVehicleLoad() + "\t";listStr += vehicleView.getVehiclePeopleNumber() + "人\t";listStr += (vehicleView.getVehicleIsRent() == 0 ? "不可租" : "可租")+ "\t";listStr += vehicleView.getVehicleMoney() + "元\t";listStr += vehicleView.getVehicleDays() + "天\t";listStr += "\r\n";}System.out.print(listStr+ "功能:\r\n1:新增车辆\r\n2:修改车辆\r\n3:删除车辆\r\n4:返回上一步\r\n5:注销账户\r\n0:退出系统\r\n请输入编号进入相应的功能:");int optNumber = sc.nextInt();if (optNumber == 1) {// 新增车辆System.out.println("----管理员-----");System.out.println("新增车辆,请按照如下格式输入车辆信息:\r\n车辆分类(客车|货车|皮卡)/车辆名称/车辆牌照/车辆vin码/车辆载重/准乘人数/天租金/可租天数");String formatStr = sc.next();String[] vehicleArray = formatStr.split("/");VehicleView vehicle = new VehicleView();vehicle.setClassify(vehicleArray[0]);vehicle.setVehicleName(vehicleArray[1]);vehicle.setVehicleNumber(vehicleArray[2]);vehicle.setVehicleVin(vehicleArray[3]);String load = vehicleArray[4];String peoperNumber = vehicleArray[5];vehicle.setVehicleLoad(StringUtil.isEmpty(load) ? 0 : Integer.parseInt(load));vehicle.setVehiclePeopleNumber(StringUtil.isEmpty(peoperNumber) ? 0: Integer.parseInt(peoperNumber));vehicle.setVehicleIsRent(1);vehicle.setVehicleMoney(Integer.parseInt(vehicleArray[6]));vehicle.setVehicleDays(Integer.parseInt(vehicleArray[7]));if (vehicleServie.addVehicle(vehicle) > 0)System.out.println("新增车辆成功!");listVehicle(userName, pwd);}if (optNumber == 2) {// 修改车辆System.out.println("----管理员-----");System.out.print("输入要修改的车辆编号:");int vehicleId = sc.nextInt();System.out.println("修改车辆,请按照如下格式输入车辆信息:\r\n车辆分类(客车|货车|皮卡)/车辆名称/车辆牌照/车辆vin码/车辆载重/准乘人数/天租金/可租天数");String formatStr = sc.next();String[] vehicleArray = formatStr.split("/");VehicleView vehicle = new VehicleView();vehicle.setVehicleId(vehicleId);vehicle.setClassify(vehicleArray[0]);vehicle.setVehicleName(vehicleArray[1]);vehicle.setVehicleNumber(vehicleArray[2]);vehicle.setVehicleVin(vehicleArray[3]);vehicle.setVehicleLoad(Integer.parseInt(vehicleArray[4]));vehicle.setVehiclePeopleNumber(Integer.parseInt(vehicleArray[5]));vehicle.setVehicleMoney(Integer.parseInt(vehicleArray[6]));vehicle.setVehicleDays(Integer.parseInt(vehicleArray[7]));if (vehicleServie.updateVehicle(vehicle) > 0)System.out.println("更新车辆信息成功!");listVehicle(userName, pwd);}if (optNumber == 3) {// 删除车辆System.out.println("----管理员-----");System.out.print("输入要删除的车辆的编号:");int vehicleId = sc.nextInt();if (vehicleServie.deleteVehicle(vehicleId) > 0)System.out.println("编号为" + vehicleId + "的车辆信息已删除!");elseSystem.out.println("输入编号为" + vehicleId + "的车辆未删除成功!");listVehicle(userName, pwd);}if (optNumber == 4) {// 返回上一层adminManage(userName, pwd);}if (optNumber == 5) {// 注销账户enter();}if (optNumber == 0) {// 退出系统exit();}}/*** 用户功能* * @param userName* @param userPwd*/public static void userManage(String userName, String userPwd) {// 用户管理功能// 1:登录UserService userService = new UserServiceImpl();UserView user = userService.login(userName, userPwd);if (user != null) {userRentVehicle(user.getUserId());} else {// 返回入口页面enter();}}/*** 用户功能 页面* * @param userId*/public static void userRentVehicle(int userId) {// 2:查看可租车辆信息System.out.println("----用户-----");System.out.print("您已登录成功\r\n功能:\r\n1:查看已租车辆 \r\n2:查看可租车辆信息\r\n请输入编号进入相应的功能:");Scanner sc = new Scanner(System.in);int optNumber = sc.nextInt();RentRelationService rentService = new RentRelationServiceImpl();if (optNumber == 1) {// 查看已租车辆信息System.out.println("----用户-----");List<RentRecord> records = rentService.selectRentRecord(userId);String listStr = "车辆ID\t车辆名称\t      车辆识别码\t车辆类别\t载重(吨)\t可乘人数\t租金\t可租天数\t         租赁日期\t租期(小时) \r\n";for (RentRecord rentRecord : records) {listStr += rentRecord.getVehicleId() + "\t";listStr += rentRecord.getVehicleName() + "\t";listStr += rentRecord.getVehicleVin() + "\t";listStr += rentRecord.getClassify() + "\t";listStr += rentRecord.getVehicleLoad() + "\t";listStr += rentRecord.getVehiclePeople() + "\t";listStr += rentRecord.getVehicleMoney() + "\t";listStr += rentRecord.getVehicleDays() + "\t";listStr += rentRecord.getRentTime() + "\t";listStr += rentRecord.getRentTenancy() + "\t";listStr += "\r\n";}			System.out.print(listStr+ "功能:\r\n1:返回上一层\r\n2:退租车辆\r\n4:注销账户\r\n0:退出系统\r\n请输入编号进入相应的功能:");int opt = sc.nextInt();if (opt == 1) {userRentVehicle(userId);}if (opt == 2) {//  退租车辆backRentVehicle(userId);}if (opt == 4) {// 注销账户enter();}if (opt == 0) {// 退出系统exit();}}if (optNumber == 2) {// 查看可租车辆信息VehicleServie vehicleServie = new VehicleServiceImpl();List<VehicleView> vehicles = vehicleServie.selectCanRentVehicles();String listStr = "";for (VehicleView vehicleView : vehicles) {listStr += vehicleView.getVehicleId() + "\t";listStr += vehicleView.getClassify() + "\t";listStr += vehicleView.getVehicleName() + "\t";listStr += vehicleView.getVehicleNumber() + "\t";listStr += vehicleView.getVehicleVin() + "\t";listStr += vehicleView.getVehicleLoad() + "\t";listStr += vehicleView.getVehiclePeopleNumber() + "\t";listStr += vehicleView.getVehicleMoney() + "\t";listStr += vehicleView.getVehicleDays() + "\t";listStr += "\r\n";}System.out.print(listStr+ "功能:\r\n 1:租车\r\n 2:返回上一层\r\n 3:注销账户\r\n 0:退出系统\r\n请输入编号进入相应的功能:");int opt = sc.nextInt();if (opt == 1) {// 租车rentVehicle(userId);}if (opt == 2) {// 返回上一层userRentVehicle(userId);}if (opt == 3) {// 注销账户enter();}if (opt == 0) {// 退出系统exit();}}}/*** 用户租车* * @param userId*/private static void rentVehicle(int userId) {System.out.print("请输入车辆编号:");Scanner sc = new Scanner(System.in);int vehicleId = sc.nextInt();// 查询是否可租VehicleServie vehicleService = new VehicleServiceImpl();VehicleView view = vehicleService.getVehicleById(vehicleId);if (view.getVehicleIsRent() == 1) {System.out.print("请输入租车天数:");int days = sc.nextInt();int money = days * view.getVehicleMoney();System.out.println("您选择的" + view.getVehicleName() + "车辆 租金为:"+ money + "元,支付完成即可租车成功!");RentRelationService rentService = new RentRelationServiceImpl();rentService.insertRentRelation(userId, vehicleId,DateUtil.formatDate(new Date(System.currentTimeMillis())),days * 24);view.setVehicleIsRent(0);vehicleService.updateVehicle(view);} else {System.out.println("您所输入的车辆目前不可租!");}// 返回到用户功能页面userRentVehicle(userId);}/*** 用户退租* * @param userId*/private static void backRentVehicle(int userId) {System.out.print("请输入车辆编号:");Scanner sc = new Scanner(System.in);int vehicleId = sc.nextInt();// 查询是否在个人租车列表中RentRelationService relationService = new RentRelationServiceImpl();int recordId = relationService.selectRelationByUserIdAndVehicleId(userId, vehicleId);if (recordId != 0) {// 执行退租操作if (relationService.deleteRentRelation(recordId) > 0) {// 更新车辆状态VehicleServie vehicleService = new VehicleServiceImpl();VehicleView view = vehicleService.getVehicleById(vehicleId);view.setVehicleIsRent(1);vehicleService.updateVehicle(view);}} else {System.out.println("您所输入的车辆不是您所租赁的车辆!");}// 返回到用户功能页面userRentVehicle(userId);}}

五 : config.properties文件

在这里插入图片描述

六 : info.properties文件

在这里插入图片描述
看到这里程序已经全部结束,相信会对你的学习和理解有很大的帮助。

了解更多关注我呦!!!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/565905.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【OpenCV 例程200篇】61. 导向滤波(Guided filter)

【OpenCV 例程200篇】61. 导向滤波&#xff08;Guided filter&#xff09; 欢迎关注 『OpenCV 例程200篇』 系列&#xff0c;持续更新中 欢迎关注 『Python小白的OpenCV学习课』 系列&#xff0c;持续更新中 图像滤波是在尽可能保留图像细节特征的条件下对目标图像的噪声进行抑…

使用MATLAB GUI创建图形用户界面GUI

MATLAB是众多理工科学生及工程师经常使用的一款数学软件&#xff0c;除了可以实现数据处理&#xff0c;矩阵运算、函数绘制等功能外&#xff0c;MATLAB还可以实现图形用户界面的设计。 下面介绍如何让小白也能用GUI创建最基本的用户界面&#xff0c;并帮助大家学会在今后的…

【OpenCV 例程200篇】62. 图像锐化——钝化掩蔽

【OpenCV 例程200篇】62. 图像锐化——钝化掩蔽 欢迎关注 『OpenCV 例程200篇』 系列&#xff0c;持续更新中 欢迎关注 『Python小白的OpenCV学习课』 系列&#xff0c;持续更新中 3. 空间域锐化滤波&#xff08;高通滤波&#xff09; 图像模糊通过平滑&#xff08;加权平均&a…

AJAX基本用法

在工作中和一些大项目制作的时候&#xff0c;许多人都会选择使用前后端分离技术即AJAX进行项目的制作&#xff0c;使用AJAX不仅能提高效率而且更容易修改&#xff0c;使我们制作项目的时候更加的得心应手。 在此给大家讲解一下AJAX的用法&#xff0c;一共有五个核心内容&#…

【OpenCV 例程200篇】63. 图像锐化之 Laplacian 算子

【OpenCV 例程200篇】63. 图像锐化之 Laplacian 算子 欢迎关注 『OpenCV 例程200篇』 系列&#xff0c;持续更新中 欢迎关注 『Python小白的OpenCV学习课』 系列&#xff0c;持续更新中 3. 空间域锐化滤波&#xff08;高通滤波&#xff09; 图像模糊通过平滑&#xff08;加权平…

秒表计时器

使用Jquery制作了一个漂亮的秒表计时器。 效果图 原始样式 点击开始之后 点击停止再点击清零之后 有没有一种心动的感觉呢&#xff0c;下面看代码。 代码演示 首先注意哦&#xff1a;引入相对应的Jquery架包。 代码 <!DOCTYPE html> <html><head>&l…

【OpenCV 例程200篇】64. 图像锐化——Sobel 算子

【OpenCV 例程200篇】64. 图像锐化——Sobel 算子 欢迎关注 『OpenCV 例程200篇』 系列&#xff0c;持续更新中 欢迎关注 『Python小白的OpenCV学习课』 系列&#xff0c;持续更新中 3. 空间域锐化滤波&#xff08;高通滤波&#xff09; 图像模糊通过平滑&#xff08;加权平均…

sklearn特征工程

本文转载 使用sklearn做单机特征工程 目录 1 特征工程是什么&#xff1f; 2 数据预处理   2.1 无量纲化     2.1.1 标准化     2.1.2 区间缩放法     2.1.3 标准化与归一化的区别   2.2 对定量特征二值化   2.3 对定性特征哑编码   2.4 缺失值计算   …

秒表倒计时

使用JavaScript实现秒表的倒计时。 我设置的是五分钟倒计时&#xff0c;倒计时时间是可以自己随意设置的。 效果图 代码演示 <!DOCTYPE html> <html><head><meta charset"utf-8" /><title></title></head><style>…

【OpenCV 例程200篇】65. 图像锐化——Scharr 算子

【OpenCV 例程200篇】65. 图像锐化——Scharr 算子 欢迎关注 『OpenCV 例程200篇』 系列&#xff0c;持续更新中 欢迎关注 『Python小白的OpenCV学习课』 系列&#xff0c;持续更新中 3. 空间域锐化滤波&#xff08;高通滤波&#xff09; 图像模糊通过平滑&#xff08;加权平均…

【转】常用的风控算法模型评价指标

1. 基本概念 FNTPTNFP TP —— True Positive &#xff08;真正, TP&#xff09;被模型预测为正的正样本&#xff1b;可以称作判断为真的正确率 TN —— True Negative&#xff08;真负 , TN&#xff09;被模型预测为负的负样本 &#xff1b;可以称作判断为假的正确率 FP ——…

【OpenCV 例程200篇】66. 图像滤波之低通/高通/带阻/带通

【OpenCV 例程200篇】66. 图像滤波之低通/高通/带阻/带通 欢迎关注 『OpenCV 例程200篇』 系列&#xff0c;持续更新中 欢迎关注 『Python小白的OpenCV学习课』 系列&#xff0c;持续更新中 4. 低通、高通、带阻、带通 图像滤波是在尽可能保留图像细节特征的条件下对目标图像的…

滑动登录

鼠标点击拖动滑块即可快速完成登录。 程序分析&#xff1a; 鼠标点击鼠标点击后拖动滑块鼠标点击取消滑块水平移动 效果图演示 初始页面 点击滑块进行拖动 此时的你是不是急于想实现它呢&#xff1f;&#xff1f;&#xff1f; 代码演示 <!DOCTYPE html><html …

Jupyter 快速入门

前言 之前一直在断断续续使用jupyter&#xff0c;感觉是时间来整理一下快速入门的办法了&#xff0c;方便实施建模使用。 1 Jupyter介绍 Jupyter Notebook是一个交互式笔记本编译器&#xff0c;支持在网页端运行多种编程语言&#xff0c;其本质就是一个基于web交互的程序编译…

【课题总结】OpenCV 抠图项目实战(1)目录摘要

Python 小白的课题报告—OpenCV 抠图项目实战&#xff08;1&#xff09;目录摘要 本系列是 Python 小白的课题作业《基于OpenCV 的图像分割和抠图》。 需要说明的是&#xff0c;本系列并不能算是 OpenCV 的抠图项目教程&#xff0c;只是以此为主题的课题报告。其中包括了一个较…

Vue 滑动验证

用Vue实现滑动验证码&#xff0c;鼠标点击滑动验证&#xff0c;验证成功之后会显示验证通过。 程序分析 鼠标的点击滑块的拖动未验证之前滑动条上显示的文字滑块箭头指向Vue函数判断是否拖动完毕拖动完毕时改变背景色并显示验证成功 效果图演示 原始状态 点击之后拖动 拖…

【课题总结】OpenCV 抠图项目实战(2)抠图绪论

Python 小白的课题报告&#xff1a;OpenCV 抠图项目实战&#xff08;2&#xff09;抠图绪论 本系列是 Python 小白的课题作业《基于OpenCV 的图像分割和抠图》。 需要说明的是&#xff0c;本系列并不能算是 OpenCV 的抠图项目教程&#xff0c;只是以此为主题的课题报告。其中包…

滑动解锁

模仿手机解锁滑动&#xff0c;点击向右滑动完毕即可显示解锁成功。 程序详解 1.点击和松开事件 2. 未解锁之前显示的样式和背景色 3. 解锁之后显示的样式和背景色 4. 滑动完毕后才能解锁 图片演示 原始界面 点击滑动后 解锁成功 下面我们跟随我一起来欣赏一下代码 代码…

Python中利用LSTM模型进行时间序列预测分析

时间序列模型 时间序列预测分析就是利用过去一段时间内某事件时间的特征来预测未来一段时间内该事件的特征。这是一类相对比较复杂的预测建模问题&#xff0c;和回归分析模型的预测不同&#xff0c;时间序列模型是依赖于事件发生的先后顺序的&#xff0c;同样大小的值改变顺序…

【课题总结】OpenCV 抠图项目实战(3)抠图综述

Python 小白的课题报告—OpenCV 抠图项目实战&#xff08;3&#xff09;抠图综述 本系列是 Python 小白的课题作业《基于OpenCV 的图像分割和抠图》。 需要说明的是&#xff0c;本系列并不能算是 OpenCV 的抠图项目教程&#xff0c;只是以此为主题的课题报告。其中包括了一个较…