作者主页:源码空间站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/ 登录
运行截图
管理端页面
相关代码
课程管理控制器
@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;
}
}
如果也想学习本系统,下面领取。关注并回复:049ssh