博客目錄
- SSM+Mysql實(shí)現(xiàn)的共享單車管理系統(tǒng)
- 實(shí)現(xiàn)功能截圖
- 系統(tǒng)功能
- 使用技術(shù)
- 代碼
- 完整源碼
SSM+Mysql實(shí)現(xiàn)的共享單車管理系統(tǒng)
本系統(tǒng)一個(gè)學(xué)校共享單車管理的項(xiàng)目,通過(guò)線上系統(tǒng)化的管理,可以為后續(xù)的運(yùn)營(yíng)以及單車的項(xiàng)目運(yùn)轉(zhuǎn)提供極大的幫助。
(文末查看完整源碼)
實(shí)現(xiàn)功能截圖
用戶登錄
用戶管理‘
服務(wù)點(diǎn)管理
單車管理
分類管理
學(xué)生信息管理
單車租賃
信息統(tǒng)計(jì)匯總
更改密碼
系統(tǒng)功能
本系統(tǒng)實(shí)現(xiàn)了以下功能:
1、登錄
2、用戶管理
3、服務(wù)點(diǎn)管理
4、單車管理
5、單車租賃
6、學(xué)生信息管理
7、分類管理
8、信息統(tǒng)計(jì)匯總
9、系統(tǒng)設(shè)置
等
使用技術(shù)
數(shù)據(jù)庫(kù):mysql
開(kāi)發(fā)工具:Idea(Myeclispe、Eclipse也可以)
知識(shí)點(diǎn):SSM
項(xiàng)目結(jié)構(gòu)
代碼
java端
實(shí)體類
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();}@Overridepublic 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;
@Servicepublic class AdminServiceImpl implements AdminService {@Autowiredprivate AdminMapper adminMapper
;@Autowiredprivate PlaceMapper placeMapper
;@Overridepublic String checkUserPwd(Admin admin
) {
String password
= admin
.getaPassword();Admin realAdmin
= findByUsername(admin
.getaUsername());if(realAdmin
!= null ){if(password
.equals(realAdmin
.getaPassword())){return "成功";}return "密碼錯(cuò)誤~";}return "沒(méi)有此賬號(hào)~";}@Overridepublic boolean upDate(Admin admin
) {AdminExample adminExample
= new AdminExample();adminExample
.createCriteria().andAUsernameEqualTo(admin
.getaUsername());int i
= adminMapper
.updateByExampleSelective(admin
, adminExample
);return i
> 0 ? true : false;}@Overridepublic 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);if(admin
.getaPid() != null) {admin
.setPlace(placeMapper
.selectByPrimaryKey(admin
.getaPid()));}return admin
;}return null;}@Overridepublic 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
;}@Overridepublic 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);}@Overridepublic List<Place> loadPlace() {List<Place> places
= placeMapper
.selectByExample(new PlaceExample());return places
;}@Overridepublic 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);}}@Overridepublic 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.*;
@Service
public class BikeControllerImpl implements BikeService {@Autowiredprivate BikeMapper bikeMapper
;@Autowiredprivate CategoryService categoryService
;@Transactional@Overridepublic 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);}}@Overridepublic 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);}}@Overridepublic 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
;}@Transactional@Overridepublic 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();
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();return new JsonResult(false,ResultEnum.SYSTEM_ERROR);}}@Overridepublic 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
@RequestMapping("/admin")
public class AdminController {@Autowiredprivate 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
)) {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")@ResponseBodypublic 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")@ResponseBodypublic Page<Admin> showAll(Integer page
, Integer rows
){return adminService
.findAllToPage(page
,rows
);}@RequestMapping("/remove")@ResponseBodypublic JsonResult remove(Integer aid
){return adminService
.deleteById(aid
);}@RequestMapping("/loadPlace")@ResponseBodypublic List<Place> loadPlace(){return adminService
.loadPlace();}@RequestMapping("/loadForm")@ResponseBodypublic Admin loadForm(String username
){Admin admin
= adminService
.findByUsername(username
);return admin
;}@RequestMapping("/addOrUpdate")@ResponseBodypublic 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.*;
@Controller
@RequestMapping("/bike")public class BikeController {@Autowiredprivate BikeService bikeService
;@Autowiredprivate CategoryService categoryService
;@RequestMapping("/bikeManage")public String bikeManage(){return "bike";}@RequestMapping(value
= "/addOrUpdate",method
= RequestMethod.POST)@ResponseBodypublic 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
);}@RequestMapping("/showAll")@ResponseBodypublic Page<Bike> show(Integer page
, Integer rows
){return bikeService
.findAllToPage(page
,rows
);}@RequestMapping(value
= "/remove",method
= RequestMethod.POST)@ResponseBodypublic JsonResult remove(String bids
,String cids
){return bikeService
.deleteById(bids
,cids
);}@RequestMapping("/loadForm")@ResponseBodypublic Bike loadForm(Integer bid
){return bikeService
.findById(bid
);}@RequestMapping(value
= "/loadCategory",method
= RequestMethod.POST)@ResponseBodypublic List<Category> loadCategory(){return categoryService
.findAll();}}
完整源碼
覺(jué)得有用,記得一鍵三連哦!
總結(jié)
以上是生活随笔為你收集整理的SSM+Mysql实现的共享单车管理系统(功能包含分角色,登录、用户管理、服务点管理、单车管理、分类管理、学生信息管理、单车租赁、信息统计、系统设置等)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。