Java项目:健身房俱乐部管理系统(java+SSM+JSP+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项目:是;


技术栈

1. 后端:Spring+SpringMVC+Mybatis
2. 前端:JSP+CSS+JavaScript+Layui+bootstrap+jquery


使用说明

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

 

 

 

 

 

 

订单管理 -控制层:

/**
 * 订单管理 -控制层
 */
@Controller
public class OrderController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private ClassService classService;
    /**
     * 后台跳转到订单页面
     * @return
     */
    @RequestMapping("/admin/order.html")
    public String adminOrder(){
        return "admin/order/orderlist";
    }

    /**
     * 订单后台分页
     * @param page
     * @param limit
     * @param mname
     * @return
     */
    @RequestMapping("/admin/orderlist.html")
    @ResponseBody
    public Map<String,Object> orderList(String page,String limit,String mname){
        Map<String,Object> orderPageMap = new HashMap<String,Object>();
        PageHelper.startPage(Integer.parseInt(page),Integer.parseInt(limit));
        List<TblOrder> orders = orderService.selectAllOrderWithMember(mname);
        PageInfo<TblOrder> orderPageInfo = new PageInfo<TblOrder>(orders);
        orderPageMap.put("code",0);
        orderPageMap.put("msg","");
        orderPageMap.put("count",orderPageInfo.getTotal());
        orderPageMap.put("data",orders);
        return orderPageMap;
    }

    /**
     * 预订
     * @param classId
     * @return
     */
    @RequestMapping("/class/order.html")
    @ResponseBody
    public Map<String,Object> orderCourse(String classId, HttpServletRequest request){
        Map<String,Object> orderMap = new HashMap<String,Object>();
        TblOrder order = new TblOrder();
        Member member = (Member) request.getSession().getAttribute("member");
        order.setMemberId(member.getMid());
        order.setOcreatetime(new Date());
        order.setOstatus(1);
        order.setClassId(Integer.parseInt(classId));
        TblOrderExample tblOrderExample = new TblOrderExample();
        TblOrderExample.Criteria criteria = tblOrderExample.createCriteria();
        criteria.andMemberIdEqualTo(member.getMid());
        criteria.andClassIdEqualTo(Integer.parseInt(classId));
        List<TblOrder> tblOrders = orderService.selectByExample(tblOrderExample);
        if(!tblOrders.isEmpty()){//不为null说明已经预订
            orderMap.put("msg","您已经预订过该课程,不可重复预订");
        }else{
            //判断是否已经满员
            //1、先根据课程id查询课程的容量
            TblOrderExample tblOrderExample2 = new TblOrderExample();
            Class clazz = classService.selectByPrimaryKey(Integer.parseInt(classId));
            TblOrderExample.Criteria criteria2 = tblOrderExample2.createCriteria();
            criteria2.andClassIdEqualTo(Integer.parseInt(classId));
            long haveOrder = orderService.countByExample(tblOrderExample2);
            //2、已经预订人数和容量比较
            if(new Long(haveOrder).intValue() == clazz.getClassvolume() ){
                orderMap.put("msg","班级已经满员");
            }else{
                int i = orderService.insertSelective(order);
                if(i>0){
                    orderMap.put("msg","预订成功");
                }else {
                    orderMap.put("msg","预订失败");
                }
            }
        }
        return orderMap;
    }
    @RequestMapping("/admin/order/del.html")
    @ResponseBody
    public Map<String,Object> delOrder(String oid){
        Map<String,Object> delMap = new HashMap<String,Object>();
        int i = orderService.deleteByPrimaryKey(Integer.parseInt(oid));
        if(i>0){
            delMap.put("status",1);
        }else{
            delMap.put("status",0);
        }
        return delMap;
    }

}

员工 -控制层:

/**
 * 员工 -控制层
 */
