博客目录
- SSM+Mysql实现的共享单车管理系统
- 实现功能截图
- 系统功能
- 使用技术
- 代码
- 完整源码
SSM+Mysql实现的共享单车管理系统
本系统一个学校共享单车管理的项目,通过线上系统化的管理,可以为后续的运营以及单车的项目运转提供极大的帮助。
(文末查看完整源码)
实现功能截图
用户登录
用户管理‘
服务点管理
单车管理
分类管理
学生信息管理
单车租赁
信息统计汇总
更改密码
系统功能
本系统实现了以下功能:
1、登录
2、用户管理
3、服务点管理
4、单车管理
5、单车租赁
6、学生信息管理
7、分类管理
8、信息统计汇总
9、系统设置
等
使用技术
数据库:mysql
开发工具:Idea(Myeclispe、Eclipse也可以)
知识点:SSM
项目结构
代码
java端
实体类
Admin.java
package com.webike.pojo;
import java.util.Date;
public class Admin {
private Integer aid;
private Integer aPid;
private Place place;
private String aUsername;
private String aPassword;
private String aRealName;
private String aPhone;
private String aRole;
private String aIcon;
private Date aLoginTime;
private Date aCreateTime;
private Date aUpdateTime;
private String aComment;
public Place getPlace() {
return place;
}
public void setPlace(Place place) {
this.place = place;
}
public Integer getAid() {
return aid;
}
public void setAid(Integer aid) {
this.aid = aid;
}
public Integer getaPid() {
return aPid;
}
public void setaPid(Integer aPid) {
this.aPid = aPid;
}
public String getaUsername() {
return aUsername;
}
public void setaUsername(String aUsername) {
this.aUsername = aUsername == null ? null : aUsername.trim();
}
public String getaPassword() {
return aPassword;
}
public void setaPassword(String aPassword) {
this.aPassword = aPassword == null ? null : aPassword.trim();
}
public String getaRealName() {
return aRealName;
}
public void setaRealName(String aRealName) {
this.aRealName = aRealName == null ? null : aRealName.trim();
}
public String getaPhone() {
return aPhone;
}
public void setaPhone(String aPhone) {
this.aPhone = aPhone == null ? null : aPhone.trim();
}
public String getaRole() {
return aRole;
}
public void setaRole(String aRole) {
this.aRole = aRole == null ? null : aRole.trim();
}
public String getaIcon() {
return aIcon;
}
public void setaIcon(String aIcon) {
this.aIcon = aIcon == null ? null : aIcon.trim();
}
public Date getaLoginTime() {
return aLoginTime;
}
public void setaLoginTime(Date aLoginTime) {
this.aLoginTime = aLoginTime;
}
public Date getaCreateTime() {
return aCreateTime;
}
public void setaCreateTime(Date aCreateTime) {
this.aCreateTime = aCreateTime;
}
public Date getaUpdateTime() {
return aUpdateTime;
}
public void setaUpdateTime(Date aUpdateTime) {
this.aUpdateTime = aUpdateTime;
}
public String getaComment() {
return aComment;
}
public void setaComment(String aComment) {
this.aComment = aComment == null ? null : aComment.trim();
}
@Override
public String toString() {
return "Admin{" +
"aid=" + aid +
", aPid=" + aPid +
", place=" + place +
", aUsername='" + aUsername + '\'' +
", aPassword='" + aPassword + '\'' +
", aRealName='" + aRealName + '\'' +
", aPhone='" + aPhone + '\'' +
", aRole='" + aRole + '\'' +
", aIcon='" + aIcon + '\'' +
", aLoginTime=" + aLoginTime +
", aCreateTime=" + aCreateTime +
", aUpdateTime=" + aUpdateTime +
", aComment='" + aComment + '\'' +
'}';
}
}
Bike,java
package com.webike.pojo;
import java.util.Date;
public class Bike {
private Integer bid;
private String bName;
private String bIcon;
private Integer bCid;
private String bInTime;
private String bState;
private Date bCreateTime;
private Date bUpdateTime;
private String bComment;
public Integer getBid() {
return bid;
}
public void setBid(Integer bid) {
this.bid = bid;
}
public String getbName() {
return bName;
}
public void setbName(String bName) {
this.bName = bName == null ? null : bName.trim();
}
public String getbIcon() {
return bIcon;
}
public void setbIcon(String bIcon) {
this.bIcon = bIcon == null ? null : bIcon.trim();
}
public Integer getbCid() {
return bCid;
}
public void setbCid(Integer bCid) {
this.bCid = bCid;
}
public String getbInTime() {
return bInTime;
}
public void setbInTime(String bInTime) {
this.bInTime = bInTime == null ? null : bInTime.trim();
}
public String getbState() {
return bState;
}
public void setbState(String bState) {
this.bState = bState == null ? null : bState.trim();
}
public Date getbCreateTime() {
return bCreateTime;
}
public void setbCreateTime(Date bCreateTime) {
this.bCreateTime = bCreateTime;
}
public Date getbUpdateTime() {
return bUpdateTime;
}
public void setbUpdateTime(Date bUpdateTime) {
this.bUpdateTime = bUpdateTime;
}
public String getbComment() {
return bComment;
}
public void setbComment(String bComment) {
this.bComment = bComment == null ? null : bComment.trim();
}
}
service层
AdminServiceImpl.java
package com.webike.service.impl;
import com.webike.dao.AdminMapper;
import com.webike.dao.PlaceMapper;
import com.webike.dto.JsonResult;
import com.webike.dto.Page;
import com.webike.enums.ResultEnum;
import com.webike.enums.RoleEnum;
import com.webike.pojo.*;
import com.webike.service.AdminService;
import com.webike.utils.FileUtil;
import com.webike.utils.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.Date;
import java.util.List;
/**
* Created by Ming on 2018/2/9.
*/
@Service
public class AdminServiceImpl implements AdminService {
@Autowired
private AdminMapper adminMapper;
@Autowired
private PlaceMapper placeMapper;
@Override
public String checkUserPwd(Admin admin) {
// String password = MD5Util.getMD5(admin.getaPassword());
String password = admin.getaPassword();
Admin realAdmin = findByUsername(admin.getaUsername());
if(realAdmin != null ){
if(password.equals(realAdmin.getaPassword())){
return "成功";
}
return "密码错误~";
}
return "没有此账号~";
}
@Override
public boolean upDate(Admin admin) {
AdminExample adminExample = new AdminExample();
adminExample.createCriteria().andAUsernameEqualTo(admin.getaUsername());
int i = adminMapper.updateByExampleSelective(admin, adminExample);
return i > 0 ? true : false;
}
@Override
public Admin findByUsername(String username) {
AdminExample adminExample = new AdminExample();
adminExample.createCriteria().andAUsernameEqualTo(username);
List<Admin> admins = adminMapper.selectByExample(adminExample);
if(admins != null && admins.size() > 0){
Admin admin = admins.get(0);
//pid不为空设置站点对象
if(admin.getaPid() != null) {
admin.setPlace(placeMapper.selectByPrimaryKey(admin.getaPid()));
}
return admin;
}
return null;
}
@Override
public Page<Admin> findAllToPage(Integer page, Integer rows) {
Page<Admin> aPage = new Page<>();
List<Admin> lists = adminMapper.findToPage((page-1)*rows,rows);
aPage.setRows(lists);
aPage.setTotal(adminMapper.countByExample(new AdminExample()));
return aPage;
}
@Override
public JsonResult deleteById(Integer aid) {
if (aid == null) return new JsonResult(false, ResultEnum.SYSTEM_ERROR);
int i = adminMapper.deleteByPrimaryKey(aid);
return i > 0 ? new JsonResult(true, ResultEnum.DELETE_SUCCESS)
: new JsonResult(false, ResultEnum.DELETE_FAIL);
}
@Override
public List<Place> loadPlace() {
List<Place> places = placeMapper.selectByExample(new PlaceExample());
return places;
}
@Override
public JsonResult add(MultipartFile adminIcon, Admin admin, HttpServletRequest request) {
if(!adminIcon.isEmpty()){
String path = FileUtil.uploadImage(adminIcon, "adminIcon", request);
if(path == null) return new JsonResult(false, ResultEnum.UPLOAD_TYPE_ERROR);
admin.setaIcon(path);
}
if(admin.getaRole() == null) admin.setaRole(RoleEnum.MANAGER.getMassage());
admin.setaPassword(MD5Util.getMD5(admin.getaPassword()));
admin.setaCreateTime(new Date());
admin.setaUpdateTime(new Date());
try{
int row = adminMapper.insertSelective(admin);
return row > 0 ? new JsonResult(true, ResultEnum.ADD_SUCCESS)
: new JsonResult(false, ResultEnum.ADD_FAIL);
}catch (Exception e){
e.printStackTrace();
return new JsonResult(false, ResultEnum.REPEAT_ERROR);
}
}
@Override
public JsonResult update(MultipartFile adminIcon, Admin admin, HttpServletRequest request) {
try{
if(!adminIcon.isEmpty()){
//更新首先要先删除原来的文件
if(admin.getaIcon() != null){
File file = new File(request.getServletContext().getRealPath("/" + admin.getaIcon()));
if(file != null) file.delete();
}
String path = FileUtil.uploadImage(adminIcon, "adminIcon", request);
if(path == null) return new JsonResult(false, ResultEnum.UPLOAD_TYPE_ERROR);
admin.setaIcon(path);
}
admin.setaUpdateTime(new Date());
int i = adminMapper.updateByPrimaryKeySelective(admin);
return i > 0 ? new JsonResult(false, ResultEnum.UPDATE_SUCCESS)
: new JsonResult(false, ResultEnum.UPDATE_FAIL);
}catch (Exception e){
e.printStackTrace();
return new JsonResult(false, ResultEnum.SYSTEM_ERROR);
}
}
}
BikeControllerImpl.java
package com.webike.service.impl;
import com.webike.dao.BikeMapper;
import com.webike.dto.JsonResult;
import com.webike.dto.Page;
import com.webike.enums.BikeStateEnum;
import com.webike.enums.ResultEnum;
import com.webike.pojo.Bike;
import com.webike.pojo.BikeExample;
import com.webike.service.BikeService;
import com.webike.service.CategoryService;
import com.webike.utils.ArithmeticUtil;
import com.webike.utils.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.*;
/**
* Created by Ming on 2018/2/10.
*/
@Service
public class BikeControllerImpl implements BikeService {
@Autowired
private BikeMapper bikeMapper;
@Autowired
private CategoryService categoryService;
//事务控制 该单车分类剩余量+1
@Transactional
@Override
public JsonResult add(MultipartFile bikeIcon, Bike bike, HttpServletRequest request,Integer bCount) {
if(!bikeIcon.isEmpty()){
String path = FileUtil.uploadImage(bikeIcon, "bikeIcon", request);
if(path == null) return new JsonResult(false, ResultEnum.UPLOAD_TYPE_ERROR);
bike.setbIcon(path);
}
bike.setbState(BikeStateEnum.AVAILABLE.getState());
bike.setbCreateTime(new Date());
bike.setbUpdateTime(new Date());
try{
int row = 0;
for (int i = 0; i < bCount; i++) {
row += bikeMapper.insertSelective(bike);
}
if(row == bCount){
return categoryService.updateRemainById(bike.getbCid(),bCount) ?
new JsonResult(true, ResultEnum.ADD_SUCCESS):new JsonResult(false, ResultEnum.ADD_FAIL);
}else{
throw new RuntimeException();
}
}catch (Exception e){
e.printStackTrace();
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return new JsonResult(false,ResultEnum.SYSTEM_ERROR);
}
}
@Override
public JsonResult update(MultipartFile bikeIcon, Bike bike, HttpServletRequest request) {
try{
if(!bikeIcon.isEmpty()){
//更新首先要先删除原来的文件
if(bike.getbIcon() != null){
File file = new File(request.getServletContext().getRealPath("/" + bike.getbIcon()));
if(file != null) file.delete();
}
String path = FileUtil.uploadImage(bikeIcon, "bikeIcon", request);
if(path == null) return new JsonResult(false, ResultEnum.UPLOAD_TYPE_ERROR);
bike.setbIcon(path);
}
bike.setbUpdateTime(new Date());
int i = bikeMapper.updateByPrimaryKeySelective(bike);
return i > 0 ? new JsonResult(false, ResultEnum.UPDATE_SUCCESS)
: new JsonResult(false, ResultEnum.UPDATE_FAIL);
}catch (Exception e){
e.printStackTrace();
return new JsonResult(false, ResultEnum.SYSTEM_ERROR);
}
}
@Override
public Page<Bike> findAllToPage(Integer page, Integer rows) {
Page<Bike> bPage = new Page<>();
List<Bike> lists = bikeMapper.findToPage((page-1)*rows,rows);
bPage.setRows(lists);
bPage.setTotal(bikeMapper.countByExample(new BikeExample()));
return bPage;
}
//事务控制 该单车的分类剩余量减size
@Transactional
@Override
public JsonResult deleteById(String bids,String cids) {
try{
String[] bidList = bids.split(",");
String[] cidList = cids.split(",");
int row = 0;
for (int i = 0; i < bidList.length; i++) {
row += bikeMapper.deleteByPrimaryKey(Integer.parseInt(bidList[i]));
}
if(row == bidList.length){ //更新分类表的剩余数量
HashMap<String, Integer> cidMap = ArithmeticUtil.getElementForTimes(cidList);
Set<Map.Entry<String, Integer>> entries = cidMap.entrySet();
for (Map.Entry<String, Integer> entry : entries) {
boolean isSuccess = categoryService.updateRemainById(Integer.parseInt(entry.getKey()), - entry.getValue());
if(!isSuccess) throw new RuntimeException();
}
return new JsonResult(true, ResultEnum.DELETE_SUCCESS);
}else{
throw new RuntimeException();
}
}catch (Exception e){
e.printStackTrace();
// throw new RuntimeException(e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return new JsonResult(false,ResultEnum.SYSTEM_ERROR);
}
}
@Override
public Bike findById(Integer bid) {
return bikeMapper.selectByPrimaryKey(bid);
}
}
controller层
AdminController.java
package com.webike.web;
import com.webike.dto.JsonResult;
import com.webike.dto.Page;
import com.webike.enums.ResultEnum;
import com.webike.pojo.Admin;
import com.webike.pojo.Place;
import com.webike.service.AdminService;
import com.webike.utils.MD5Util;
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.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;
/**管理员controller
* Created by Ming on 2018/2/8.
*/
@Controller
@RequestMapping("/admin")
public class AdminController {
@Autowired
private AdminService adminService;
//跳转到首页
@RequestMapping("/index")
public String index(){
return "index";
}
//验证登陆
@RequestMapping(value = "/login",method = RequestMethod.POST)
public String login(Admin admin, Model model, HttpSession session){
String message = adminService.checkUserPwd(admin);
if("成功".equals(message)) {
//注入Session
Admin realAdmin = adminService.findByUsername(admin.getaUsername());
session.setAttribute("admin",realAdmin);
//更新登陆的时间
admin.setaLoginTime(new Date());
admin.setaUpdateTime(new Date());
admin.setaPassword(null);
adminService.upDate(admin);
return "redirect:index";
}
model.addAttribute("msg",message);
return "forward:/login.jsp";
}
//退出登陆
@RequestMapping("/logout")
public String logout(HttpSession session){
session.invalidate();
return "redirect:/login.jsp";
}
//跳转到修改密码的页面
@RequestMapping("/rePassword")
public String rePassword(){
return "rePassword";
}
//修改提交的密码
@RequestMapping("/submitResetPwd")
@ResponseBody
public JsonResult submitResetPwd(String password, String newPassword,HttpSession httpSession){
Admin admin = (Admin) httpSession.getAttribute("admin");
if(!admin.getaPassword().equals(password))
return new JsonResult(false,ResultEnum.OLD_PASSWORD_ERROR);
admin.setaPassword(MD5Util.getMD5(newPassword));
admin.setaUpdateTime(new Date());
boolean isSuccess = adminService.upDate(admin);
if(isSuccess) return new JsonResult(isSuccess, ResultEnum.UPDATE_SUCCESS);
return new JsonResult(isSuccess, ResultEnum.UPDATE_FAIL);
}
//跳转到用户管理页面
@RequestMapping("/adminManage")
public String adminMange(){
return "admin";
}
//显示用户页面
@RequestMapping("/showAll")
@ResponseBody
public Page<Admin> showAll(Integer page, Integer rows){
return adminService.findAllToPage(page,rows);
}
//删除用户
@RequestMapping("/remove")
@ResponseBody
public JsonResult remove(Integer aid){
return adminService.deleteById(aid);
}
// 加载服务点到表单下拉框 loadPlace
@RequestMapping("/loadPlace")
@ResponseBody
public List<Place> loadPlace(){
return adminService.loadPlace();
}
//回显用户表单
@RequestMapping("/loadForm")
@ResponseBody
public Admin loadForm(String username){
Admin admin = adminService.findByUsername(username);
return admin;
}
//addOrUpdate
@RequestMapping("/addOrUpdate")
@ResponseBody
public JsonResult addOrUpdate(MultipartFile adminIcon, Admin admin, HttpServletRequest request){
if(admin.getAid() == null) return adminService.add(adminIcon,admin,request);
return adminService.update(adminIcon,admin,request);
}
}
BikeController.java
package com.webike.web;
import com.webike.dto.JsonResult;
import com.webike.dto.Page;
import com.webike.pojo.Bike;
import com.webike.pojo.Category;
import com.webike.pojo.Student;
import com.webike.service.BikeService;
import com.webike.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
/**
* Created by Ming on 2018/2/10.
*/
@Controller
@RequestMapping("/bike")
public class BikeController {
@Autowired
private BikeService bikeService;
@Autowired
private CategoryService categoryService;
//跳转到 bike管理页面
@RequestMapping("/bikeManage")
public String bikeManage(){
return "bike";
}
//添加或更新bike
@RequestMapping(value = "/addOrUpdate",method = RequestMethod.POST)
@ResponseBody
public JsonResult addOrUpdate(MultipartFile bikeIcon, Bike bike, HttpServletRequest request,Integer bCount){
if(bCount != null) return bikeService.add(bikeIcon,bike,request,bCount);
return bikeService.update(bikeIcon,bike,request);
}
//showAll bike
@RequestMapping("/showAll")
@ResponseBody
public Page<Bike> show(Integer page, Integer rows){
return bikeService.findAllToPage(page,rows);
}
//删除单车和更新单车的分类
@RequestMapping(value = "/remove",method = RequestMethod.POST)
@ResponseBody
public JsonResult remove(String bids,String cids){
return bikeService.deleteById(bids,cids);
}
//点击修改回显bike弹出表单
@RequestMapping("/loadForm")
@ResponseBody
public Bike loadForm(Integer bid){
return bikeService.findById(bid);
}
//回显bike分类
@RequestMapping(value = "/loadCategory",method = RequestMethod.POST)
@ResponseBody
public List<Category> loadCategory(){
return categoryService.findAll();
}
}
完整源码
觉得有用,记得一键三连哦!