基于javaweb+mysql的ssm共享汽车租赁平台(java+ssm+jsp+jquery+mysql)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的SSM共享汽车租赁平台(java+ssm+jsp+jquery+mysql)
项目介绍
本项目分为前后台,前台为普通用户登录,后台为管理员登录; 管理员角色包含以下功能: 管理员登录,修改管理员信息,用户信息管理,管理新闻公告,汽车品牌信息管理,城市信息管理,租赁点信息管理,共享汽车信息管理,汽车订单信息管理,汽车评价信息管理等功能。 用户角色包含以下功能: 查看首页,查看网站公告,查看可用共享汽车,查看租赁点,查看汽车详情,加入租赁单,提交订单,查看我的订单,修改个人信息等功能。
环境需要
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项目:否;
技术栈
- 后端:Spring+SpringMVC+Mybatis 2. 前端:JSP+CSS+JavaScript+jQuery
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中springmvc-servlet.xml配置文件中的数据库配置改为自己的配置; 4. 运行项目,在浏览器中输入http://localhost:8080/ 登录 用户账号/密码: user/123456 管理员账号/密码:admin/admin
number = "0";
}
int start = Integer.parseInt(number) * 12;
int over = (Integer.parseInt(number) + 1) * 12;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
}
for (int i = start; i < over; i++) {
Orders o = tempList.get(i);
ordersList.add(o);
}
String html = "";
StringBuffer buffer = new StringBuffer();
buffer.append(" 共为");
buffer.append(maxPage);
buffer.append("页 共有");
buffer.append(pageNumber);
buffer.append("条 当前为第");
buffer.append((Integer.parseInt(number) + 1));
buffer.append("页 ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("首页");
} else {
buffer.append("<a href=\"index/showOrders.action?number=0\">首页</a>");
}
buffer.append(" ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("上一页");
} else {
buffer.append("<a href=\"index/showOrders.action?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("下一页");
} else {
buffer.append("<a href=\"index/showOrders.action?number=" + (Integer.parseInt(number) + 1) + "\">下一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("尾页");
} else {
buffer.append("<a href=\"index/showOrders.action?number=" + (maxPage - 1) + "\">尾页</a>");
}
html = buffer.toString();
this.getRequest().setAttribute("html", html);
this.getRequest().setAttribute("ordersList", ordersList);
return "users/orderlist";
}
// 准备付款
@RequestMapping("prePay.action")
public String prePay(String id) {
}
// 显示全部数据
@RequestMapping("getAllPeihuo.action")
public String getAllPeihuo(String number) {
List<Peihuo> peihuoList = this.peihuoService.getAllPeihuo();
PageHelper.getPage(peihuoList, "peihuo", null, null, 10, number, this.getRequest(), null);
return "admin/listpeihuo";
}
// 显示全部数据
@RequestMapping("getNetWork.action")
public String getNetWork(String number) {
List<Peihuo> peihuoList = this.peihuoService.getAllPeihuo();
PageHelper.getPage(peihuoList, "peihuo", null, null, 10, number, this.getRequest(), null);
return "users/network";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryPeihuoByCond.action")
public String queryPeihuoByCond(String cond, String name, String number) {
Peihuo peihuo = new Peihuo();
if (cond != null) {
if ("peihuoname".equals(cond)) {
peihuo.setPeihuoname(name);
}
if ("cityid".equals(cond)) {
peihuo.setCityname(name);
}
if ("address".equals(cond)) {
peihuo.setAddress(name);
}
if ("contact".equals(cond)) {
peihuo.setContact(name);
}
if ("memo".equals(cond)) {
peihuo.setMemo(name);
}
}
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/cate", produces = "text/plain;charset=utf-8")
public class CateAction extends BaseAction {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private CateService cateService;
// 准备添加数据
@RequestMapping("createCate.action")
public String createCate() {
return "admin/addcate";
}
// 添加数据
@RequestMapping("addCate.action")
public String addCate(Cate cate) {
cate.setAddtime(VeDate.getStringDateShort());
this.cateService.insertCate(cate);
return "redirect:/cate/createCate.action";
}
// 通过主键删除数据
@RequestMapping("deleteCate.action")
public String deleteCate(String id) {
this.cateService.deleteCate(id);
return "redirect:/cate/getAllCate.action";
}
// 批量删除数据
@RequestMapping("deleteCateByIds.action")
public String deleteCateByIds() {
String[] ids = this.getRequest().getParameterValues("cateid");
for (String cateid : ids) {
this.cateService.deleteCate(cateid);
}
return "redirect:/cate/getAllCate.action";
}
// 更新数据
@RequestMapping("updateCate.action")
public String updateCate(Cate cate) {
this.cateService.updateCate(cate);
return "redirect:/cate/getAllCate.action";
}
// 显示全部数据
this.jiancaiService.updateJiancai(goods);
total += Double.parseDouble(cart.getPrice()) * Double.parseDouble(cart.getNum());
this.cartService.deleteCart(cart.getCartid());
}
Orders orders = new Orders();
orders.setAddtime(VeDate.getStringDateShort());
orders.setOrdercode(ordercode);
orders.setStatus("未付款");
orders.setTotal("" + total);
orders.setUsersid(userid);
this.ordersService.insertOrders(orders);
}
return "redirect:/index/showOrders.action";
}
// 查看订购
@RequestMapping("showOrders.action")
public String showOrders(String number) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
Orders orders = new Orders();
orders.setUsersid(userid);
List<Orders> ordersList = new ArrayList<Orders>();
List<Orders> tempList = this.ordersService.getOrdersByCond(orders);
int pageNumber = tempList.size();
int maxPage = pageNumber;
if (maxPage % 12 == 0) {
maxPage = maxPage / 12;
} else {
maxPage = maxPage / 12 + 1;
}
if (number == null) {
number = "0";
}
int start = Integer.parseInt(number) * 12;
int over = (Integer.parseInt(number) + 1) * 12;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
}
}
// 准备修改密码
@RequestMapping("prePwd.action")
public String prePwd() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
return "users/editpwd";
}
// 修改密码
@RequestMapping("editpwd.action")
public String editpwd() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
String password = this.getRequest().getParameter("password");
String repassword = this.getRequest().getParameter("repassword");
Users users = this.usersService.getUsersById(userid);
if (password.equals(users.getPassword())) {
users.setPassword(repassword);
this.usersService.updateUsers(users);
} else {
this.getSession().setAttribute("message", "旧密码错误");
return "redirect:/index/prePwd.action";
}
return "redirect:/index/prePwd.action";
}
@RequestMapping("usercenter.action")
public String usercenter() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
return "users/usercenter";
}
return "savefile";
}
}
/**
* Action 基类
*/
@Controller
public class BaseAction {
/* 日志 */
protected final Log log = LogFactory.getLog(getClass());
/* 获取基本环境 */
public Map<String, String[]> getParameters() {// 封装为Map的requestParameters
ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
return attrs.getRequest().getParameterMap();
}
public HttpServletRequest getRequest() {
ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
return attrs.getRequest();
}
public HttpSession getSession() {
HttpSession session = null;
try {
session = this.getRequest().getSession();
} catch (Exception e) {
}
return session;
}
public void setOrdersService(OrdersService ordersService) { this.ordersService = ordersService; }
}
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/article", produces = "text/plain;charset=utf-8")
public class ArticleAction extends BaseAction {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private ArticleService articleService;
// 准备添加数据
@RequestMapping("createArticle.action")
public String createArticle() {
return "admin/addarticle";
}
// 添加数据
@RequestMapping("addArticle.action")
public String addArticle(Article article) {
article.setAddtime(VeDate.getStringDateShort());
article.setHits("0");
this.articleService.insertArticle(article);
return "redirect:/article/createArticle.action";
}
// 通过主键删除数据
@RequestMapping("deleteArticle.action")
public String deleteArticle(String id) {
this.articleService.deleteArticle(id);
return "redirect:/article/getAllArticle.action";
}
// 批量删除数据
@RequestMapping("deleteArticleByIds.action")
public String deleteArticleByIds() {
String[] ids = this.getRequest().getParameterValues("articleid");
for (String articleid : ids) {
public String detail(String id) {
this.front();
Jiancai goods = this.jiancaiService.getJiancaiById(id);
goods.setHits("" + (Integer.parseInt(goods.getHits()) + 1));
this.jiancaiService.updateJiancai(goods);
this.getRequest().setAttribute("goods", goods);
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
Topic topic = new Topic();
topic.setJiancaiid(id);
List<Topic> topicList = this.topicService.getTopicByCond(topic);
this.getRequest().setAttribute("topicList", topicList);
this.getRequest().setAttribute("tnum", topicList.size());
return "users/detail";
}
@RequestMapping("addTopic.action")
public String addTopic(Topic topic) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
topic.setAddtime(VeDate.getStringDateShort());
topic.setContents(this.getRequest().getParameter("contents"));
topic.setJiancaiid(this.getRequest().getParameter("goodsid"));
topic.setNum(this.getRequest().getParameter("num"));
topic.setUsersid(userid);
this.topicService.insertTopic(topic);
return "redirect:/index/detail.action?id=" + topic.getJiancaiid();
}
}
//定义为控制器
buffer.append("上一页");
} else {
buffer.append("<a href=\"index/showOrders.action?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("下一页");
} else {
buffer.append("<a href=\"index/showOrders.action?number=" + (Integer.parseInt(number) + 1) + "\">下一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("尾页");
} else {
buffer.append("<a href=\"index/showOrders.action?number=" + (maxPage - 1) + "\">尾页</a>");
}
html = buffer.toString();
this.getRequest().setAttribute("html", html);
this.getRequest().setAttribute("ordersList", ordersList);
return "users/orderlist";
}
// 准备付款
@RequestMapping("prePay.action")
public String prePay(String id) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
this.getRequest().setAttribute("id", id);
return "users/pay";
}
// 付款
@RequestMapping("pay.action")
public String pay(String id) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
jiancai.setRecommend(name);
}
if ("thestart".equals(cond)) {
jiancai.setThestart(name);
}
if ("theend".equals(cond)) {
jiancai.setTheend(name);
}
if ("hits".equals(cond)) {
jiancai.setHits(name);
}
if ("sellnum".equals(cond)) {
jiancai.setSellnum(name);
}
if ("contents".equals(cond)) {
jiancai.setContents(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.jiancaiService.getJiancaiByLike(jiancai), "jiancai", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/queryjiancai";
}
// 按主键查询数据
@RequestMapping("getJiancaiById.action")
public String getJiancaiById(String id) {
Jiancai jiancai = this.jiancaiService.getJiancaiById(id);
this.getRequest().setAttribute("jiancai", jiancai);
List<Cate> cateList = this.cateService.getAllCate();
this.getRequest().setAttribute("cateList", cateList);
return "admin/editjiancai";
}
public JiancaiService getJiancaiService() {
return jiancaiService;
}
public void setJiancaiService(JiancaiService jiancaiService) {
this.jiancaiService = jiancaiService;
}
}
@Resource
private JiancaiService jiancaiService;
// 准备添加数据
@RequestMapping("createTopic.action")
public String createTopic() {
List<Users> usersList = this.usersService.getAllUsers();
this.getRequest().setAttribute("usersList", usersList);
List<Jiancai> jiancaiList = this.jiancaiService.getAllJiancai();
this.getRequest().setAttribute("jiancaiList", jiancaiList);
return "admin/addtopic";
}
// 添加数据
@RequestMapping("addTopic.action")
public String addTopic(Topic topic) {
this.topicService.insertTopic(topic);
return "redirect:/topic/createTopic.action";
}
// 通过主键删除数据
@RequestMapping("deleteTopic.action")
public String deleteTopic(String id) {
this.topicService.deleteTopic(id);
return "redirect:/topic/getAllTopic.action";
}
// 批量删除数据
@RequestMapping("deleteTopicByIds.action")
public String deleteTopicByIds() {
String[] ids = this.getRequest().getParameterValues("topicid");
for (String topicid : ids) {
this.topicService.deleteTopic(topicid);
}
return "redirect:/topic/getAllTopic.action";
}
// 更新数据
@RequestMapping("updateTopic.action")
public String updateTopic(Topic topic) {
this.topicService.updateTopic(topic);
private CartService cartService;
@Autowired
@Resource
private OrdersService ordersService;
@Autowired
@Resource
private DetailsService detailsService;
@Autowired
@Resource
private TopicService topicService;
// 公共方法 提供公共查询数据
private void front() {
this.getRequest().setAttribute("title", "龙城共享汽车网-力作中国最大的共享汽车网站");
List<Cate> cateList = this.cateService.getAllCate();
this.getRequest().setAttribute("cateList", cateList);
List<Jiancai> hotList = this.jiancaiService.getJiancaiByHot();
Collections.shuffle(hotList);
this.getRequest().setAttribute("hotList", hotList);
}
// 首页显示
@RequestMapping("index.action")
public String index() {
this.front();
List<Cate> cateList = this.cateService.getCateFront();
List<Cate> frontList = new ArrayList<Cate>();
for (Cate cate : cateList) {
List<Jiancai> flimList = this.jiancaiService.getJiancaiByCate(cate.getCateid());
cate.setFlimList(flimList);
frontList.add(cate);
}
this.getRequest().setAttribute("frontList", frontList);
return "users/index";
}
// 首页显示
@RequestMapping("network.action")
public String network() {
this.front();
List<Cate> cateList = this.cateService.getCateFront();
List<Cate> frontList = new ArrayList<Cate>();
for (Cate cate : cateList) {
List<Jiancai> flimList = this.jiancaiService.getJiancaiByCate(cate.getCateid());
cate.setFlimList(flimList);
frontList.add(cate);
}
this.getRequest().setAttribute("frontList", frontList);
return "users/network";
}
// 公告
@RequestMapping("article.action")
int maxPage = pageNumber;
if (maxPage % 12 == 0) {
maxPage = maxPage / 12;
} else {
maxPage = maxPage / 12 + 1;
}
if (number == null) {
number = "0";
}
int start = Integer.parseInt(number) * 12;
int over = (Integer.parseInt(number) + 1) * 12;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
}
for (int i = start; i < over; i++) {
Article x = tempList.get(i);
articleList.add(x);
}
String html = "";
StringBuffer buffer = new StringBuffer();
buffer.append(" 共为");
buffer.append(maxPage);
buffer.append("页 共有");
buffer.append(pageNumber);
buffer.append("条 当前为第");
buffer.append((Integer.parseInt(number) + 1));
buffer.append("页 ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("首页");
} else {
buffer.append("<a href=\"index/article.action?number=0\">首页</a>");
}
buffer.append(" ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("上一页");
} else {
buffer.append("<a href=\"index/article.action?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("下一页");
} else {
buffer.append("<a href=\"index/article.action?number=" + (Integer.parseInt(number) + 1) + "\">下一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
this.cateService.updateCate(cate);
return "redirect:/cate/getAllCate.action";
}
// 显示全部数据
@RequestMapping("getAllCate.action")
public String getAllCate(String number) {
List<Cate> cateList = this.cateService.getAllCate();
PageHelper.getPage(cateList, "cate", null, null, 10, number, this.getRequest(), null);
return "admin/listcate";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryCateByCond.action")
public String queryCateByCond(String cond, String name, String number) {
Cate cate = new Cate();
if (cond != null) {
if ("catename".equals(cond)) {
cate.setCatename(name);
}
if ("memo".equals(cond)) {
cate.setMemo(name);
}
if ("addtime".equals(cond)) {
cate.setAddtime(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.cateService.getCateByLike(cate), "cate", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/querycate";
}
// 按主键查询数据
@RequestMapping("getCateById.action")
public String getCateById(String id) {
jiancai.setHits(name);
}
if ("sellnum".equals(cond)) {
jiancai.setSellnum(name);
}
if ("contents".equals(cond)) {
jiancai.setContents(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.jiancaiService.getJiancaiByLike(jiancai), "jiancai", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/queryjiancai";
}
// 按主键查询数据
@RequestMapping("getJiancaiById.action")
public String getJiancaiById(String id) {
Jiancai jiancai = this.jiancaiService.getJiancaiById(id);
this.getRequest().setAttribute("jiancai", jiancai);
List<Cate> cateList = this.cateService.getAllCate();
this.getRequest().setAttribute("cateList", cateList);
return "admin/editjiancai";
}
public JiancaiService getJiancaiService() {
return jiancaiService;
}
public void setJiancaiService(JiancaiService jiancaiService) {
this.jiancaiService = jiancaiService;
}
}
return "admin/editpeihuo";
}
public PeihuoService getPeihuoService() {
return peihuoService;
}
public void setPeihuoService(PeihuoService peihuoService) {
this.peihuoService = peihuoService;
}
}
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/topic" , produces = "text/plain;charset=utf-8")
public class TopicAction extends BaseAction {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private TopicService topicService;
@Autowired
@Resource
private UsersService usersService;
@Autowired
@Resource
private JiancaiService jiancaiService;
// 准备添加数据
@RequestMapping("createTopic.action")
public String createTopic() {
List<Users> usersList = this.usersService.getAllUsers();
List<Jiancai> tempList = this.jiancaiService.getJiancaiByCond(goods);
int pageNumber = tempList.size();
int maxPage = pageNumber;
if (maxPage % 12 == 0) {
maxPage = maxPage / 12;
} else {
maxPage = maxPage / 12 + 1;
}
if (number == null) {
number = "0";
}
int start = Integer.parseInt(number) * 12;
int over = (Integer.parseInt(number) + 1) * 12;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
}
for (int i = start; i < over; i++) {
Jiancai x = tempList.get(i);
flimList.add(x);
}
String html = "";
StringBuffer buffer = new StringBuffer();
buffer.append(" 共为");
buffer.append(maxPage);
buffer.append("页 共有");
buffer.append(pageNumber);
buffer.append("条 当前为第");
buffer.append((Integer.parseInt(number) + 1));
buffer.append("页 ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("首页");
} else {
buffer.append("<a href=\"index/recommend.action?number=0\">首页</a>");
}
buffer.append(" ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("上一页");
} else {
buffer.append("<a href=\"index/recommend.action?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
}
buffer.append(" ");
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
Details details = new Details();
details.setOrdercode(id);
List<Details> detailsList = this.detailsService.getDetailsByCond(details);
this.getRequest().setAttribute("detailsList", detailsList);
return "users/orderdetail";
}
// 按分类查询
@RequestMapping("cate.action")
public String cate(String id, String number) {
this.front();
Jiancai goods = new Jiancai();
goods.setCateid(id);
List<Jiancai> flimList = new ArrayList<Jiancai>();
List<Jiancai> tempList = this.jiancaiService.getJiancaiByCond(goods);
int pageNumber = tempList.size();
int maxPage = pageNumber;
if (maxPage % 12 == 0) {
maxPage = maxPage / 12;
} else {
maxPage = maxPage / 12 + 1;
}
if (number == null) {
number = "0";
}
int start = Integer.parseInt(number) * 12;
int over = (Integer.parseInt(number) + 1) * 12;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
}
for (int i = start; i < over; i++) {
Jiancai x = tempList.get(i);
flimList.add(x);
}
String html = "";
StringBuffer buffer = new StringBuffer();
buffer.append(" 共为");
buffer.append(maxPage);
buffer.append("页 共有");