@Controller
public class EmployeeController {
    @Autowired
    private PostService postService;
    @Autowired
    private EmployeeService employeeService;
    /**
     * 后台员工管理
     * @return
     */
    @RequestMapping("/admin/employee.html")
    public String employeePage(Model model){
        //查询所有职务
        List<Post> posts = postService.selectByExample(new PostExample());
        model.addAttribute("posts",posts);
        return "admin/employee/employeelist";
    }

    /**
     * 员工管理分页
     * @param page
     * @param limit
     * @param model
     * @param ename
     * @return
     */
    @RequestMapping("/admin/employeelist.html")
    @ResponseBody
    public Map<String,Object> employeelistPage(String page, String limit, Model model, String ename){
        Map<String,Object> employeeMap = new HashMap<String,Object>();
        //查询所有职务
        List<Post> posts = postService.selectByExample(new PostExample());
        model.addAttribute("posts",posts);
        //分页查询员工
        EmployeeExample employeeExample = new EmployeeExample();
        EmployeeExample.Criteria criteria = employeeExample.createCriteria();
        if(ename != null&& !ename.equals("")){
            criteria.andEnameLike("%"+ename+"%");
        }
        PageHelper.startPage(Integer.parseInt(page),Integer.parseInt(limit));
        List<Employee> employees = employeeService.selectByExample(employeeExample);
        PageInfo<Employee> employeePageInfo = new PageInfo<Employee>(employees);
        employeeMap.put("code",0);
        employeeMap.put("msg","");
        employeeMap.put("count",employeePageInfo.getTotal());
        employeeMap.put("data",employeePageInfo.getList());
        return employeeMap;
    }
    @RequestMapping("/admin/employee/goaddorupdate.html")
    public String goUpdate(Model model,String eid){
        //查询所有职务
        List<Post> posts = postService.selectByExample(new PostExample());
        model.addAttribute("posts",posts);
        //eid不为null,就进行更新,根据员工id查询员工
        if(eid!=null&&!eid.equals(" ")){
            Employee employee = employeeService.selectByPrimaryKey(Integer.parseInt(eid));
            model.addAttribute("employee",employee);
        }
        return "admin/employee/employeeedit";
    }
    @RequestMapping("/admin/employee/doaddorupdate.html")
    @ResponseBody
    public Map<String,Object> doaddorupdate(Employee employee,String time){
        Map<String,Object> updateMap = new HashMap<String,Object>();
        int i = 0;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date date = sdf.parse(time);
            employee.setEhire(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if(employee.getEid()==null){//没有eid则是添加员工
            i = employeeService.insertSelective(employee);
            if(i>0){
                updateMap.put("msg","添加成功");
                updateMap.put("status",1);
            }else{
                updateMap.put("msg","添加失败");
                updateMap.put("status",0);
            }
        }else{
            i = employeeService.updateByPrimaryKeySelective(employee);
            if(i>0){
                updateMap.put("msg","更新成功");
                updateMap.put("status",1);
            }else{
                updateMap.put("msg","更新失败");
                updateMap.put("status",0);
            }
        }

        return updateMap;
    }
    @RequestMapping("/admin/employee/del.html")
    @ResponseBody
    public Map<String,String> delEmployee(String eid){
        Map<String,String> delMap = new HashMap<String, String>();
        int i = employeeService.deleteByPrimaryKey(Integer.parseInt(eid));
        if(i>0){
            delMap.put("status","1");
        }else {
            delMap.put("status","0");
        }
        return delMap;
    }
    /**
     *
     * 教练管理
     *
     */
    @RequestMapping("/admin/trainer.html")
    public String adminTrainer(Model model){
        return "admin/trainer/trainerlist";
    }
    /**
     * 教练管理分页
     */
    @RequestMapping("/admin/trainerlist.html")
    @ResponseBody
    public Map<String,Object> trainerPage(String page,String limit,String ename,Model model){
        Map<String,Object> trainerMap = new HashMap<String,Object>();
        EmployeeExample employeeExample = new EmployeeExample();
        EmployeeExample.Criteria criteria = employeeExample.createCriteria();
        criteria.andEpostIdEqualTo(1);
        if(ename!=null && !ename.equals(" ")){
            criteria.andEnameLike("%"+ename+"%");
        }
        PageHelper.startPage(Integer.parseInt(page),Integer.parseInt(limit));
        List<Employee> trainers = employeeService.selectByExample(employeeExample);
        PageInfo<Employee> trainerPageInfo = new PageInfo<Employee>(trainers);
        trainerMap.put("code",0);
        trainerMap.put("msg","");
        trainerMap.put("count",trainerPageInfo.getTotal());
        trainerMap.put("data",trainers);
        return trainerMap;
    }
    /**
     * 添加或者更新教练
     */
    @RequestMapping("/admin/trainer/goaddorupdate.html")
    public String trainerGoAddOrUpdate(String eid,Model model){
        if(eid!=null&&!eid.equals(" ")){//更新
            Employee trainer = employeeService.selectByPrimaryKey(Integer.parseInt(eid));
            model.addAttribute("trainer",trainer);
        }
        return "admin/trainer/traineredit";
    }
    @RequestMapping("/admin/trainer/doaddorupdate.html")
    @ResponseBody
    public Map<String,Object>  trainerDoAddOrUpdate(Employee employee,String time){
        Map<String,Object> trainerMap = new HashMap<String,Object>();
        int i = 0;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date ehire = sdf.parse(time);
            employee.setEhire(ehire);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if(employee.getEid()!=null&&!employee.getEid().equals(" ")){//eid不为null则是更新
            i = employeeService.updateByPrimaryKeySelective(employee);
            if(i>0){
                trainerMap.put("msg","更新成功");
                trainerMap.put("res",1);
            }else {
                trainerMap.put("msg","更新失败");
                trainerMap.put("res",0);
            }
        }else{
            i = employeeService.insertSelective(employee);
            if(i>0){
                trainerMap.put("msg","添加成功");
                trainerMap.put("res",1);
            }else{
                trainerMap.put("msg","添加失败");
                trainerMap.put("res",0);
            }
        }
        return trainerMap;
    }
    /**
     * 教练删除
     */
    @RequestMapping("/admin/trainer/del.html")
    @ResponseBody
    public Map<String,Object> delTrainer(String eid){
        Map<String,Object> delMap = new HashMap<String,Object>();
        int i = employeeService.deleteByPrimaryKey(Integer.parseInt(eid));
        if(i>0){
            delMap.put("status",1);
        }else {
            delMap.put("status",0);
        }
        return delMap;
    }

}

课程管理 -控制层:

/**
 * 课程管理 -控制层
 */
@Controller
public class CourseController {
	@Autowired
	private CourseService courseService;
	@Autowired
	private EmployeeService employeeService;
	@Autowired
	private CoursecategoryService coursecategoryService;
	@Autowired
	private CoursefunctionService coursefunctionService;
	@Autowired
	private ClassService classService;
	@Autowired
	private OrderService orderService;
	@Autowired
	private ClassMapper classMapper;
	/**
	 * 前台页面-跳转到健身课程
	 * @return
	 */
	@RequestMapping("/course.html")
	public String coursePage(Model model,String page,String cate,String func){
		System.out.println(cate+"====================================="+func);
		//查询所有课程类型
		List<Coursecategory> coursecategories = coursecategoryService.selectByExample(new CoursecategoryExample());
		model.addAttribute("coursecategories",coursecategories);
		//查询所有课程功能
		List<Coursefunction> coursefunctions = coursefunctionService.selectByExample(new CoursefunctionExample());
		model.addAttribute("coursefunctions",coursefunctions);
		//查询所有课程  总页数
		int _page;
		if(page==null){
			_page = 1;
		}else {
			_page = Integer.parseInt(page);
		}
		//根据课程类型名称查询课程类型ID,根据功能名称查询功能ID
		CourseExample courseExample = new CourseExample();
		CourseExample.Criteria criteria = courseExample.createCriteria();

		CoursecategoryExample coursecategoryExample = new CoursecategoryExample();
		CoursecategoryExample.Criteria criteria1 = coursecategoryExample.createCriteria();

		CoursefunctionExample coursefunctionExample = new CoursefunctionExample();
		CoursefunctionExample.Criteria criteria2 = coursefunctionExample.createCriteria();


		if(cate!=null&&!cate.equals("全部")){
			criteria1.andCateNameEqualTo(cate);
			List<Coursecategory> coursecategories1 = coursecategoryService.selectByExample(coursecategoryExample);
			criteria.andCcateIdEqualTo(coursecategories1.get(0).getCateId());
		}
		if (func!=null&&!func.equals("全部")){
			criteria2.andFnameEqualTo(func);
			List<Coursefunction> coursefunctions1 = coursefunctionService.selectByExample(coursefunctionExample);
			criteria.andCfunctionIdEqualTo(coursefunctions1.get(0).getFid());
		}
		PageHelper.startPage(_page,6);
		List<Course> courses = courseService.selectByExampleWithBLOBs(courseExample);
		PageInfo<Course> pageInfo = new PageInfo<Course>(courses);
		int totalPages = pageInfo.getPages();
		model.addAttribute("totalPages",totalPages);
		model.addAttribute("currentPage",_page);
		model.addAttribute("courses",courses);
		model.addAttribute("cate",cate);
		model.addAttribute("func",func);
		Sheet sheet = courseService.selectSheetByPrimaryKey(1);
		if(sheet!=null){
			model.addAttribute("sheetsrc",sheet.getSsrc());
		}
		return "course";
	}

