作者主页:夜未央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+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/ 登录
- package com.stern.controller;
-
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import com.stern.mapper.ClassMapper;
- import com.stern.pojo.*;
- import com.stern.pojo.Class;
- import com.stern.pojo.ClassExample.Criteria;
- import com.stern.service.*;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.multipart.MultipartFile;
-
- import java.io.File;
- import java.io.IOException;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
-
- /**
- * 课程管理 -控制层
- */
- @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
coursecategories = coursecategoryService.selectByExample(new CoursecategoryExample()); - model.addAttribute("coursecategories",coursecategories);
- //查询所有课程功能
- List
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
coursecategories1 = coursecategoryService.selectByExample(coursecategoryExample); - criteria.andCcateIdEqualTo(coursecategories1.get(0).getCateId());
- }
- if (func!=null&&!func.equals("全部")){
- criteria2.andFnameEqualTo(func);
- List
coursefunctions1 = coursefunctionService.selectByExample(coursefunctionExample); - criteria.andCfunctionIdEqualTo(coursefunctions1.get(0).getFid());
- }
- PageHelper.startPage(_page,6);
- List
courses = courseService.selectByExampleWithBLOBs(courseExample); - PageInfo
pageInfo = new PageInfo(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
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
trainers = employeeService.selectByExample(employeeExample); - model.addAttribute("trainers",trainers);
- return "courseinfo";
- }
- /**
- * 后台管理跳转到课程管理界面
- * @return
- */
- @RequestMapping("/admin/course.html")
- public String admincourse(Model model){
- //查询所有员工,进行教练名称显示
- List
employees = employeeService.selectByExample(new EmployeeExample()); - model.addAttribute("employees",employees);
- //查询所有课程类型
- List
coursecategories = coursecategoryService.selectByExample(new CoursecategoryExample()); - model.addAttribute("coursecategories",coursecategories);
- //查询所有课程功能
- List
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
courselistPage(String page, String limit,Model model,String cname){ - List
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
courses = courseService.selectByExampleWithBLOBs(example); - PageInfo
pageInfo = new PageInfo(courses); - Map
pageMap = new HashMap(); - 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
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
srcMap = new HashMap(); - srcMap.put("src",filename);
- Map
imgMap = new HashMap(); - 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
trainers = employeeService.selectByExample(example); - model.addAttribute("trainers",trainers);
- //查询所有课程类型
- List
coursecategories = coursecategoryService.selectByExample(new CoursecategoryExample()); - model.addAttribute("coursecategories",coursecategories);
- //查询所有课程功能
- List
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
trainers = employeeService.selectByExample(example); - model.addAttribute("trainers",trainers);
- //查询所有课程类型
- List
coursecategories = coursecategoryService.selectByExample(new CoursecategoryExample()); - model.addAttribute("coursecategories",coursecategories);
- //查询所有课程功能
- List
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
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
courseDel(String cid){ - int i = courseService.deleteByPrimaryKey(Integer.parseInt(cid));
- Map
delMap = new HashMap(); - 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
uploatSheet(MultipartFile file){ - Map
uploadMap = new HashMap(); - Map
srcMap = new HashMap(); - 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;
- }
- }
- package com.stern.controller;
-
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import com.stern.pojo.Employee;
- import com.stern.pojo.EmployeeExample;
- import com.stern.pojo.Post;
- import com.stern.pojo.PostExample;
- import com.stern.service.EmployeeService;
- import com.stern.service.PostService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.ResponseBody;
-
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
-
- /**
- * 员工 -控制层
- */
- @Controller
- public class EmployeeController {
- @Autowired
- private PostService postService;
- @Autowired
- private EmployeeService employeeService;
- /**
- * 后台员工管理
- * @return
- */
- @RequestMapping("/admin/employee.html")
- public String employeePage(Model model){
- //查询所有职务
- List
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
employeelistPage(String page, String limit, Model model, String ename){ - Map
employeeMap = new HashMap(); - //查询所有职务
- List
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
employees = employeeService.selectByExample(employeeExample); - PageInfo
employeePageInfo = new PageInfo(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
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
doaddorupdate(Employee employee,String time){ - Map
updateMap = new HashMap(); - 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
delEmployee(String eid){ - Map
delMap = new HashMap(); - 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
trainerPage(String page,String limit,String ename,Model model){ - Map
trainerMap = new HashMap(); - 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
trainers = employeeService.selectByExample(employeeExample); - PageInfo
trainerPageInfo = new PageInfo(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
trainerDoAddOrUpdate(Employee employee,String time){ - Map
trainerMap = new HashMap(); - 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
delTrainer(String eid){ - Map
delMap = new HashMap(); - int i = employeeService.deleteByPrimaryKey(Integer.parseInt(eid));
- if(i>0){
- delMap.put("status",1);
- }else {
- delMap.put("status",0);
- }
- return delMap;
- }
-
- }
如果也想学习本系统,下面领取。关注并回复:094ssm