作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
项目介绍
本项目为前后台项目,有管理员与普通用户两种角色,普通用户登录前台,管理员登录后台;
管理员角色包含以下功能:
管理员登录,用户管理,管理员管理,订单管理和审核,利润统计,交易流水管理,车辆管理,汽车品牌管理等功能。
用户角色包含以下功能:
用户登录页面,查看所有租车信息,查看汽车详细信息,提交租车订单,查看我的订单,查看个人租车记录,个人中心管理等功能。
由于本程序规模不大,可供课程设计,毕业设计学习演示之用
环境需要
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项目:否;
技术栈
1. 后端:Spring+Struts+Hibernate
2. 前端:JSP+CSS+JavaScript+jQuery
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中jdbc.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,前台地址:http://localhost:8080/login_index.do?role=1 登录
用户账号/密码:user/123456
后台地址:http://localhost:8080/login_login.do?role=2 登录
管理员账号/密码:admin/admin
运行截图
前台界面
后台界面
相关代码
CarAction
package com.neusoft.action;import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.context.annotation.Scope;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.neusoft.utils.Pager;
import com.neusoft.utils.UUIDUtils;
import com.opensymphony.xwork2.ModelDriven;
import com.neusoft.model.*;
import com.neusoft.service.*;/*** @ClassName: * @Description: * @author administrator* @date 2015年12月24日 下午1:46:33 - 2016年12月15日 21时47分53秒*/@Controller("carAction")
@Scope("prototype")
public class CarAction extends ActionSupport implements ModelDriven<Car>{private static final long serialVersionUID = 1L;//==========model==============private Car car;@Overridepublic Car getModel() {if(car==null) car = new Car();return car; }//==========model==============/*** 依赖注入 start dao/service/===*/@Autowiredprivate CarService carService;@Autowiredprivate CarCategoryService carCategoryService;//依赖注入 end dao/service/===//-------------------------华丽分割线---------------------------------------------//============自定义参数start=============//============自定义参数end=============//-------------------------华丽分割线---------------------------------------------//============文件上传start=======================================================private File file;//提交过来的file的名字private String fileFileName;//提交过来的file的MIME类型private String fileContentType;public File getFile() {return file;}public void setFile(File file) {this.file = file;}public String getFileFileName() {return fileFileName;}public void setFileFileName(String fileFileName) {this.fileFileName = fileFileName;}public String getFileContentType() {return fileContentType;}public void setFileContentType(String fileContentType) {this.fileContentType = fileContentType;}//============文件上传end=========================================================//-------------------------华丽分割线---------------------------------------------////=============公=======共=======方=======法==========区=========start============///*** 前台根据传入的参数展示的汽车列表* @return*/public String uCarList(){ StringBuffer sb = new StringBuffer();sb = sb.append("from Car where 1=1 and isDelete=0");if(car.getIsRecommend()==1){sb.append(" and isRecommend =1");}if(car.getIsDiscount()==1){sb.append(" and isDiscount =1");}sb = sb.append(" order by id desc");Pager<Car> pagers = carService.findByAlias(sb.toString(),null);ActionContext.getContext().put("pagers", pagers);ActionContext.getContext().put("car", car);return SUCCESS;}/*** 前台根据carId查询单个汽车信息* @return*/public String uCar(){String hql = "from Car where 1=1 and id = :id and isDelete=0 ";Map<String,Object> alias = new HashMap<String,Object>();alias.put("id", car.getId());List<Car> carList = carService.getByHQL(hql, alias);ActionContext.getContext().put("car", carList.get(0));return SUCCESS;}/*** 前台根据carId进入确认租车页面* @return*/public String uRentCar(){//判断该用户是否已经登录,如果没登录跳入到登录页面User existUser = (User) ServletActionContext.getRequest().getSession().getAttribute("user");if(existUser==null){return "userLogin"; }else{String hql = "from Car where 1=1 and id = :id and isDelete=0 ";Map<String,Object> alias = new HashMap<String,Object>();alias.put("id", car.getId());List<Car> carList = carService.getByHQL(hql, alias);ActionContext.getContext().put("car", carList.get(0));return SUCCESS;}}/*** 列表分页查询*/public String car(){Map<String,Object> alias = new HashMap<String,Object>();StringBuffer sb = new StringBuffer();sb = sb.append("from Car where 1=1 and isDelete=0");if(car.getCarType()!=null&& !"".equals(car.getCarType() )){sb.append(" and carType like :carType");alias.put("carType", "%"+car.getCarType()+"%" );}if(car.getCarCategory()!=null&& !"".equals(car.getCarCategory() )){if(car.getCarCategory().getId()!=0&& !"".equals(car.getCarCategory().getId())){sb.append(" and carCategory.id = :id");alias.put("id", car.getCarCategory().getId() );}}if(car.getIsRecommend()!=0&& !"".equals(car.getIsRecommend() )){sb.append(" and isRecommend = :isRecommend");alias.put("isRecommend", car.getIsRecommend() );}if(car.getIsDiscount()!=0&& !"".equals(car.getIsDiscount() )){sb.append(" and isDiscount = :isDiscount");alias.put("isDiscount", car.getIsDiscount() );}sb = sb.append(" order by id desc");Pager<Car> pagers = carService.findByAlias(sb.toString(),alias);ActionContext.getContext().put("pagers", pagers);ActionContext.getContext().put("car", car);Map<String,Object> alias1 = new HashMap<String,Object>();StringBuffer sb1 = new StringBuffer();sb1 = sb1.append("from CarCategory where 1=1");//进入修改页面时候首先查询出品牌分类的所有信息List<CarCategory> carCatList=carCategoryService.getByHQL(sb1.toString(), alias1);ActionContext.getContext().put("carCatList", carCatList);return SUCCESS;}/*** 跳转到添加页面* @return*/public String add(){Map<String,Object> alias = new HashMap<String,Object>();StringBuffer sb = new StringBuffer();sb = sb.append("from CarCategory where 1=1");//进入新增页面时候首先查询出品牌分类的所有信息List<CarCategory> carCatList=carCategoryService.getByHQL(sb.toString(), alias);ActionContext.getContext().put("carCatList", carCatList);return SUCCESS;}/*** 执行添加* @return* @throws Exception */public String exAdd() throws Exception{//图片上传String root = "D:/my/upload";InputStream is = new FileInputStream(file);fileFileName = UUIDUtils.create()+fileFileName;OutputStream os = new FileOutputStream(new File(root, fileFileName));System.out.println("fileFileName: " + fileFileName);System.out.println("file: " + file.getName());System.out.println("file: " + file.getPath());byte[] buffer = new byte[500];int length = 0;while(-1 != (length = is.read(buffer, 0, buffer.length))){os.write(buffer);}os.close();is.close();car.setCarImage("\\upload\\"+fileFileName);carService.save(car);ActionContext.getContext().put("url", "/car_car.do");return "redirect";}/*** 查看详情页面* @return*/public String view(){Car n = carService.getById(car.getId());ActionContext.getContext().put("car", n);return SUCCESS;}/*** 跳转修改页面* @return*/public String update(){Car n = carService.getById(car.getId());ActionContext.getContext().put("car", n);Map<String,Object> alias = new HashMap<String,Object>();StringBuffer sb = new StringBuffer();sb = sb.append("from CarCategory where 1=1");//进入修改页面时候首先查询出品牌分类的所有信息List<CarCategory> carCatList=carCategoryService.getByHQL(sb.toString(), alias);ActionContext.getContext().put("carCatList", carCatList);return SUCCESS;}/*** 执行修改* @return* @throws Exception */public String exUpdate() throws Exception{Car c =carService.getById(car.getId());if(file!=null){//图片上传String root = "D:/my/upload";InputStream is = new FileInputStream(file);fileFileName = UUIDUtils.create()+fileFileName;OutputStream os = new FileOutputStream(new File(root, fileFileName));System.out.println("fileFileName: " + fileFileName);System.out.println("file: " + file.getName());System.out.println("file: " + file.getPath());byte[] buffer = new byte[500];int length = 0;while(-1 != (length = is.read(buffer, 0, buffer.length))){os.write(buffer);}os.close();is.close();c.setCarImage("\\upload\\"+fileFileName);}else{c.setCarImage(c.getCarImage());}c.setCarType(car.getCarType());c.setCarNumber(car.getCarNumber());c.setCarCategory(car.getCarCategory());c.setCarOilType(car.getCarOilType());c.setDailyPrice(car.getDailyPrice());c.setDistance(car.getDistance());c.setIsDiscount(car.getIsDiscount());c.setIsRecommend(car.getIsRecommend());carService.update(c);ActionContext.getContext().put("url", "/car_car.do");return "redirect";}/*** 删除* @return*/public String delete(){Car n = carService.getById(car.getId());n.setIsDelete(1);carService.update(n);ActionContext.getContext().put("url", "/car_car.do");return "redirect";}//=============公=======共=======方=======法==========区=========end============////-------------------------华丽分割线---------------------------------------------////=============自=======定=======义=========方=======法==========区=========start============////=============自=======定=======义=========方=======法==========区=========end============//}
CarCategoryAction
package com.neusoft.action;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import org.springframework.context.annotation.Scope;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.neusoft.utils.Pager;
import com.opensymphony.xwork2.ModelDriven;
import com.neusoft.model.*;
import com.neusoft.service.*;/*** @ClassName: * @Description: * @author administrator* @date 2015年12月24日 下午1:46:33 - 2016年12月15日 21时47分53秒*/@Controller("carCategoryAction")
@Scope("prototype")
public class CarCategoryAction extends ActionSupport implements ModelDriven<CarCategory>{private static final long serialVersionUID = 1L;//==========model==============private CarCategory carCategory;@Overridepublic CarCategory getModel() {if(carCategory==null) carCategory = new CarCategory();return carCategory; }//==========model==============/*** 依赖注入 start dao/service/===*/@Autowiredprivate CarCategoryService carCategoryService;//依赖注入 end dao/service/===//-------------------------华丽分割线---------------------------------------------//============自定义参数start=============//============自定义参数end=============//-------------------------华丽分割线---------------------------------------------//============文件上传start=======================================================private File file;//提交过来的file的名字private String fileFileName;//提交过来的file的MIME类型private String fileContentType;public File getFile() {return file;}public void setFile(File file) {this.file = file;}public String getFileFileName() {return fileFileName;}public void setFileFileName(String fileFileName) {this.fileFileName = fileFileName;}public String getFileContentType() {return fileContentType;}public void setFileContentType(String fileContentType) {this.fileContentType = fileContentType;}//============文件上传end=========================================================//-------------------------华丽分割线---------------------------------------------////=============公=======共=======方=======法==========区=========start============///*** 列表分页查询*/public String carCategory(){Map<String,Object> alias = new HashMap<String,Object>();StringBuffer sb = new StringBuffer();sb = sb.append("from CarCategory where 1=1 and isDelete=0");if(carCategory.getCname()!=null&& !"".equals(carCategory.getCname() )){sb.append(" and cname like :cname");alias.put("cname", "%"+carCategory.getCname()+"%");}sb = sb.append(" order by id desc");Pager<CarCategory> pagers = carCategoryService.findByAlias(sb.toString(),alias);ActionContext.getContext().put("pagers", pagers);ActionContext.getContext().put("carCategory", carCategory);return SUCCESS;}/*** 跳转到添加页面* @return*/public String add(){return SUCCESS;}/*** 执行添加* @return*/public String exAdd(){carCategoryService.save(carCategory);ActionContext.getContext().put("url", "/carCategory_carCategory.do");return "redirect";}/*** 查看详情页面* @return*/public String view(){CarCategory n = carCategoryService.getById(carCategory.getId());ActionContext.getContext().put("carCategory", n);return SUCCESS;}/*** 跳转修改页面* @return*/public String update(){CarCategory n = carCategoryService.getById(carCategory.getId());ActionContext.getContext().put("carCategory", n);return SUCCESS;}/*** 执行修改* @return*/public String exUpdate(){carCategoryService.update(carCategory);ActionContext.getContext().put("url", "/carCategory_carCategory.do");return "redirect";}/*** 删除* @return*/public String delete(){CarCategory n = carCategoryService.getById(carCategory.getId());n.setIsDelete(1);carCategoryService.update(n);ActionContext.getContext().put("url", "/carCategory_carCategory.do");return "redirect";}//=============公=======共=======方=======法==========区=========end============////-------------------------华丽分割线---------------------------------------------////=============自=======定=======义=========方=======法==========区=========start============////=============自=======定=======义=========方=======法==========区=========end============//}
如果也想学习本系统,下面领取。关注并回复:019ssh