	/**
	 * 前台课程详情页面
	 * @param model
	 * @param cid
	 * @return
	 */
	@RequestMapping("/courseinfo.html")
	public String coursePage(Model model,String cid){
		Course course = courseService.selectByPrimaryKey(Integer.parseInt(cid));
		model.addAttribute("course",course);
		//如果是cid为8(游泳)或者18(瑜伽)就查询所有开设班级
		ClassExample classExample = new ClassExample();
		ClassExample.Criteria criteria = classExample.createCriteria();
		criteria.andCourseIdEqualTo(Integer.parseInt(cid));
		List<Class> classes = classService.selectByExample(classExample);
		//查询该课程已预订人数
		for (Class aClass : classes) {
			TblOrderExample tblOrderExample = new TblOrderExample();
			TblOrderExample.Criteria criteria1 = tblOrderExample.createCriteria();
			criteria1.andClassIdEqualTo(aClass.getClassid());
			long haveOrder = orderService.countByExample(tblOrderExample);
			aClass.setHaveOrder(new Long(haveOrder).intValue());
		}
		model.addAttribute("classes",classes);
		//查询所有教练
		EmployeeExample employeeExample = new EmployeeExample();
		EmployeeExample.Criteria criteria2 = employeeExample.createCriteria();
		criteria2.andEpostIdEqualTo(1);
		List<Employee> trainers = employeeService.selectByExample(employeeExample);
		model.addAttribute("trainers",trainers);
		return "courseinfo";
	}
	/**
	 * 后台管理跳转到课程管理界面
	 * @return
	 */
	@RequestMapping("/admin/course.html")
	public String admincourse(Model model){
		//查询所有员工,进行教练名称显示
		List<Employee> employees = employeeService.selectByExample(new EmployeeExample());
		model.addAttribute("employees",employees);
		//查询所有课程类型
		List<Coursecategory> coursecategories = coursecategoryService.selectByExample(new CoursecategoryExample());
		model.addAttribute("coursecategories",coursecategories);
		//查询所有课程功能
		List<Coursefunction> coursefunctions = coursefunctionService.selectByExample(new CoursefunctionExample());
		model.addAttribute("coursefunctions",coursefunctions);
		return "admin/course/courselist";
	}

