作者主页:夜未央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. 前端:HTML+LayUI+bootstrap+jQuery
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中spring-database.xml配置文件中的数据库配置改为自己的配置;
4. 运行项目,在浏览器中输入http://localhost:8080/ 登录
运行截图
代码相关
汽车管理控制器
@Controller
@RequestMapping("/cart")
public class CartController {
private CartService cartService;
@Autowired
public CartController(CartService cartService) {
this.cartService = cartService;
}
/**
* 添加车辆
* @param cart
* @return
*/
@RequestMapping(value = "/addCart")
@ResponseBody
public Map<String,Object> addcart(@RequestBody Cart cart){
return cartService.addCart(cart);
}
/**
* 多条件查询车辆
* @param cart
* @return
*/
@RequestMapping(value = "/getCartList")
@ResponseBody
public Map<String,Object> getCartList(@RequestBody(required = false) Cart cart){
return cartService.selectbyCondiction(cart);
}
/**
* 通过id查看
* @param map
* @return
*/
@RequestMapping(value = "/getCartDetail")
@ResponseBody
public Map<String,Object> getCarDetail(@RequestBody(required = false) Map map){
return cartService.selectbyId(map.get("carId").toString());
}
/**
* 修改车辆信息
* @param cart
* @return
*/
@RequestMapping(value = "/updateCart")
@ResponseBody
public Map<String,Object> updateCar(@RequestBody(required = false) Cart cart){
return cartService.updateCar(cart);
}
/**
*
* @param cart
* @return
*/
@RequestMapping(value = "/removeCar")
@ResponseBody
public Map<String,Object> removeCar(@RequestBody(required = false) Cart cart){
return cartService.removeCart(cart);
}
}
登录管理控制器
@Controller
@RequestMapping("/login")
public class LoginController {
final private StudentService studentService;
final private TeacherService teacherService;
@Autowired
public LoginController(StudentService studentService, TeacherService teacherService) {
this.studentService = studentService;
this.teacherService = teacherService;
}
/**
* 登录 返回格式
*
* @param map
* @param request
* @return
*/
@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> login(@RequestBody Map<String, String> map, HttpServletRequest request) {
String phone = map.get("phone");
String password = map.get("password");
String role = map.get("role");
Teacher teacher = new Teacher();
teacher.setTeaphone(phone);
boolean flag = false;
if (role.equals("student")) {
Student student = studentService.getByPhone(phone);
if (student != null && password.equals(student.getStupwd())) {
flag = true;
request.getSession().setAttribute("user", student);
}
} else {
Integer roleTmp = role.equals("admin") ? 1 : 0;
teacher.setTearole(roleTmp);
Teacher teacherRe = teacherService.selectByPone(teacher);
if (teacherRe != null && teacherRe.getTeapwd().equals(password)) {
flag = true;
request.getSession().setAttribute("user", teacherRe);
}
}
Map<String, Object> mapjson = new HashMap<>();
if (flag) {
mapjson.put("code", 200);
mapjson.put("role", role);
} else {
mapjson.put("code", 201);
}
return mapjson;
}
/**
* 教练 管理员的修改用户信息
*
* @param request
* @return
*/
@RequestMapping(value = "/teacherInfo", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> teacherInfo(HttpServletRequest request) {
Map<String, Object> mapjson = new HashMap<>();
Teacher teacher = (Teacher) request.getSession().getAttribute("user");
teacher.setTeapwd("");
mapjson.put("code", 200);
mapjson.put("data", teacher);
return mapjson;
}
/**
* 注销登录
*
* @param request
* @return
*/
@RequestMapping(value = "/logout")
public String loginOut(HttpServletRequest request) {
request.getSession().removeAttribute("user");
return "redirect:/index.html";
}
/**
* @param request
* @return
*/
@RequestMapping(value = "/getStudentInfo", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> getStudentInfo(HttpServletRequest request) {
Map<String, Object> mapjson = new HashMap<>();
Student student = (Student) request.getSession().getAttribute("user");
student.setStupwd("");
mapjson.put("code", 200);
mapjson.put("data", student);
return mapjson;
}
/**
* 获得验证码
*
* @param map
* @param request
* @return
*/
@RequestMapping(value = "/getCode", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> getCode(@RequestBody Map<String, String> map, HttpServletRequest request) {
String phone = map.get("phone");
String role = map.get("role");
Teacher teacher = new Teacher();
teacher.setTeaphone(phone);
Map<String, Object> mapCode = new HashMap<>();
Map<String, Object> mapjson = new HashMap<>();
int mobileCode = (int) ((Math.random() * 9 + 1) * 100000);
mapCode.put("number", mobileCode + "");
mapCode.put("phone", phone);
boolean flag = false;
if (role.equals("student")) {
if (studentService.getByPhone(phone) != null) {
flag = true;
}
} else {
Integer roleTmp = role.equals("admin") ? 1 : 0;
teacher.setTearole(roleTmp);
if (teacherService.selectByPone(teacher) != null) {
flag = true;
}
}
// if (flag&& Send.sendCode(mobileCode,phone)){
if (flag) {
//发送手机号到手机
mapjson.put("code", 200);
mapjson.put("number", mobileCode);
mapCode.put("time", System.currentTimeMillis());
mapCode.put("role", role);
request.getSession().setAttribute("smscode", mapCode);
} else {
mapjson.put("code", 201);
mapjson.put("msg", "手机号不存在,请查证");
}
return mapjson;
}
/**
* 获得验证码 公用
*
* @param map
* @param request
* @return
*/
@RequestMapping(value = "/getPhoneCode", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> getPhoneCode(@RequestBody Map<String, String> map, HttpServletRequest request) {
String phone = map.get("phone");
Teacher teacher = new Teacher();
teacher.setTeaphone(phone);
Map<String, Object> mapCode = new HashMap<>();
Map<String, Object> mapjson = new HashMap<>();
int mobileCode = (int) ((Math.random() * 9 + 1) * 100000);
mapCode.put("number", mobileCode + "");
mapCode.put("phone", phone);
boolean flag = false;
// if (flag&& Send.sendCode(mobileCode,phone)){
mapCode.put("time",System.currentTimeMillis()+"");
mapjson.put("code",200);
mapjson.put("number", mobileCode + "");
request.getSession().setAttribute("smscode", mapCode);
// }
return mapjson;
}
@RequestMapping(value = "/updatePhone", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> updatePhone(@RequestBody Map<String, String> map, HttpServletRequest request) {
String phone = map.get("phone");
String number=map.get("number");
Map<String, Object> mapjson = new HashMap<>();
Object object=request.getSession().getAttribute("user");
//判断验证码手机是否合法
Map<String,Object> mapSession= (Map<String, Object>) request.getSession().getAttribute("smscode");
System.out.println(mapSession);
System.out.println(map);
if (mapSession.get("phone").toString().equals(phone) && mapSession.get("number").toString().equals(number) &&
System.currentTimeMillis() - Long.parseLong(mapSession.get("time").toString()) < 60 * 1000){
if (object instanceof Student){
Student student= (Student) object;
Student studenttmp=studentService.getByPhone(student.getStuphone());
studenttmp.setStuphone(phone);
request.getSession().setAttribute("user",studenttmp);
return studentService.updateStudent(studenttmp);
}
else{
Teacher teacher= (Teacher) object;
Teacher teachertmp=teacherService.selectByPone(teacher);
teachertmp.setTeaphone(phone);
request.getSession().setAttribute("user",teachertmp);
return teacherService.updateTeacher(teachertmp);
}
}
else{
mapjson.put("code",201);
mapjson.put("msg","时间超时重新发送");
}
return mapjson;
}
/**
* 获得用户的信息
* @param request
* @return
*/
@RequestMapping(value = "/getUserInfo", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> updatePhone(HttpServletRequest request) {
Map<String, Object> mapjson = new HashMap<>();
Object object=request.getSession().getAttribute("user");
//判断验证码手机是否合法
if (object instanceof Student){
Student student=(Student) object;
mapjson.put("img",student.getStuimg());
mapjson.put("name",student.getStuname());
}
else{
Teacher teacher=(Teacher) object;
mapjson.put("img",teacher.getTeaimg());
mapjson.put("name",teacher.getTeaname());
}
return mapjson;
}
/**
* 验证手机号和验证码
*
* @param map
* @param request
* @return
*/
@RequestMapping(value = "/resetPassword", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> checkCode(@RequestBody Map<String, String> map, HttpServletRequest request) {
Map<String, Object> mapjson = new HashMap<>();
String phone = map.get("phone");
String number = map.get("number");
String role = map.get("role");
String password = map.get("password");
Map<String, Object> mapSession = (Map<String, Object>) request.getSession().getAttribute("smscode");
if (mapSession.get("phone").equals(phone) && mapSession.get("number").equals(number) &&
System.currentTimeMillis() - Long.parseLong(mapSession.get("time").toString()) < 60 * 1000
&& role.equals(mapSession.get("role"))) {
boolean action = false;
switch (role) {
case "student":
action = studentService.updatePassword(phone, password);
break;
case "admin":
action = teacherService.updatePassword(phone, password, 1);
break;
case "teacher":
action = teacherService.updatePassword(phone, password, 0);
break;
}
if (action) {
mapjson.put("code", 200);
} else {
mapjson.put("code", 202);
}
} else {
request.getSession().removeAttribute("smscode");
mapjson.put("code", 201);
}
return mapjson;
}
@RequestMapping(value = "/updatePasswordTeacher", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> updatePasswordTeacher(@RequestBody Map map, HttpServletRequest request) {
Map<String, Object> mapjson = new HashMap<>();
Teacher teacher = (Teacher) request.getSession().getAttribute("user");
//判断原密码是否正确
Teacher teacherTmp=teacherService.selectByPone(teacher);
System.out.println(teacherTmp.getTeapwd());
if(map.get("oldpassword").toString().equals(teacherTmp.getTeapwd())){
//修改session的的密码
teacherTmp.setTeapwd(map.get("newpassword").toString());
request.getSession().setAttribute("user",teacherTmp);
//修改数据库中的
return teacherService.updateTeacher(teacherTmp);
}
else{
mapjson.put("code",201);
mapjson.put("msg","原密码错误");
return mapjson;
}
}
/**
* 修改密码 学生
* @param map
* @param request
* @return
*/
@RequestMapping(value = "/updatePasswordStudent", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> updatePasswordStudent(@RequestBody Map map, HttpServletRequest request) {
Map<String, Object> mapjson = new HashMap<>();
Student student = (Student) request.getSession().getAttribute("user");
//判断原密码是否正确
Student studentTmp=studentService.getByPhone(student.getStuphone().toString());
System.out.println(studentTmp.getStupwd());
if(map.get("oldpassword").toString().equals(studentTmp.getStupwd())){
//修改session的的密码
studentTmp.setStupwd(map.get("newpassword").toString());
request.getSession().setAttribute("user",studentTmp);
//修改数据库中的
return studentService.updateStudent(studentTmp);
}
else{
mapjson.put("code",201);
mapjson.put("msg","原密码错误");
return mapjson;
}
}
@ResponseBody
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public Map<String, Object> upload(HttpServletRequest request, @RequestParam("file") MultipartFile file) {
Map<String, Object> map = new HashMap<>();
// String path=request.getSession().getServletContext().getRealPath("/");
String path = request.getSession().getServletContext().getRealPath("/img");
System.out.println(path);
String fileName = UUID.randomUUID().toString().replaceAll("-", "") + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
System.out.println(fileName);
System.out.println(path);
File targetFile = new File(path, fileName);
if (!targetFile.exists()) {
targetFile.mkdirs();
}
// 保存
try {
file.transferTo(targetFile);
map.put("code", 200);
map.put("data", fileName);
} catch (Exception e) {
e.printStackTrace();
map.put("code", 201);
}
return map;
}
}
如果也想学习本系统,下面领取。关注并回复:068ssm