Java项目:SSH汽车销售管理系统

94 篇文章 1 订阅

作者主页:源码空间站2022

 简介: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. 后端:mysql+Spring+hibernate+Struts 2

2. 前端:HTML+CSS+JavaScript+jsp

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;

4. 运行项目,输入localhost:8080/ 登录

运行截图

管理端页面

相关代码 

管理端页面

/**
 * @ClassName:  
 * @Description: 
 * @author administrator
 * @date 2015年12月24日 下午1:46:33 - 2016年12月15日 21时47分53秒
 */

@Controller("adminAction")
@Scope("prototype")
public class AdminAction extends ActionSupport implements ModelDriven<Admin>{
	
	private static final long serialVersionUID = 1L;

	//==========model==============
	  private Admin admin;
		@Override
		public Admin getModel() {
			if(admin==null) admin = new Admin();
			return admin;	
		}
		//==========model==============
	/**
	 * 依赖注入 start dao/service/===
	 */
	@Autowired
	private AdminService adminService;
	
	//依赖注入 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
     * @throws IOException 
     */
    public void index() throws IOException{
        HttpServletResponse resp = ServletActionContext.getResponse();
        resp.setContentType("application/json;charset=UTF-8");
        PrintWriter out = null;
        JSONObject json  = new JSONObject();
        //查询该用户是否存在
    	 Admin ad1 =  adminService.getByUserName(admin);
    	 //查询用户和密码是否 
    	 Admin ad =  adminService.login(admin);
    	if(ad1==null){
    		 json.put("result", 3); //该用户不存在
    	}else{
		   if(ad!=null){
	        	 json.put("result", 1); //登录成功
	        	 HttpSession session = ServletActionContext.getRequest().getSession();
	           session.setAttribute("adminName", ad.getAdminName());
	           session.setAttribute("adminId", ad.getId());
	           ActionContext.getContext().put("url", "/admin_admin.do");
	        }else{
	        	json.put("result",2);//密码错误
	        }
    	}
         out = resp.getWriter();
         out.write(json.toString());
		
    }
	
	/**
	 * 列表分页查询
	 */
	public String admin(){
	    Map<String,Object> alias = new HashMap<String,Object>();
		StringBuffer sb = new StringBuffer();
		sb = sb.append("from Admin where 1=1 and isDelete=0");
		if(admin.getAdminName()!=null&& !"".equals(admin.getAdminName() )){
			 sb.append(" and adminName like :adminName");
			 alias.put("adminName", "%"+admin.getAdminName()+"%" );
		}
		sb = sb.append(" order by id desc");
		//分页查询
		Pager<Admin> pagers = adminService.findByAlias(sb.toString(),alias);
		ActionContext.getContext().put("pagers", pagers);
		ActionContext.getContext().put("admin", admin);
		return SUCCESS;
    }
	
	/**
	 * 跳转到添加页面
	 * @return
	 */
	public String add(){
		return SUCCESS;
	}
	
	/**
	 * 执行添加
	 * @return
	 */
	public String exAdd(){
		adminService.save(admin);
		ActionContext.getContext().put("url", "/admin_admin.do");
		return "redirect";
	}
	
	/**
	 * 查看详情页面
	 * @return
	 */
	public String view(){
		Admin n = adminService.getById(admin.getId());
		ActionContext.getContext().put("admin", n);
		return SUCCESS;
	}
	
	/**
	 * 跳转修改页面
	 * @return
	 */
	public String update(){
		Admin n = adminService.getById(admin.getId());
		ActionContext.getContext().put("admin", n);
		return SUCCESS;
	}
    
	/**
	 * 执行修改
	 * @return
	 */
	public String exUpdate(){
		adminService.update(admin);
		ActionContext.getContext().put("url", "/admin_admin.do");
		return "redirect";
	}
	
	
	/**
	 * 删除
	 * @return
	 */
	public String delete(){
		Admin a = adminService.getById(admin.getId());
		a.setIsDelete(1);
		adminService.update(a);
		ActionContext.getContext().put("url", "/admin_admin.do");
		return "redirect";
	}
	
	//=============公=======共=======方=======法==========区=========end============//
	
	 //-------------------------华丽分割线---------------------------------------------//
	
	 //=============自=======定=======义=========方=======法==========区=========start============//
	
	
	
	
	//=============自=======定=======义=========方=======法==========区=========end============//
		
	
	
}

汽车管理控制器

@Controller("carAction")
@Scope("prototype")
public class CarAction extends ActionSupport implements ModelDriven<Car>{
	
	private static final long serialVersionUID = 1L;

	//==========model==============
	  private Car car;
		@Override
		public Car getModel() {
			if(car==null) car = new Car();
			return car;	
		}
		//==========model==============
	/**
	 * 依赖注入 start dao/service/===
	 */
	@Autowired
	private CarService carService;
	
	@Autowired
	private 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============//
		
	
	
}

如果也想学习本系统,下面领取。关注并回复:028ssh

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值