	/**
	 * 分页+课程名称  查询
	 * @param page
	 * @param limit
	 * @param model
	 * @param cname
	 * @return
	 */
	@RequestMapping("/admin/courselist.html")
	@ResponseBody
	public Map<String,Object> courselistPage(String page, String limit,Model model,String cname){
		List<Employee> employees = employeeService.selectByExample(new EmployeeExample());
		model.addAttribute("employees",employees);
		CourseExample example = new CourseExample();
		if(cname!=null&&!"".equals(cname)){
			CourseExample.Criteria criteria = example.createCriteria();
			criteria.andCnameLike("%"+cname+"%");
		}
		PageHelper.startPage(Integer.parseInt(page),Integer.parseInt(limit));
		List<Course> courses = courseService.selectByExampleWithBLOBs(example);
		PageInfo<Course> pageInfo = new PageInfo<Course>(courses);
		Map<String,Object> pageMap = new HashMap<String,Object >();
		pageMap.put("code",0);
		pageMap.put("msg","");
		pageMap.put("count",pageInfo.getTotal());
		pageMap.put("data",pageInfo.getList());
		return pageMap;
	}


	/**
	 * 上传课程图片
	 * @param file
	 * @return
	 */
	@RequestMapping("/admin/upload.html")
	@ResponseBody
	public Map<String,Object> upload(MultipartFile file){
		String extName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
		String filename = System.currentTimeMillis()+extName;
		File newFile = new File(Thread.currentThread().getContextClassLoader().getResource("").getPath().substring(0,Thread.currentThread().getContextClassLoader().getResource("").getPath().length()-16)+"/sterngymimages/"+filename);
		try {
			file.transferTo(newFile);
		}catch (Exception e){
			e.printStackTrace();
		}
		Map<String,String > srcMap = new HashMap<String, String>();
		srcMap.put("src",filename);
		Map<String,Object> imgMap = new HashMap<String,Object>();
		imgMap.put("code",0);
		imgMap.put("msg","");
		imgMap.put("data",srcMap);
		return imgMap;
	}

