• 【Spring Boot+Thymeleaf+MyBatis+mysql】实现电子商务平台实战(附源码)持续更新~~


    源码请点赞关注收藏后评论区留言和私信博主

    开发环境:Web服务器使用Servlet容器,数据库采用mysql,集成开发环境为Spring Tool Suite(STS)

    一、系统设计

    电子商务平台分为两个子系统 一个是后台管理系统 一个是电子商务系统,下面分别讲解着两个子系统的功能需要与模块划分

    系统功能需求

    1:后台管理子系统

    要求管理员登录成功后,才能对商品进行管理,包括添加商品,查询商品,修改商品以及删除商品,除商品管理外,管理员还需要对商品类型,注册用户以及用户的订单等进行管理

    2:电子商务子系统

    (1):非注册用户

    具有浏览首页,查看商品详情以及搜索商品的功能

    (2):注册用户

    还可以购买商品,查看购物车,收藏商品,查看订单等等

    系统模块划分

    1:后台管理子系统

    模块划分如下

     2:电子商务子系统

    模块划分如下

     二、数据库设计

    系统采用加载纯Java数据库驱动程序的方式连接MYSQL数据库,创建数据库shop并创建8张系统表 数据库E-R图如下

    建表的sql语句此处省略 需要请点赞关注收藏后私信博主

     部分sql语句如下

    1. /*
    2. Navicat MySQL Data Transfer
    3. Source Server : testSpringMVC
    4. Source Server Version : 50519
    5. Source Host : localhost:3306
    6. Source Database : shop
    7. Target Server Type : MYSQL
    8. Target Server Version : 50519
    9. File Encoding : 65001
    10. Date: 2019-10-08 07:41:20
    11. */
    12. SET FOREIGN_KEY_CHECKS=0;
    13. -- ----------------------------
    14. -- Table structure for `ausertable`
    15. -- ----------------------------
    16. DROP TABLE IF EXISTS `ausertable`;
    17. CREATE TABLE `ausertable` (
    18. `aname` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
    19. `apwd` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
    20. PRIMARY KEY (`aname`)
    21. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
    22. -- ----------------------------
    23. -- Records of ausertable
    24. -- ----------------------------
    25. INSERT INTO ausertable VALUES ('admin', 'admin');
    26. -- ----------------------------
    27. -- Table structure for `busertable`
    28. -- ----------------------------
    29. DROP TABLE IF EXISTS `busertable`;
    30. CREATE TABLE `busertable` (
    31. `id` int(11) NOT NULL AUTO_INCREMENT,
    32. `bemail` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
    33. `bpwd` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
    34. PRIMARY KEY (`id`)
    35. ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
    36. -- ----------------------------
    37. -- Records of busertable
    38. -- ----------------------------
    39. INSERT INTO busertable VALUES ('6', 'chenhengdl@126.com', '78f8a7ae700c91db09facb05a675432b');
    40. -- ----------------------------
    41. -- Table structure for `carttable`
    42. -- ----------------------------
    43. 还没弄
    44. DROP TABLE IF EXISTS `carttable`;
    45. CREATE TABLE `carttable` (
    46. `id` int(11) NOT NULL AUTO_INCREMENT,
    47. `busertable_id` int(11) NOT NULL,
    48. `goodstable_id` int(11) NOT NULL,
    49. `shoppingnum` int(11) NOT NULL,
    50. PRIMARY KEY (`id`),
    51. KEY `bid` (`busertable_id`),
    52. KEY `gno` (`goodstable_id`),
    53. CONSTRAINT `bid` FOREIGN KEY (`busertable_id`) REFERENCES `busertable` (`id`),
    54. CONSTRAINT `gno` FOREIGN KEY (`goodstable_id`) REFERENCES `goodstable` (`id`)
    55. ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
    56. -- ----------------------------
    57. -- Records of carttable
    58. -- ----------------------------
    59. -- ----------------------------
    60. -- Table structure for `focustable`
    61. -- ----------------------------
    62. 还没弄
    63. DROP TABLE IF EXISTS `focustable`;
    64. CREATE TABLE `focustable` (
    65. `id` int(11) NOT NULL AUTO_INCREMENT,
    66. `goodstable_id` int(11) NOT NULL,
    67. `busertable_id` int(11) NOT NULL,
    68. `focustime` datetime DEFAULT NULL,
    69. PRIMARY KEY (`id`),
    70. KEY `gno1` (`goodstable_id`),
    71. KEY `bid1` (`busertable_id`),
    72. CONSTRAINT `bid1` FOREIGN KEY (`busertable_id`) REFERENCES `busertable` (`id`),
    73. CONSTRAINT `gno1` FOREIGN KEY (`goodstable_id`) REFERENCES `goodstable` (`id`)
    74. ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
    75. -- ----------------------------
    76. -- Records of focustable
    77. -- ----------------------------
    78. INSERT INTO focustable VALUES ('5', '29', '6', '2019-10-05 14:55:51');
    79. -- ----------------------------
    80. -- Table structure for `goodstable`
    81. -- ----------------------------
    82. 还没弄
    83. DROP TABLE IF EXISTS `goodstable`;
    84. CREATE TABLE `goodstable` (
    85. `id` int(11) NOT NULL AUTO_INCREMENT,
    86. `gname` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
    87. `goprice` double DEFAULT NULL,
    88. `grprice` double DEFAULT NULL,
    89. `gstore` int(11) DEFAULT NULL,
    90. `gpicture` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
    91. `isRecommend` tinyint(2) DEFAULT NULL,
    92. `isAdvertisement` tinyint(2) DEFAULT NULL,
    93. `goodstype_id` int(11) DEFAULT NULL,
    94. PRIMARY KEY (`id`),
    95. KEY `typeid` (`goodstype_id`),
    96. CONSTRAINT `typeid` FOREIGN KEY (`goodstype_id`) REFERENCES `goodstype` (`id`)
    97. ) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
    98. -- ----------------------------
    99. -- Records of goodstable
    100. -- ----------------------------
    101. INSERT INTO goodstable VALUES ('26', '广告商品4', '90', '80', '1000', '201910274135059473.jpg', '0', '1', '2');
    102. INSERT INTO goodstable VALUES ('27', '广告商品5', '80', '30', '122', '201910274135126352.jpg', '0', '1', '3');
    103. INSERT INTO goodstable VALUES ('28', '抱枕11号', '100', '20', '200', '201910274135150096.jpg', '1', '0', '14');
    104. INSERT INTO goodstable VALUES ('29', '抱枕22号', '300', '200', '180', '201910274135212497.jpg', '1', '0', '15');
    105. INSERT INTO goodstable VALUES ('32', '抱枕99', '80', '70', '80', '201910280135330014.jpg', '1', '0', '14');
    106. DROP TABLE IF EXISTS `orderdetail`;
    107. CREATE TABLE `orderdetail` (
    108. `id` int(11) NOT NULL AUTO_INCREMENT,
    109. `orderbasetable_id` int(11) NOT NULL,
    110. `goodstable_id` int(11) NOT NULL,
    111. `shoppingnum` int(11) NOT NULL,
    112. PRIMARY KEY (`id`),
    113. KEY `odsn` (`orderbasetable_id`),
    114. KEY `gno3` (`goodstable_id`),
    115. CONSTRAINT `gno3` FOREIGN KEY (`goodstable_id`) REFERENCES `goodstable` (`id`),
    116. CONSTRAINT `odsn` FOREIGN KEY (`orderbasetable_id`) REFERENCES `orderbasetable` (`id`)
    117. ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
    118. -- ----------------------------
    119. -- Records of orderdetail
    120. -- ----------------------------
    121. INSERT INTO orderdetail VALUES ('5', '3', '29', '20');
    122. INSERT INTO orderdetail VALUES ('6', '4', '33', '20');

    建表后效果如下

     

     

     

     三、系统管理

    1:添加相关依赖

    在pom.xml文件中添加如下代码

    1. <!-- 添加MySQL依赖 -->
    2. <dependency>
    3. <groupId>mysql</groupId>
    4. <artifactId>mysql-connector-java</artifactId>
    5. <version>5.1.45</version>
    6. <!-- MySQL8.x时,请使用8.x的连接器 -->
    7. </dependency>
    8. <!-- MyBatis-Spring,Spring Boot应用整合MyBatis框架的核心依赖配置 -->
    9. <dependency>
    10. <groupId>org.mybatis.spring.boot</groupId>
    11. <artifactId>mybatis-spring-boot-starter</artifactId>
    12. <version>2.1.0</version>
    13. </dependency>
    14. <dependency>
    15. <groupId>commons-fileupload</groupId>
    16. <artifactId>commons-fileupload</artifactId>
    17. <!-- 由于commons-fileupload组件不属于Spring Boot,所以需要加上版本 -->
    18. <version>1.3.3</version>
    19. </dependency>

    应用的目录结构如下

     

     

     

     

     在配置文件application.properties中添加如下代码

    1. server.servlet.context-path=/eBusiness
    2. ###
    3. ##数据源信息配置
    4. ###
    5. #数据库地址
    6. spring.datasource.url=jdbc:mysql://localhost:3306/shop?characterEncoding=utf8
    7. #数据库MySQL为8.x时,url为jdbc:mysql://localhost:3306/springbootjpa?useSSL=false&serverTimezone=Asia/Beijing&characterEncoding=utf-8
    8. #数据库用户名
    9. spring.datasource.username=root
    10. #数据库密码
    11. spring.datasource.password=root
    12. #数据库驱动
    13. spring.datasource.driver-class-name=com.mysql.jdbc.Driver
    14. #设置包别名(在Mapper映射文件中直接使用实体类名)
    15. mybatis.type-aliases-package=com.ch.ebusiness.entity
    16. #告诉系统在哪里去找mapper.xml文件(映射文件)
    17. mybatis.mapperLocations=classpath:mappers/*.xml
    18. #在控制台输出SQL语句日志
    19. logging.level.com.ch.ebusiness.repository=debug
    20. #关闭Thymeleaf模板引擎缓存(使页面热部署),默认是开启的
    21. spring.thymeleaf.cache=false
    22. #上传文件时,默认单个上传文件大小是1MB,max-file-size设置单个上传文件大小
    23. spring.servlet.multipart.max-file-size=50MB
    24. #默认总文件大小是10MB,max-request-size设置总上传文件大小
    25. spring.servlet.multipart.max-request-size=500MB

    四、组件设计

    包括 管理员登录权限验证 前台用户登录权限验证 验证码 统一异常处理 工具类等等

    五、后台管理子系统的实现

    管理员登录界面如下

    代码如下

    1. <!DOCTYPE html>
    2. <html xmlns:th="http://www.thymeleaf.org">
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>管理员登录页面</title>
    6. <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}" />
    7. <body>
    8. <div class="container">
    9. <div class="bg-primary" style="width:70%; height: 60px;padding-top: 1px;">
    10. <h3 align="center">管理员登录</h3>
    11. </div>
    12. <br>
    13. <br>
    14. <form th:action="@{/admin/login}" name="myform" method="post" th:object="${aUser}" class="form-horizontal" role="form" >
    15. <div class="form-group has-success">
    16. <label class="col-sm-2 col-md-2 control-label">用户名</label>
    17. <div class="col-sm-4 col-md-4">
    18. <input type="text" class="form-control"
    19. placeholder="请输入管理员名"
    20. th:field="*{aname}"/>
    21. <span th:errors="*{aname}"></span>
    22. </div>
    23. </div>
    24. <div class="form-group has-success">
    25. <label class="col-sm-2 col-md-2 control-label">密码</label>
    26. <div class="col-sm-4 col-md-4">
    27. <input type="password" class="form-control"
    28. placeholder="请输入您的密码" th:field="*{apwd}"/>
    29. <span th:errors="*{apwd}"></span>
    30. </div>
    31. </div>
    32. <div class="form-group">
    33. <div class="col-sm-offset-2 col-sm-10">
    34. <button type="submit"class="btn btn-success" >登录</button>
    35. <button type="reset" class="btn btn-primary" >重置</button>
    36. </div>
    37. </div>
    38. <div class="form-group">
    39. <div class="col-sm-offset-2 col-sm-10">
    40. <font size="6" color="red">
    41. <span th:text="${errorMessage }"></span>
    42. </font>
    43. </div>
    44. </div>
    45. </form>
    46. </div>
    47. </body>
    48. </html>

     类型管理界面如下 包括增删改查

    添加类型页面代码如下

    1. <!DOCTYPE html>
    2. <html xmlns:th="http://www.thymeleaf.org">
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>商品类型添加页面</title>
    6. <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}" />
    7. <body>
    8. <div th:include="admin/header"></div>
    9. <br><br><br>
    10. <div class="container">
    11. <div class="bg-primary" style="width:70%; height: 60px;padding-top: 0.5px;">
    12. <h3 align="center">添加类型</h3>
    13. </div><br>
    14. <form th:action="@{/type/addType}" name="myform" method="post" th:object="${goodsType}" class="form-horizontal" role="form" >
    15. <div class="form-group has-success">
    16. <label class="col-sm-2 col-md-2 control-label">类型名称</label>
    17. <div class="col-sm-4 col-md-4">
    18. <input type="text" class="form-control"
    19. placeholder="请输入类型名"
    20. th:field="*{typename}"/>
    21. </div>
    22. </div>
    23. <div class="form-group">
    24. <div class="col-sm-offset-2 col-sm-10">
    25. <button type="submit"class="btn btn-success" >添加</button>
    26. <button type="reset" class="btn btn-primary" >重置</button>
    27. </div>
    28. </div>
    29. </form>
    30. </div>
    31. </body>
    32. </html>

     添加商品效果如下

     代码如下

    1. <!DOCTYPE html>
    2. <html xmlns:th="http://www.thymeleaf.org">
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>商品类型添加页面</title>
    6. <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}" />
    7. <body>
    8. <div th:include="admin/header"></div>
    9. <br><br><br>
    10. <div class="container">
    11. <div class="bg-primary" style="width:70%; height: 60px;padding-top: 0.5px;">
    12. <h3 align="center">添加商品</h3>
    13. </div><br>
    14. <form th:action="@{/goods/addGoods?act=add}"
    15. name="myform" method="post"
    16. th:object="${goods}"
    17. class="form-horizontal"
    18. enctype="multipart/form-data" >
    19. <div class="form-group has-success">
    20. <label class="col-sm-2 col-md-2 control-label">商品名称</label>
    21. <div class="col-sm-4 col-md-4">
    22. <input type="text" class="form-control"
    23. placeholder="请输入商品名"
    24. th:field="*{gname}"/>
    25. </div>
    26. </div>
    27. <div class="form-group has-success">
    28. <label class="col-sm-2 col-md-2 control-label">商品原价</label>
    29. <div class="col-sm-4 col-md-4">
    30. <input type="number" class="form-control"
    31. placeholder="请输入商品原价"
    32. th:field="*{goprice}"/>
    33. </div>
    34. </div>
    35. <div class="form-group has-success">
    36. <label class="col-sm-2 col-md-2 control-label">商品折扣价</label>
    37. <div class="col-sm-4 col-md-4">
    38. <input type="number" class="form-control"
    39. placeholder="请输入商品折扣价"
    40. th:field="*{grprice}"/>
    41. </div>
    42. </div>
    43. <div class="form-group has-success">
    44. <label class="col-sm-2 col-md-2 control-label">商品库存</label>
    45. <div class="col-sm-4 col-md-4">
    46. <input type="number" class="form-control"
    47. placeholder="请输入商品库存"
    48. th:field="*{gstore}"/>
    49. </div>
    50. </div>
    51. <div class="form-group has-success">
    52. <label class="col-sm-2 col-md-2 control-label">商品图片</label>
    53. <div class="col-sm-4 col-md-4">
    54. <input type="file" placeholder="请选择商品图片" class="form-control" name="fileName"/>
    55. </div>
    56. </div>
    57. <div class="form-group has-success">
    58. <label class="col-sm-2 col-md-2 control-label">是否推荐</label>
    59. <div class="col-sm-4 col-md-4 radio">
    60. <label>
    61. <input type="radio" th:field="*{isRecommend}" value="1">
    62. </label>
    63. <label>
    64. <input type="radio" th:field="*{isRecommend}" value="0">
    65. </label>
    66. </div>
    67. </div>
    68. <div class="form-group has-success">
    69. <label class="col-sm-2 col-md-2 control-label">是否广告</label>
    70. <div class="col-sm-4 col-md-4 radio">
    71. <label>
    72. <input type="radio" th:field="*{isAdvertisement}" value="1">
    73. </label>
    74. <label>
    75. <input type="radio" th:field="*{isAdvertisement}"s value="0">
    76. </label>
    77. </div>
    78. </div>
    79. <div class="form-group has-success">
    80. <label class="col-sm-2 col-md-2 control-label">商品类型</label>
    81. <div class="col-sm-4 col-md-4">
    82. <select class="form-control" th:field="*{goodstype_id}">
    83. <option th:each="gty:${goodsType}" th:value="${gty.id}" th:text="${gty.typename}">
    84. </select>
    85. </div>
    86. </div>
    87. <div class="form-group">
    88. <div class="col-sm-offset-2 col-sm-10">
    89. <button type="submit"class="btn btn-success" >添加</button>
    90. <button type="reset" class="btn btn-primary" >重置</button>
    91. </div>
    92. </div>
    93. </form>
    94. </div>
    95. </body>
    96. </html>

    其余的删除修改页面此处省略 有需要者点赞关注收藏后评论区留言或私信博主

    六、前台商务子系统的实现

    导航页效果如下 点击即可跳转到其他页面

     代码如下

    1. html>
    2. <html xmlns:th="http://www.thymeleaf.org">
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>导航页title>
    6. <base th:href="@{/}">
    7. <link href="css/bootstrap.min.css" rel="stylesheet">
    8. <script src="js/jquery.min.js">script>
    9. <script src="js/bootstrap.min.js">script>
    10. <style type="text/css">
    11. .carousel{
    12. height: 200px;
    13. background-color: #000;
    14. }
    15. .carousel .item{
    16. height: 200px;
    17. background-color: #000;
    18. }
    19. .carousel img{
    20. width: 100%;
    21. }
    22. style>
    23. head>
    24. <body>
    25. <div class="container-fruid">
    26. <div class="navbar navbar-default navbar-fixed-top" role="navigation"
    27. style="padding-left: 30px;">
    28. <div class="navbar-header">
    29. <span class="navbar-brand">欢迎光临eBusinessspan>
    30. div>
    31. <ul class="nav navbar-nav">
    32. <li><a th:href="@{user/toRegister}">注册a>li>
    33. <li>
    34. <a th:href="(${session.bUser} == null)?'user/toLogin':'#'" >
    35. <span th:if="${session.bUser} == null" >
    36. 登录
    37. span>
    38. <span th:if="${session.bUser} != null" >
    39. 欢迎<span th:text="${session.bUser.bemail}" >span>
    40. span>
    41. a>
    42. li>
    43. <li><a th:href="@{admin/toLogin}">后台a>li>
    44. ul>
    45. <ul class="nav navbar-nav navbar-right" style="padding-right: 30px;">
    46. <li><a href="cart/userInfo">个人信息a>li>
    47. <li><a href="cart/selectCart">我的购物车a>li>
    48. <li><a href="cart/myFocus">我的收藏a>li>
    49. <li><a href="cart/myOder">我的订单a>li>
    50. <li class="dropdown"><a href="##" data-toggle="dropdown"
    51. class="dropdown-toggle">关于我们<span class="caret">span>a>
    52. <ul class="dropdown-menu">
    53. <li><a href="##">联系我们a>li>
    54. <li><a href="##">投诉建议a>li>
    55. ul>
    56. li>
    57. ul>
    58. div>
    59. <div id="carousel-example-generic" class="carousel slide"
    60. data-ride="carousel" style="margin-top: 20px;">
    61. <ol class="carousel-indicators">
    62. <li data-target="#carousel-example-generic"
    63. th:each="advertise,adstat:${advertisementGoods}"
    64. th:data-slide-to="${adstat.index}"
    65. th:class="(${adstat.index}==0)? 'active' : ''">li>
    66. ol>
    67. <div class="carousel-inner" role="listbox">
    68. <div th:each="advertise,adstat:${advertisementGoods}" th:class="(${adstat.index}==0)? 'item active' : 'item'">
    69. <img th:src="'images/' + ${advertise.gpicture}" th:alt="${adstat.index + 1}">
    70. <div class="carousel-caption"><span th:text="${advertise.gname}">span>div>
    71. div>
    72. div>
    73. <a class="left carousel-control" href="#carousel-example-generic"
    74. role="button" data-slide="prev"> <span
    75. class="glyphicon glyphicon-chevron-left" aria-hidden="true">span>
    76. <span class="sr-only">Previousspan>
    77. a> <a class="right carousel-control" href="#carousel-example-generic"
    78. role="button" data-slide="next"> <span
    79. class="glyphicon glyphicon-chevron-right" aria-hidden="true">span>
    80. <span class="sr-only">Nextspan>
    81. a>
    82. div>
    83. <div class="navbar navbar-default " role="navigation">
    84. <ul class="nav navbar-nav" style="padding-left: 50px;">
    85. <li><a th:href="@{/}">首页a>li>
    86. <li th:each="gty:${goodsType}"><a th:href="'?tid=' + ${gty.id}"><span th:text="${gty.typename}">span>a>li>
    87. ul>
    88. <form action="search" class="navbar-form navbar-right"
    89. style="padding-right: 50px;">
    90. <div class="form-group">
    91. <input type="text" class="form-control" name="mykey" placeholder="请输入关键词" />
    92. div>
    93. <button type="submit" class="btn btn-default">搜索button>
    94. form>
    95. div>
    96. div>
    97. body>
    98. html>

    商品详情页面如下

     代码如下

    1. html>
    2. <html xmlns:th="http://www.thymeleaf.org">
    3. <head>
    4. <base th:href="@{/}">
    5. <meta charset="UTF-8">
    6. <title>商品页面title>
    7. <link rel="stylesheet" href="css/bootstrap.min.css" />
    8. <script src="js/jquery.min.js">script>
    9. <script type="text/javascript" th:inline="javascript">
    10. function focus(){
    11. $.ajax(
    12. {
    13. //请求路径,要注意的是url和th:inline="javascript"
    14. url : [[@{/cart/focus}]],
    15. //请求类型
    16. type : "post",
    17. contentType : "application/json",
    18. //data表示发送的数据
    19. data : JSON.stringify({
    20. id : $("#gid").val()
    21. }),
    22. //成功响应的结果
    23. success : function(obj){//obj响应数据
    24. if(obj == "no"){
    25. alert("您已收藏该商品!");
    26. }else if(obj == "ok"){
    27. alert("成功收藏该商品");
    28. }else{
    29. alert("您没有登录,请登录!");
    30. }
    31. },
    32. error : function() {
    33. alert("处理异常!");
    34. }
    35. }
    36. );
    37. }
    38. function putCart(){
    39. if(!(/(^[1-9]\d*$)/.test($("#buyNumber").val()))){
    40. alert("购买量请输入正整数!");
    41. $("#buyNumber").focus();
    42. return;
    43. }
    44. if(parseInt($("#buyNumber").val()) > parseInt($("#gstore").text())){
    45. alert("购买量超出库存!");
    46. $("#buyNumber").focus();
    47. return;
    48. }
    49. //获取路径
    50. var pathName=window.document.location.pathname;
    51. //截取,得到项目名称
    52. var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
    53. window.location.href = projectName + "/cart/putCart?id=" + $("#gid").val() + "&buyNumber=" + $("#buyNumber").val();
    54. }
    55. script>
    56. head>
    57. <body>
    58. <div th:include="user/header">div>
    59. <div class="container">
    60. <div class="row">
    61. <div class="col-xs-6 col-md-3">
    62. <img
    63. th:src="'images/' + ${goods.gpicture}"
    64. style="height: 220px; width: 280px; display: block;">
    65. div>
    66. <div class="col-xs-6 col-md-3">
    67. <p>商品名:<span th:text="${goods.gname}">span>p>
    68. <p>
    69. 商品折扣价:<span style="color: red;">¥
    70. <span th:text="${goods.grprice}">span>
    71. span>
    72. p>
    73. <p>
    74. 商品原价:
    75. <span class="text-dark" style="text-decoration: line-through;"> ¥
    76. <span th:text="${goods.goprice}">span>
    77. span>
    78. p>
    79. <p>
    80. 商品类型:<span th:text="${goods.typename}">span>
    81. p>
    82. <p>
    83. 库存:<span id="gstore" th:text="${goods.gstore}">span>
    84. p>
    85. <p>
    86. <input type="text" size="12" class="form-control" placeholder="请输入购买量" id="buyNumber" name="buyNumber"/>
    87. <input type="hidden" name="gid" id="gid" th:value="${goods.id}"/>
    88. p>
    89. <p>
    90. <a href="javascript:focus()" class="btn btn-primary"
    91. style="font-size: 10px;">加入收藏a>
    92. <a href="javascript:putCart()" class="btn btn-success"
    93. style="font-size: 10px;">加入购物车a>
    94. p>
    95. div>
    96. div>
    97. div>
    98. body>
    99. html>

    测试效果如下

     

    如果账号密码不对则弹出错误窗口

     

     

     

    还有用户注册 登录页面 购物车 下单页面 个人信息 我的收藏页面等等此处省略

    需要源码请点赞关注收藏后评论区留言或 私信博主即可

  • 相关阅读:
    时序数据库选型
    每日一练Day05:寻找多数元素
    xdebug3开启profile和trace
    AWS SSA-C003 #21
    配置HBase和zookeeper
    Wireshark原理介绍
    JAVA中的基本数据类型
    Spring框架系列(11) - Spring AOP实现原理详解之Cglib代理实现
    CentOS 7 上安装 MySQL 8.0详细步骤
    【从入门到起飞】IO高级流(1)(缓冲流,转换流,序列化流,反序列化流)
  • 原文地址:https://blog.csdn.net/jiebaoshayebuhui/article/details/127609482