一、展示买车页面
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <script type="text/javascript" src="/js/jquery-2.1.0.js"></script> <!-- 最新版本的 Bootstrap 核心 CSS 文件 --> <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <!-- 可选的 Bootstrap 主题文件(一般不用引入)--> <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> <!--最新的 Bootstrap 核心 JavaScript 文件 --> <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> <!--js框架--> <script type="text/javascript" src="/js/angularjs.js"></script> </head> <body> <div class="container"> <div class="page-header"> <h1 align="center">汽 车 展 示 页 面</h1> </div> <form class="navbar-form navbar-left" role="search" action="selectByName" style="margin-left: 400px;"> <div class="form-group"> <input type="text" class="form-control" name="name" style="width: 250px;"> </div> <button type="submit" class="btn btn-default">品牌搜索</button> </form> <div class="row"> <#list list.list as l > <div class="col-sm-6 col-md-4"> <div class="thumbnail"> <a href="selectById?id=${l.id}"><img src="/images/${l.picture}" alt="..."></a> <div class="caption"> <p><a href="selectById?id=${l.id}" class="btn btn-default" role="button">${l.name}</a> <a href="#" class="btn btn-default glyphicon glyphicon-yen" role="button">${l.price}</a> <#-- <button href="selectById?id=${l.id}">购买</button>--> <button οnclick="window.location.href='/gar/addGarage?id=${l.id}'">购买</button> </p> </div> </div> </div> </#list> </div> <div style="margin-left: 500px"> <nav aria-label="Page navigation" "> <ul class="pagination"> <#if list.isFirstPage==true> <li class="disabled"><a href="/rest/?pageNo=${list.firstPage}&pageSize=${list.pageSize}" aria-label="Previous"> <span aria-hidden="true">«</span><#--class="active"--></a> </li> <#else > <li><a href="/rest/?pageNo=${list.prePage}&pageSize=${list.pageSize}" aria-label="Previous"> <span aria-hidden="true">«</span><#--class="active"--></a></li> </#if> <#list 1..list.pages as s> <li><a href="/rest/?pageNo=${s}&pageSize=${list.pageSize}">${s}</a></li> </#list> <#if list.isLastPage==true> <li class="disabled"><a href="/rest/?pageNo=${list.lastPage}&pageSize=${list.pageSize}" aria-label="Next"> <span aria-hidden="true">»</span> </a></li> <#else > <li><a href="/rest/?pageNo=${list.nextPage}&pageSize=${list.pageSize}" aria-label="Next"> <span aria-hidden="true">»</span> </a></li> </#if> </ul> </nav> </div> </div> </body> </html>二、汽车详情页面
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <script type="text/javascript" src="/js/jquery-2.1.0.js"></script> <!-- 最新版本的 Bootstrap 核心 CSS 文件 --> <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <!-- 可选的 Bootstrap 主题文件(一般不用引入)--> <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> <!--最新的 Bootstrap 核心 JavaScript 文件 --> <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> <!--js框架--> <script type="text/javascript" src="/js/angularjs.js"></script> </head> <body> <div class="container"> <div class="page-header"> <h2>汽 车 详 情 页 面</h2> </div> <div class="row"> <div class="col-md-4"> <img src="/js/images/${automobile.picture}" width="300" height="250" /> </div> <div class="col-md-6"> <table class="table-bordered" width="240" height="170" style="text-align: center; margin-top: 00px;"> <tr> <td width="120">汽车品牌名称</td> <td width="120">${automobile.name}</td> </tr> <tr> <td>汽车售价</td> <td>${automobile.price}</td> </tr> <tr> <td>发动机排量</td> <td>${automobile.displacement}</td> </tr> <tr> <td>变速箱</td> <td>${automobile.transmission}</td> </tr> <tr> <td>车身结构</td> <td>${automobile.structure}</td> </tr> </table> <a style="margin-top: 45px;" href="/coll/addCollection?id=${automobile.id}" class="btn btn-default btn-lg " role="button">收藏/关注</a> <a style="margin-top: 45px; margin-left: 20px;" href="/gar/addGarage?id=${automobile.id}" class="btn btn-default btn-lg " role="button">立即购买</a> </div > </div> </div> </body> </html>三、汽车页面
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <script type="text/javascript" src="/js/jquery-2.1.0.js"></script> <!-- 最新版本的 Bootstrap 核心 CSS 文件 --> <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <!-- 可选的 Bootstrap 主题文件(一般不用引入)--> <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> <!--最新的 Bootstrap 核心 JavaScript 文件 --> <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> <!--js框架--> <script type="text/javascript" src="/js/angularjs.js"></script> </head> <body> <div class="container"> <div class="page-header"> <h1 align="center">收 藏 列 表</h1> </div> <div class="row"> <#list list as l> <div class="col-sm-6 col-md-4"> <div class="thumbnail"> <img src="/js/images/${l.automobile.picture}" alt="..."> <div class="caption"> <p><a href="#" class="btn btn-default" role="button">${l.automobile.name}</a> <a href="#" class="btn btn-default" role="button">${l.automobile.price}</a> <button οnclick="window.location.href='/gar/addGarage?id=${l.automobile.id}'">购买</button> </p> <p><a style="margin-top: 45px;" href="/coll/deleteCollection?id=${l.id}" class="btn btn-default btn-lg" role="button">取消收藏</a></p> </div> </div> </div> </#list> <#if (list?size>0)> <#else > 您没有藏品快去<a href="/rest/">逛逛</a>吧 </#if> </div> </div> </body> </html>四、车库展示
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <script type="text/javascript" src="/js/jquery-2.1.0.js"></script> <!-- 最新版本的 Bootstrap 核心 CSS 文件 --> <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <!-- 可选的 Bootstrap 主题文件(一般不用引入)--> <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> <!--最新的 Bootstrap 核心 JavaScript 文件 --> <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> <!--js框架--> <script type="text/javascript" src="/js/angularjs.js"></script> </head> <body> <div class="container"> <div class="page-header"> <h1 align="center">车 库 展 示</h1> </div> <button οnclick="window.location.href='/coll/selectCollection'">我的收藏</button> <table class="table table-bordered" style=" text-align:center "> <tr> <td >图片</td> <td >品牌</td> <td >颜色</td> <td >数量</td> <td >购买日期</td> </tr> <#list list as l> <tr> <td><img src="/js/images/${l.automobile.picture}" width="100" height="80" </td> <td>${l.automobile.name}</td> <td>${l.automobile.colour}</td> <td>${l.count}</td> <td>${l.getPurchase()?date}</td> </tr> </#list> </table> <#if (list?size>0)> <#else > 您没有爱车快去<a href="/rest/">逛逛</a>吧 </#if> <a style="margin-top: 45px;" href="/rest/"class="btn btn-default btn-lg " role="button">去买车</a> <a style="margin-top: 45px; margin-left: 20px;" href="#" class="btn btn-default btn-lg " role="button">去卖车</a> </div> </body> </html>五、汽车控制类
package com.bw.controller; import com.bw.pojo.Automobile; import com.bw.service.AutomobileService; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.ValueOperations; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.ModelAndView; import javax.annotation.Resource; import java.util.List; @RestController @RequestMapping("rest") public class AutomobileController { @Autowired private AutomobileService automobileService; @RequestMapping("/") public ModelAndView selectAll(ModelAndView modelAndView, String pageNo, String pageSize) { Integer num = 1; Integer size = 6; if (pageNo != null && !"".equals(pageNo)) { num = Integer.parseInt(pageNo); } if (pageSize != null && !"".equals(pageSize)) { size = Integer.parseInt(pageSize); } //开始分页 PageHelper.startPage(num, size); List<Automobile> automobiles = automobileService.selectAllAutomobile(); System.out.print(automobiles); PageInfo<Automobile> pageInfo = new PageInfo<Automobile>(automobiles); modelAndView.addObject("list", pageInfo); modelAndView.setViewName("carsList"); return modelAndView; } @RequestMapping("/selectById") public ModelAndView selectById(ModelAndView modelAndView, Integer id) { Automobile automobile = automobileService.selectById(id); modelAndView.addObject("automobile", automobile); modelAndView.setViewName("carsDetail"); return modelAndView; } @RequestMapping("/selectByName") public ModelAndView selectByName(ModelAndView modelAndView, String name, String pageNo, String pageSize) { Integer num = 1; Integer size = 6; if (pageNo != null && !"".equals(pageNo)) { num = Integer.parseInt(pageNo); } if (pageSize != null && !"".equals(pageSize)) { size = Integer.parseInt(pageSize); } //开始分页 PageHelper.startPage(num, size); List<Automobile> automobiles = automobileService.selectByName(name); PageInfo<Automobile> pageInfo = new PageInfo<Automobile>(automobiles); modelAndView.addObject("list", pageInfo); modelAndView.setViewName("carsList"); return modelAndView; } }六、收藏控制类
package com.bw.controller; import com.bw.pojo.CollectionBean; import com.bw.service.CollectionService; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import javax.annotation.Resource; import java.util.List; @Controller @RequestMapping("coll") public class CollectionController { @Resource private CollectionService collectionService; @RequestMapping("addCollection") public String addCollection(Integer id){ collectionService.addConllection(id); return "redirect:/coll/selectCollection"; } @RequestMapping("selectCollection") public ModelAndView selectCollection(ModelAndView modelAndView){ List<CollectionBean> collectionsa = collectionService.selectCollection(); modelAndView.addObject("list",collectionsa); modelAndView.setViewName("collectionBean"); return modelAndView; } @RequestMapping("deleteCollection") public String deleteCollection(Integer id){ collectionService.deleteCollection(id); return "redirect:/coll/selectCollection"; } }七、车库控制类
package com.bw.controller; import com.bw.pojo.Automobile; import com.bw.pojo.Garage; import com.bw.service.AutomobileService; import com.bw.service.GarageService; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import javax.annotation.Resource; import java.util.Date; import java.util.List; @Controller @RequestMapping("gar") public class GarageController { @Resource private GarageService garageService; @Resource private AutomobileService automobileService; @RequestMapping("addGarage") public String addGarage(Integer id,Garage garage){ Garage garage1 = garageService.selectByIdGarage(id); if(garage1==null){ Automobile automobile = automobileService.selectById(id); garage.setCount(1); garage.setAutomobile(automobile); garage.setPurchase(new Date()); garageService.addGarage(garage); }else{ Integer count = garage1.getCount()+1; garage1.setCount(count); garage1.setPurchase(new Date()); // garageService.addGarage(garage); garageService.updateGarage(garage1); } return "redirect:/gar/selectGarage"; } @RequestMapping("selectGarage") public ModelAndView selectGarage(ModelAndView modelAndView){ List<Automobile> automobiles = garageService.selectGarage(); System.out.print(automobiles); modelAndView.addObject("list",automobiles); modelAndView.setViewName("home"); return modelAndView; } }