	/**
	 * 查看课程信息
	 * @param model
	 * @param cid
	 * @return
	 */
	@RequestMapping("/admin/courseinfo.html")
	public String courseInfo(Model model,String cid){
		Course course = courseService.selectByPrimaryKey(Integer.parseInt(cid));
		model.addAttribute("course",course);
		//查询所有教练
		EmployeeExample example = new EmployeeExample();
		EmployeeExample.Criteria criteria = example.createCriteria();
		criteria.andEpostIdEqualTo(1);
		List<Employee> trainers = employeeService.selectByExample(example);
		model.addAttribute("trainers",trainers);
		//查询所有课程类型
		List<Coursecategory> coursecategories = coursecategoryService.selectByExample(new CoursecategoryExample());
		model.addAttribute("coursecategories",coursecategories);
		//查询所有课程功能
		List<Coursefunction> coursefunctions = coursefunctionService.selectByExample(new CoursefunctionExample());
		model.addAttribute("coursefunctions",coursefunctions);
		return "admin/course/courseinfo";
	}
	@RequestMapping("/admin/goaddorupdate.html")
	public String admingoaddPage(Model model, @RequestParam(required = false)String cid){
		//查询所有教练
		EmployeeExample example = new EmployeeExample();
		EmployeeExample.Criteria criteria = example.createCriteria();
		criteria.andEpostIdEqualTo(1);
		List<Employee> trainers = employeeService.selectByExample(example);
		model.addAttribute("trainers",trainers);
		//查询所有课程类型
		List<Coursecategory> coursecategories = coursecategoryService.selectByExample(new CoursecategoryExample());
		model.addAttribute("coursecategories",coursecategories);
		//查询所有课程功能
		List<Coursefunction> coursefunctions = coursefunctionService.selectByExample(new CoursefunctionExample());
		model.addAttribute("coursefunctions",coursefunctions);
		//如果是要更新,根据课程id查询课程
		if(cid!=null &&!cid.equals("")){
			Course course = courseService.selectByPrimaryKey(Integer.parseInt(cid));
			model.addAttribute("course",course);
		}
		return "admin/course/courseaddorupdate";
	}

