基于javaweb+mysql的ssm汽车租车管理系统(java+ssm+html+bootstrap+layui+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM汽车租车管理系统(java+ssm+html+bootstrap+layui+mysql)
项目介绍
本项目包含管理员、普通用户两种角色; 管理员主要功能包括: 后台首页、停车位信息管理、车辆求租信息审核、车辆出租信息审核、管理员广播等;
普通用户主要功能包括: 个人信息管理、租入订单(租入的车、租入的车位)、租出订单、发布车辆出租信息、我要租车、我要租车位、留言、来自管理员的公告等内容;
环境需要
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.数据库:MySql 5.7版本; 6.是否Maven项目:否;
技术栈
- 后端:Spring+SpringMVC+Mybatis 2. 前端:HTML+CSS+JavaScript+jsp+jquery+bootstrap+layui
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中util/DBUtil.java配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/ssm_qiche_rentsys/ 登录
@Controller
@RequestMapping(value = "/carout")
public class CarOutController {
CarOutService orderService=new CarOutService();
//对于用户
/**
*添加订单,必须设置名字和价格
* code=200 data=1添加成功
* code=200 data=0添加失败
* code=202 data=0参数有错误
* code=404 data=-1异常
* @param sender_id
* @param name
* @param price
* @param pic
* @return
*/
@RequestMapping(value = "/orderAdd", method = RequestMethod.GET)
@ResponseBody
public JsonMsg orderAdd(int sender_id,String name,String price,String pic)
{
JsonMsg jsonMsg=new JsonMsg();
if(price==null||name==null)
{
jsonMsg.setCode("202");
jsonMsg.setData(0);
}
try {
int i=orderService.add(sender_id,name,Integer.parseInt(price),pic);
jsonMsg.setCode("200");
jsonMsg.setData(i);
System.out.println("successfully insert into database");
} catch (Exception e) {
jsonMsg.setCode("404");
else
car.setPrice(Integer.parseInt(price));
car.setPic(pic);
if(orderService.getOrderById(id)==null)
{
jsonMsg.setCode("202");
jsonMsg.setData(0);
}
jsonMsg.setData(carService.updateCar(orderService.getOrderById(id).getCar_id(),car));
jsonMsg.setCode("200");
} catch (Exception e) {
jsonMsg.setCode("404");
jsonMsg.setData(-1);
e.printStackTrace();
}
return jsonMsg;
}
/**
* 得到和myId相关的所有订单
* code=200,data存这些订单
* code=404 data=-1异常
* @param myId
* @return
*/
@RequestMapping(value = "/myOrder", method = RequestMethod.GET)
@ResponseBody
public JsonMsg getMyOrder(int myId)
{
JsonMsg jsonMsg=new JsonMsg();
List<CarOutBean> orders= null;
List<CarOutBean> myOrders=new ArrayList<CarOutBean>();
try {
orders = orderService.getAllOrder();
for(CarOutBean car:orders)
{
if(car.getSender_id()==myId||car.getReceiver_id()==myId)
{
UserService userService=new UserService();
CarService carService=new CarService();
car.setCarName(carService.getCar(car.getCar_id()).getName());
car.setSenderName(userService.getUserById(car.getSender_id()).getUserName());
JsonMsg jsonMsg=new JsonMsg();
List<CarInBean> orders= null;
List<CarInBean> myOrders=new ArrayList<CarInBean>();
try {
orders = orderService.getAllOrder();
for(CarInBean car:orders)
{
if(car.getStatus()==1)
{
myOrders.add(car);
}
}
jsonMsg.setData(myOrders);
jsonMsg.setCode("200");
} catch (SQLException e) {
jsonMsg.setCode("404");
jsonMsg.setData(-1);
e.printStackTrace();
}
return jsonMsg;
}
/**
* 得到所有的order
* code=200 data为这些order
* code=404 data=-1 异常
* @return
*/
@RequestMapping(value = "/orderTraversal", method = RequestMethod.GET)
@ResponseBody
public JsonMsg orderTraversal()
{
JsonMsg jsonMsg=new JsonMsg();
List<CarInBean> orders= null;
try {
orders = orderService.getAllOrder();
jsonMsg.setData(orders);
jsonMsg.setCode("200");
} catch (SQLException e) {
jsonMsg.setCode("404");
jsonMsg.setData(-1);
e.printStackTrace();
}
return jsonMsg;
}
/**
* 接受某个订单
* Code=200 取出成功
* code=404 data=-1异常
* @param userid
* @return
*/
@RequestMapping(value = "/getParkOrderByUserid", method = RequestMethod.GET)
@ResponseBody
public JsonMsg getParkorderByUserid(int userid)
{
JsonMsg jsonMsg=new JsonMsg();
ParkOrderService parkOrderService=new ParkOrderService();
try {
List<ParkOrderBean> orders= parkOrderService.getAllParkOrder();
List<ParkOrderBean> ordersOut=new ArrayList<ParkOrderBean>();
for(ParkOrderBean parkOrderBean:orders)
{
if(parkOrderBean.getUserid()==userid)
{
UserService userService=new UserService();
ParkService parkService=new ParkService();
parkOrderBean.setUserName(userService.getUserById(parkOrderBean.getUserid()).getUserName());
if(parkService.getParkById(parkOrderBean.getParkid())!=null)
parkOrderBean.setParkName(parkService.getParkById(parkOrderBean.getParkid()).getName());
ordersOut.add(parkOrderBean);
}
}
jsonMsg.setCode("200");
jsonMsg.setData(ordersOut);
} catch (Exception e) {
jsonMsg.setCode("404");
jsonMsg.setData(-1);
e.printStackTrace();
}
return jsonMsg;
}
/**
* 得到所有的order
* Code=200 List<ParkOrderBean>
* Code=404 data=-1页面异常
* @return
*/
@RequestMapping(value = "/parkOrderTraversal", method = RequestMethod.GET)
@ResponseBody
public JsonMsg parkOrderTraversal()
{
JsonMsg jsonMsg=new JsonMsg();
ParkOrderService parkOrderService=new ParkOrderService();
jsonMsg.setCode("200");
jsonMsg.setData(parkBeans);
}
catch (Exception e)
{
jsonMsg.setCode("404");
jsonMsg.setData("-1");
e.printStackTrace();
}
return jsonMsg;
}
}
@Controller
@RequestMapping(value="/msg")
public class MessageController {
MessageService messageService=new MessageService();
/**
* 添加广播信息
* Code=200 data=1成功
* Code=200 data=0失败
* Code=404 data=-1异常
* @param msg
* @return
*/
@RequestMapping(value = "/msgAdd", method = RequestMethod.GET)
@ResponseBody
public JsonMsg msgAdd(String msg)
{
JsonMsg jsonMsg=new JsonMsg();
*/
@RequestMapping(value = "/parkDelete", method = RequestMethod.GET)
@ResponseBody
public JsonMsg parkDelete(int id)
{
JsonMsg jsonMsg=new JsonMsg();
try {
ParkBean park=parkService.getParkById(id);
if(park.getStatus()==0)
{
int i=parkService.deleteParkById(id);
jsonMsg.setCode("200");
jsonMsg.setData(i);
}
else{
jsonMsg.setCode("202");
jsonMsg.setData(0);
}
}
catch (Exception e)
{
jsonMsg.setCode("404");
jsonMsg.setData("-1");
e.printStackTrace();
}
return jsonMsg;
}
/**
*Code 200 得到所有parks
* Code 404 -1异常
* @return
*/
@RequestMapping(value = "/parkTraversal", method = RequestMethod.GET)
@ResponseBody
public JsonMsg parkTraversal()
{
JsonMsg jsonMsg=new JsonMsg();
try {
}
try {
int i=orderService.add(sender_id,name,Integer.parseInt(price),pic);
jsonMsg.setCode("200");
jsonMsg.setData(i);
} catch (Exception e) {
jsonMsg.setCode("404");
jsonMsg.setData(-1);
e.printStackTrace();
}
return jsonMsg;
}
/**
* 删除一个订单
* code=200 data=1删除成功
* code=200 data=0删除失败
* code=404 data=-1删除失败
* @param id
* @return
*/
@RequestMapping(value = "/orderDelete", method = RequestMethod.GET)
@ResponseBody
public JsonMsg orderDelete(int id)
{
JsonMsg jsonMsg=new JsonMsg();
try {
jsonMsg.setData(orderService.deleteOrder(id));
jsonMsg.setCode("200");
} catch (SQLException e) {
jsonMsg.setCode("404");
jsonMsg.setData(-1);
e.printStackTrace();
}
return jsonMsg;
}
jsonMsg.setCode("404");
jsonMsg.setData("-1");
e.printStackTrace();
}
return jsonMsg;
}
/**
*id必须设置
* 其他参数不设置代表不更新
* Code 200 data=1更新成功
* Code 200 data=0 没有更新
* Code 404 异常
* @param id
* @param name
* @param price_per_day
* @param status
* @return
*/
@RequestMapping(value = "/parkUpdate", method = RequestMethod.GET)
@ResponseBody
public JsonMsg parkUpdate(int id,String name,String price_per_day,String status)
{
JsonMsg jsonMsg=new JsonMsg();
try {
ParkBean parkBean=new ParkBean();
if(name!=null)
{
parkBean.setName(name);
}
if(price_per_day!=null)
{
parkBean.setPrice_per_day(Integer.parseInt(price_per_day));
}
if(status!=null)
{
parkBean.setStatus(Integer.parseInt(status));
}
int i=parkService.updateParkById(id,parkBean);
jsonMsg.setCode("200");
jsonMsg.setData(1);
}
jsonMsg.setData(-1);
}
} else {
jsonMsg.setCode("2032");
jsonMsg.setData(-1);
}
} catch (SQLException e) {
jsonMsg.setCode("2033");
jsonMsg.setData(-1);
e.printStackTrace();
}
return jsonMsg;
}
}
@Controller
@RequestMapping(value = "/userAll")
public class UserAllKinds {
AdminService adminService = new AdminService();
UserService userService = new UserService();
public static void main(String[] args){
UserAllKinds test = new UserAllKinds();
test.checkUser("jason66");
}
/**
* Code: "1" 为管理员账号
* Code: "2" 为普通用户账号
* Code: "404" 账号不存在
* Code: "-1" 内部故障
*
* @param username
* @return JsonMsg
* @auther ChenJie
*/
@RequestMapping(value = "/checkUser", method = RequestMethod.GET)
@ResponseBody
public JsonMsg checkUser(String username) {
JsonMsg jsonMsg = new JsonMsg();
try {
orders = orderService.getAllOrder();
for(CarOutBean car:orders)
{
UserService userService=new UserService();
CarService carService=new CarService();
car.setCarName(carService.getCar(car.getCar_id()).getName());
car.setSenderName(userService.getUserById(car.getSender_id()).getUserName());
if(car.getReceiver_id()!=0)
car.setReceiverName(userService.getUserById(car.getReceiver_id()).getUserName());
}
jsonMsg.setData(orders);
jsonMsg.setCode("200");
} catch (SQLException e) {
jsonMsg.setCode("404");
jsonMsg.setData(-1);
e.printStackTrace();
}
return jsonMsg;
}
/**
* 接受某个订单
* 提供订单的id号和接收者的id
* code=200,data=1 接受成功
* code=200 data=0 接受失败
* code=404 data=-1 页面异常
* @param id 订单的编号
* @param receiver_id
* @return
*/
@RequestMapping(value = "/orderAccept", method = RequestMethod.GET)
@ResponseBody
public JsonMsg orderAccept(int id,int receiver_id)
{
JsonMsg jsonMsg=new JsonMsg();
try {
int i=orderService.updateUser(id,receiver_id);
jsonMsg.setData(i);
jsonMsg.setCode("200");
System.out.println("ChenJie Debug: accept car_rent_out order successfully.");
} catch (SQLException e) {
jsonMsg.setCode("404");
jsonMsg.setData(-1);
e.printStackTrace();
}
return jsonMsg;
}
/**
jsonMsg.setData(orders);
jsonMsg.setCode("200");
} catch (SQLException e) {
jsonMsg.setCode("404");
jsonMsg.setData(-1);
e.printStackTrace();
}
return jsonMsg;
}
/**
* 得到和passed的所有订单等待被接受的
* code=200,data存这些订单
* code=404 data=-1异常
* @return
*/
@RequestMapping(value = "/passedOrder", method = RequestMethod.GET)
@ResponseBody
public JsonMsg getpassedOrder()
{
JsonMsg jsonMsg=new JsonMsg();
List<CarOutBean> orders= null;
List<CarOutBean> myOrders=new ArrayList<CarOutBean>();
try {
orders = orderService.getAllOrder();
for(CarOutBean car:orders)
{
// if(car.getStatus()==1)
// {
// myOrders.add(car);
// }
UserService userService=new UserService();
CarService carService=new CarService();
if(car.getStatus()==1)
{
//Modified by Ceej
car.setCarName(carService.getCar(car.getCar_id()).getName());
car.setSenderName(userService.getUserById(car.getSender_id()).getUserName());
{
int status=0;
JsonMsg jsonMsg=new JsonMsg();
UserBean ub=new UserBean();
ub.setUserName(username);
ub.setPassword(password);
ub.setEmail(email);
ub.setDescription(description);
ub.setPic(pic);
try {
ub.setMoney(Integer.parseInt(money));
} catch (Exception e) {
ub.setMoney(Integer.MIN_VALUE);
}
try {
status = userService.updateUserById(id, ub);
jsonMsg.setData(status);
if (status >= 1) {
jsonMsg.setCode("200");
} else {
jsonMsg.setCode("202");
}
} catch (SQLException e) {
jsonMsg.setCode("404");
jsonMsg.setData(-1);
e.printStackTrace();
}
return jsonMsg;
}
/**
* JsonMsg ID具体查找用户
* Code:404,Data=-1查找失败
* Code:200,Data=UserBean 查找成功
* Code:202,Data=0,没有查到
*
* @param id
* @return
*/
@RequestMapping(value = "/userLocate", method = RequestMethod.GET)
@ResponseBody
public JsonMsg getUserByID(int id)
}
return jsonMsg;
}
}
@Controller
@RequestMapping(value = "/carin")
public class CarInController {
CarInService orderService=new CarInService();
//对于用户
/**
*添加订单,必须设置名字和价格
* code=200 data=1添加成功
* code=200 data=0添加失败
* code=202 data=0参数有错误
* code=404 data=-1异常
* @param sender_id
* @param name
* @param price
* @param pic
* @return
*/
@RequestMapping(value = "/orderAdd", method = RequestMethod.GET)
@ResponseBody
public JsonMsg orderAdd(int sender_id,String name,String price,String pic)
{
JsonMsg jsonMsg=new JsonMsg();
* @param carName
* @param stringPrice
* @return
*/
@RequestMapping(value = "/userAddCar", method = RequestMethod.GET)
@ResponseBody
public JsonMsg userAddCar(int sender_id, String carName, String stringPrice) {
int price = 0;
try {
price = Integer.parseInt(stringPrice);
} catch (Exception e) {
System.out.println("Chenjie Debug");
e.printStackTrace();
}
JsonMsg jsonMsg = new JsonMsg();
if (price < 0 || carName == null) {
jsonMsg.setCode("202");
jsonMsg.setData(0);
}
try {
int i = orderService.addCar(carName, price, "还没有实现照片上传");
System.out.println("addCar之后的返回值是:"+i);
if (i >= 1) {
int r = outOrderService.add(sender_id, carName, price, "还没有实现照片上传");
if (r == 1) {
jsonMsg.setCode("200");
jsonMsg.setData(1);
} else {
jsonMsg.setCode("2031");
jsonMsg.setData(-1);
}
} else {
jsonMsg.setCode("2032");
jsonMsg.setData(-1);
}
} catch (SQLException e) {
jsonMsg.setCode("2033");
jsonMsg.setData(-1);
e.printStackTrace();
}
return jsonMsg;
}
* 添加parkOrder
* 正常返回data=1 code=200
* 添加失败,余额已经小于等于0返回data=0 code=202
* 异常throw exception
* userid非法返回data=-1 code=202
* parkid非法返回data=-2 code=202
* @param userid
* @param parkid
* @return
*/
@RequestMapping(value = "/parkOrderAdd", method = RequestMethod.GET)
@ResponseBody
public JsonMsg parkOrderAdd(int userid,int parkid)
{
JsonMsg jsonMsg=new JsonMsg();
ParkOrderService parkOrderService=new ParkOrderService();
UserService userService=new UserService();
try {
if(userService.getUserById(userid).getMoney()<=0)
{
jsonMsg.setCode("2021");
jsonMsg.setData(0);
return jsonMsg;
}
int i=parkOrderService.addParkOrder(userid,parkid);
jsonMsg.setData(i);
if(i==1)
{
jsonMsg.setCode("200");
System.out.println("ChenJie Debug:成功租用了停车位");
}
else{
jsonMsg.setCode("2022");
}
} catch (Exception e) {
jsonMsg.setCode("2023");
e.printStackTrace();
}
* @param receiver_id
* @return
*/
@RequestMapping(value = "/orderAccept", method = RequestMethod.GET)
@ResponseBody
public JsonMsg orderAccept(int id,int receiver_id)
{
JsonMsg jsonMsg=new JsonMsg();
try {
int i=orderService.updateUser(id,receiver_id);
jsonMsg.setData(i);
jsonMsg.setCode("200");
} catch (SQLException e) {
jsonMsg.setCode("404");
jsonMsg.setData(-1);
e.printStackTrace();
}
return jsonMsg;
}
/**
* 管理员通过某个订单
* code=200 data=1 通过成功
* code=200 data=0 通过失败,id不存在或者状态异常
* code=404 data=-1 异常
* @param id
* @return
*/
@RequestMapping(value = "/orderPass", method = RequestMethod.GET)
@ResponseBody
public JsonMsg orderPass(int id)
{
JsonMsg jsonMsg=new JsonMsg();
try {
int i=orderService.pass(id);
jsonMsg.setData(i);
jsonMsg.setCode("200");
} catch (SQLException e) {
jsonMsg.setCode("404");
jsonMsg.setData(-1);
e.printStackTrace();
}
return jsonMsg;
}
return jsonMsg;
}
/**
* 得到receriverId租进来的订单
* code=200,data存这些订单
* code=404 data=-1异常
* @param receiverId
* @return JsonMsg
*/
@RequestMapping(value = "/myInOrder", method = RequestMethod.GET)
@ResponseBody
public JsonMsg getMyInOrder(int receiverId)
{
JsonMsg jsonMsg=new JsonMsg();
List<CarOutBean> orders= null;
List<CarOutBean> myOrders=new ArrayList<CarOutBean>();
try {
orders = orderService.getOrdersByReceiverId(receiverId);
//Modified by Ceej
try {
for (CarOutBean car:orders)
{
UserService userService=new UserService();
CarService carService=new CarService();
car.setCarName(carService.getCar(car.getCar_id()).getName());
car.setSenderName(userService.getUserById(car.getSender_id()).getUserName());
if(car.getReceiver_id()!=0)
car.setReceiverName(userService.getUserById(car.getReceiver_id()).getUserName());
}
} catch (Exception e) {
// TODO Auto-generated catch block
}
jsonMsg.setData(orders);
jsonMsg.setCode("200");
} catch (SQLException e) {
jsonMsg.setCode("404");
jsonMsg.setData(-1);
e.printStackTrace();
}
return jsonMsg;
}
return jsonMsg;
}
/**
* 通过userid来得到orders
* 这里用了个比较消耗时间的方法,但是表不大我就偷个懒不在controller开新的方法了
* Code=200 取出成功
* code=404 data=-1异常
* @param userid
* @return
*/
@RequestMapping(value = "/getParkOrderByUserid", method = RequestMethod.GET)
@ResponseBody
public JsonMsg getParkorderByUserid(int userid)
{
JsonMsg jsonMsg=new JsonMsg();
ParkOrderService parkOrderService=new ParkOrderService();
try {
List<ParkOrderBean> orders= parkOrderService.getAllParkOrder();
List<ParkOrderBean> ordersOut=new ArrayList<ParkOrderBean>();
for(ParkOrderBean parkOrderBean:orders)
{
if(parkOrderBean.getUserid()==userid)
{
UserService userService=new UserService();
ParkService parkService=new ParkService();
parkOrderBean.setUserName(userService.getUserById(parkOrderBean.getUserid()).getUserName());
if(parkService.getParkById(parkOrderBean.getParkid())!=null)
parkOrderBean.setParkName(parkService.getParkById(parkOrderBean.getParkid()).getName());
ordersOut.add(parkOrderBean);
}
}
jsonMsg.setCode("200");
jsonMsg.setData(ordersOut);
} catch (Exception e) {
jsonMsg.setCode("404");
jsonMsg.setData(-1);
e.printStackTrace();
}
return jsonMsg;
}
/**
* 得到所有的order
* Code=200 List<ParkOrderBean>
* Code=404 data=-1页面异常