	/**
	 * 更新或者添加课程
	 * @param course
	 * @return
	 */
	@RequestMapping("/admin/addorupdate.html")
	public String adminaddorupdatePage(Course course){
		if(course.getCid() == null){//添加
			if(course.getTrainerId().equals(-1)){
				course.setTrainerId(null);
			}
			course.setCcreatetime(new Date()); 

			int ids = courseService.insertSelective(course);
			Class class1 = new Class();
			class1.setClasstime("7:00-18:00");
			class1.setClassvolume(20);
			class1.setCourseId(course.getCid());
			class1.setEmplId(course.getTrainerId());
			class1.setHaveOrder(1);
			class1.setCourseId(course.getCid());
			classMapper.insertSelective(class1);

		}else{//更新
			if(course.getTrainerId().equals(-1)){
				course.setTrainerId(null);

			}
			ClassExample classExample = new ClassExample();
			ClassExample.Criteria  c = classExample.createCriteria();
			c.andCourseIdEqualTo(course.getCid());
			List<Class> list = classService.selectByExample(classExample);
			if(list == null||list.size() == 0) {
				Class class1 = new Class();
				class1.setClasstime("7:00-18:00");
				class1.setClassvolume(20);
				class1.setCourseId(course.getCid());
				class1.setEmplId(course.getTrainerId());
				class1.setHaveOrder(1);
				classMapper.insertSelective(class1);
			}else {
				Class class1 = list.get(0);
				class1.setCourseId(course.getCid());
				class1.setEmplId(course.getTrainerId());
				classMapper.updateByPrimaryKeySelective(class1);
			}

			courseService.updateByPrimaryKeySelective(course);
		}
		return "forward:/admin/course.html";
	}
	@RequestMapping("/admin/course/del.html")
	@ResponseBody
	public Map<String,Object> courseDel(String cid){
		int i = courseService.deleteByPrimaryKey(Integer.parseInt(cid));
		Map<String ,Object> delMap = new HashMap<String,Object>();
		if(i>0){//删除成功
			delMap.put("status",1);
		}else{
			delMap.put("status",0);
		}
		return delMap;
	}
	/**
	 * 上传课表
	 */
	@RequestMapping("/admin/courseupload.html")
	public String courseUpload(Model model){
		Sheet sheet = courseService.selectSheetByPrimaryKey(1);
		if(sheet!=null){
			model.addAttribute("sheetsrc",sheet.getSsrc());
		}
		return "admin/course/courseupload";
	}
	@RequestMapping("/admin/coursesheet.html")
	@ResponseBody
	public Map<String,Object> uploatSheet(MultipartFile file){
		Map<String,Object> uploadMap = new HashMap<String,Object>();
		Map<String,String> srcMap = new HashMap<String, String>();
		String filename = file.getOriginalFilename();
		Sheet sheet = new Sheet();
		sheet.setSsrc(filename);
		if(courseService.countByExample(new SheetExample())==0){
			courseService.insertSelective(sheet);
		}else {
			sheet.setSid(1);
			courseService.updateByPrimaryKey(sheet);
		}
		File newFile = new File(Thread.currentThread().getContextClassLoader().getResource("").getPath().substring(0,Thread.currentThread().getContextClassLoader().getResource("").getPath().length()-16)+"/sterngymimages/"+filename);
		try {
			file.transferTo(newFile);
		} catch (IOException e) {
			e.printStackTrace();
		}
		srcMap.put("src",filename);
		uploadMap.put("data",srcMap);
		uploadMap.put("code",0);
		uploadMap.put("msg","");
		return uploadMap;
	}
}

源码获取:俺的博客首页 "资源" 里下载!

猜你喜欢

转载自blog.csdn.net/m0_66863468/article/details/125402777