├── .gitattributes ├── .gitignore ├── .idea ├── .gitignore ├── artifacts │ ├── book_war.xml │ └── book_war_exploded.xml ├── dataSources.xml ├── encodings.xml ├── misc.xml └── uiDesigner.xml ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── LICENSE ├── README.md ├── bookshop.sql ├── mvnw ├── mvnw.cmd ├── pom.xml └── src ├── druid.properties ├── main ├── java │ └── com │ │ ├── bookshop │ │ ├── dao │ │ │ ├── BookDao.java │ │ │ ├── CartDao.java │ │ │ ├── CartItemDao.java │ │ │ ├── OrderDao.java │ │ │ ├── UserDao.java │ │ │ └── impl │ │ │ │ ├── BasicDAO.java │ │ │ │ ├── BookDaoImpl.java │ │ │ │ ├── CartDaoImpl.java │ │ │ │ ├── CartDaoItemImpl.java │ │ │ │ ├── OrderDaoImpl.java │ │ │ │ └── UserDaoImpl.java │ │ ├── filter │ │ │ ├── ManagerFilter.java │ │ │ └── TransactionFilter.java │ │ ├── pojo │ │ │ ├── Book.java │ │ │ ├── Cart.java │ │ │ ├── CartItem.java │ │ │ ├── Order.java │ │ │ ├── Page.java │ │ │ └── User.java │ │ ├── service │ │ │ ├── BookService.java │ │ │ ├── CartItemService.java │ │ │ ├── CartService.java │ │ │ ├── OrderService.java │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ │ ├── BookSerbviceimpl.java │ │ │ │ ├── CartItemSericeimpl.java │ │ │ │ ├── CartServiceImpl.java │ │ │ │ ├── OrderServiceImpl.java │ │ │ │ └── UserServiceImpl.java │ │ ├── utils │ │ │ ├── JDBCUtilsByDruid.java │ │ │ └── WebUtils.java │ │ └── web │ │ │ ├── BaseServlet.java │ │ │ ├── BookServlet.java │ │ │ ├── CartServlet.java │ │ │ ├── ClientBookServlet.java │ │ │ ├── OrderServlet.java │ │ │ └── UserServlet.java │ │ └── example │ │ └── book │ │ └── HelloServlet.java ├── resources │ └── jdbc.properties └── webapp │ ├── WEB-INF │ ├── lib │ │ ├── commons-beanutils-1.8.0.jar │ │ ├── commons-dbutils-1.3.jar │ │ ├── commons-logging-1.1.1.jar │ │ ├── druid-1.1.10.jar │ │ ├── hamcrest-core-1.3.jar │ │ ├── junit-4.12.jar │ │ ├── kaptcha-2.3.2.jar │ │ ├── mysql-connector-java-5.1.37-bin.jar │ │ ├── taglibs-standard-impl-1.2.1.jar │ │ └── taglibs-standard-spec-1.2.1.jar │ └── web.xml │ ├── index.jsp │ ├── pages │ ├── cart │ │ ├── cart.jsp │ │ └── checkout.jsp │ ├── client │ │ └── index.jsp │ ├── common │ │ ├── footer.jsp │ │ ├── head.jsp │ │ ├── login_success_menu.jsp │ │ ├── manager_menu.jsp │ │ └── page_nav.jsp │ ├── error │ │ ├── error404.jsp │ │ └── error500.jsp │ ├── manager │ │ ├── book_edit.jsp │ │ ├── book_manager.jsp │ │ ├── manager.jsp │ │ └── order.jsp │ └── user │ │ ├── login.jsp │ │ ├── login_success.jsp │ │ ├── regist.jsp │ │ └── regist_success.jsp │ └── static │ ├── css │ └── style.css │ ├── img │ ├── 1.gif │ ├── ajax.jpg │ ├── default.jpg │ ├── flash1.jpg │ ├── java1.jpg │ ├── java10.jpg │ ├── java11.jpg │ ├── java2.jpg │ ├── java3.jpg │ ├── java4.jpg │ ├── java5.jpg │ ├── java6.jpg │ ├── java7.jpg │ ├── java8.jpg │ ├── java9.jpg │ ├── javascript.jpg │ ├── javascript2.jpg │ ├── javaweb1.jpg │ ├── javaweb2.jpg │ ├── javaweb3.jpg │ ├── javaweb4.jpg │ ├── junit.jpg │ ├── log.jpg │ ├── logo.gif │ ├── node.jpg │ ├── osgi1.jpg │ ├── osgi2.jpg │ ├── pwd-icons-new.png │ ├── spring1.jpg │ ├── spring2.jpg │ └── tomcat.jpg │ └── script │ └── jquery-1.7.2.js └── test └── java └── com └── bookshop └── dao └── impl ├── BookDaoImplTest.java ├── CartDaoImplTest.java ├── CartDaoItemImplTest.java ├── OrderDaoImplTest.java └── UserDaoImplTest.java /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### IntelliJ IDEA ### 7 | .idea/modules.xml 8 | .idea/jarRepositories.xml 9 | .idea/compiler.xml 10 | .idea/libraries/ 11 | *.iws 12 | *.iml 13 | *.ipr 14 | 15 | ### Eclipse ### 16 | .apt_generated 17 | .classpath 18 | .factorypath 19 | .project 20 | .settings 21 | .springBeans 22 | .sts4-cache 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | !**/src/main/**/build/ 32 | !**/src/test/**/build/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | 37 | ### Mac OS ### 38 | .DS_Store -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # 默认忽略的文件 2 | /shelf/ 3 | /workspace.xml 4 | # 基于编辑器的 HTTP 客户端请求 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/artifacts/book_war.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/target 4 | 5 | 6 | book 7 | war 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/artifacts/book_war_exploded.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/target/book-1.0-SNAPSHOT 4 | 5 | 6 | true 7 | book 8 | war 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /.idea/dataSources.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | mysql.8 6 | true 7 | com.mysql.cj.jdbc.Driver 8 | jdbc:mysql://localhost:3306 9 | $ProjectFileDir$ 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 heweijiqn 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bookshop 2 | ## javaweb 3 | 是采用jsp+Servlet+mysql+java 4 | 有用户模块 图书管理模块 商品展示模块 订单模块 订单管理模块 购物车模块 5 | 采用mvc三层架构 6 | ## pull代码请先star~~~ 7 | -------------------------------------------------------------------------------- /bookshop.sql: -------------------------------------------------------------------------------- 1 | /* 2 | SQLyog Professional v12.14 (64 bit) 3 | MySQL - 5.7.19 : Database - book 4 | ********************************************************************* 5 | */ 6 | 7 | /*!40101 SET NAMES utf8 */; 8 | 9 | /*!40101 SET SQL_MODE=''*/; 10 | 11 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; 12 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 13 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 14 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; 15 | CREATE DATABASE /*!32312 IF NOT EXISTS*/`book` /*!40100 DEFAULT CHARACTER SET utf8 */; 16 | 17 | USE `book`; 18 | 19 | /*Table structure for table `t_book` */ 20 | 21 | DROP TABLE IF EXISTS `t_book`; 22 | 23 | CREATE TABLE `t_book` ( 24 | `id` int(11) NOT NULL AUTO_INCREMENT, 25 | `name` varchar(100) DEFAULT NULL, 26 | `price` decimal(11,2) DEFAULT NULL, 27 | `author` varchar(100) DEFAULT NULL, 28 | `sales` int(11) DEFAULT NULL, 29 | `stock` int(11) DEFAULT NULL, 30 | `img_path` varchar(200) DEFAULT NULL, 31 | PRIMARY KEY (`id`) 32 | ) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8; 33 | 34 | /*Data for the table `t_book` */ 35 | 36 | LOCK TABLES `t_book` WRITE; 37 | 38 | insert into `t_book`(`id`,`name`,`price`,`author`,`sales`,`stock`,`img_path`) values 39 | (1,'java面对对象','81.00','何伟健',9999999,999,'static/img/default.jpg'), 40 | (2,'Java经典示例','78.50','张磊',6,13,'static/img/java5.jpg'), 41 | (3,'疯狂Java讲义','68.00','叶泽荣',99999,52,'static/img/java6.jpg'), 42 | (4,'Javaweb项目案列导航','16.00','小胖',1000,50,'static/img/java7.jpg'), 43 | (5,'Java语言程序设计','45.50','大胖',14,95,'static/img/java8.jpg'), 44 | (6,'Java深入解析','9.90','吴总就',12,52,'static/img/java9.jpg'), 45 | (7,'Java面试宝典','66.50','张三',125,535,'static/img/java10.jpg'), 46 | (8,'Java编程思想','99.50','赵四',47,36,'static/img/javaweb2.jpg'), 47 | (9,'深入分析Javaweb技术内幕','9.90','刘六',85,95,'static/img/javaweb3.jpg'), 48 | (10,'学通Javaweb的24门课','49.00','牛二',52,62,'static/img/junit.jpg'), 49 | (11,'osgi实战','28.00','谭七',52,74,'static/img/osgi1.jpg'), 50 | (12,'深入了解osgi','51.50','雷八',48,82,'static/img/osgi2.jpg'), 51 | (13,'java核心技术','12.00','罗九',19,9999,'static/img/java2.jpg'), 52 | (14,'Java网络编程','33.05','刘德',22,88,'static/img/java3.jpg'), 53 | (15,'spring企业应用开发实战','133.05','刘优',122,188,'static/img/spring1.jpg'), 54 | (16,'spring攻略','173.15','封十',21,81,'static/img/spring2.jpg'), 55 | (17,'tomcat Javaweb开发技术详解','99.15','乐十一',210,810,'static/img/tomcat.jpg'), 56 | (18,'javaScript从入门到精通','69.15','国十二',210,810,'static/img/javascript.jpg'), 57 | (19,'Javascript语言精粹','89.15','国十三',20,10,'static/img/javascript2.jpg'), 58 | (20,'Java编程是想','88.15','莫刚',999,80,'static/img/java11.jpg'), 59 | (21,'javaweb典型模块域项目实战开发','999.00','何加',9999999,111,'static/img/javaweb1.jpg'), 60 | (22,'javaweb开发实战1200例','999.00','邓贺',9999999,111,'static/img/javaweb4.jpg'), 61 | (23,'疯狂Ajax讲义','999.00','王宝',9999999,111,'static/img/ajax.jpg'), 62 | (25,'flash全站互动设计','999.00','黎明',9999999,111,'static/img/flash1.jpg'); 63 | 64 | UNLOCK TABLES; 65 | 66 | /*Table structure for table `t_cart` */ 67 | 68 | DROP TABLE IF EXISTS `t_cart`; 69 | 70 | CREATE TABLE `t_cart` ( 71 | `totalPrice` int(11) DEFAULT NULL, 72 | `totalCount` int(11) DEFAULT NULL, 73 | `userid` int(11) DEFAULT NULL 74 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 75 | 76 | /*Data for the table `t_cart` */ 77 | 78 | LOCK TABLES `t_cart` WRITE; 79 | 80 | UNLOCK TABLES; 81 | 82 | /*Table structure for table `t_cart_item` */ 83 | 84 | DROP TABLE IF EXISTS `t_cart_item`; 85 | 86 | CREATE TABLE `t_cart_item` ( 87 | `id` int(11) NOT NULL AUTO_INCREMENT, 88 | `name` varchar(100) DEFAULT NULL, 89 | `count` int(11) DEFAULT NULL, 90 | `price` decimal(11,2) DEFAULT NULL, 91 | `userid` int(11) DEFAULT NULL, 92 | PRIMARY KEY (`id`) 93 | ) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8; 94 | 95 | /*Data for the table `t_cart_item` */ 96 | 97 | LOCK TABLES `t_cart_item` WRITE; 98 | 99 | UNLOCK TABLES; 100 | 101 | /*Table structure for table `t_order` */ 102 | 103 | DROP TABLE IF EXISTS `t_order`; 104 | 105 | CREATE TABLE `t_order` ( 106 | `orderid` int(20) NOT NULL, 107 | `userid` int(11) DEFAULT NULL, 108 | PRIMARY KEY (`orderid`) 109 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 110 | 111 | /*Data for the table `t_order` */ 112 | 113 | LOCK TABLES `t_order` WRITE; 114 | 115 | insert into `t_order`(`orderid`,`userid`) values 116 | (13261285,3); 117 | 118 | UNLOCK TABLES; 119 | 120 | /*Table structure for table `user` */ 121 | 122 | DROP TABLE IF EXISTS `user`; 123 | 124 | CREATE TABLE `user` ( 125 | `id` int(11) NOT NULL AUTO_INCREMENT, 126 | `username` varchar(20) NOT NULL, 127 | `password` varchar(32) NOT NULL, 128 | `email` varchar(200) DEFAULT NULL, 129 | PRIMARY KEY (`id`), 130 | UNIQUE KEY `username` (`username`) 131 | ) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8; 132 | 133 | /*Data for the table `user` */ 134 | 135 | LOCK TABLES `user` WRITE; 136 | 137 | insert into `user`(`id`,`username`,`password`,`email`) values 138 | (1,'admin','admin','admin@atguigu.com'), 139 | (3,'hwj1218','123456','hwj@qq.com'), 140 | (4,'hwj1217','123456','hwj@qq.com'), 141 | (9,'hwj1219','123456','hwj@qq.com'), 142 | (10,'hwj1216','123456','hwj@qq.com'), 143 | (11,'hwj1210','123456','hwj@qq.com'), 144 | (12,'hwj110','123456','hwj110@qq.com'), 145 | (13,'hwj1104','123456','hwj@qq.com'), 146 | (14,'hwj1234','123456','12345@qq.com'), 147 | (15,'hwj12181128','123456','12345@qq.com'), 148 | (16,'hwj1239','123456','12345@qq.com'), 149 | (17,'hwj1238','123456','12345@qq.com'), 150 | (18,'yzr1218','123456','123456@qq.com'), 151 | (19,'yzr1219','123456','123456@qq.com'), 152 | (20,'hhh1234','123456','123456@qq.com'), 153 | (21,'wbl1218','123456','123456@qq.com'), 154 | (22,'hjl1218','123456','123456@qq.com'), 155 | (23,'hwj11111','123456','12345@qq.com'), 156 | (24,'zl1234','123456','12345@qq.com'); 157 | 158 | UNLOCK TABLES; 159 | 160 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; 161 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; 162 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; 163 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; 164 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /usr/local/etc/mavenrc ] ; then 40 | . /usr/local/etc/mavenrc 41 | fi 42 | 43 | if [ -f /etc/mavenrc ] ; then 44 | . /etc/mavenrc 45 | fi 46 | 47 | if [ -f "$HOME/.mavenrc" ] ; then 48 | . "$HOME/.mavenrc" 49 | fi 50 | 51 | fi 52 | 53 | # OS specific support. $var _must_ be set to either true or false. 54 | cygwin=false; 55 | darwin=false; 56 | mingw=false 57 | case "`uname`" in 58 | CYGWIN*) cygwin=true ;; 59 | MINGW*) mingw=true;; 60 | Darwin*) darwin=true 61 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 62 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 63 | if [ -z "$JAVA_HOME" ]; then 64 | if [ -x "/usr/libexec/java_home" ]; then 65 | export JAVA_HOME="`/usr/libexec/java_home`" 66 | else 67 | export JAVA_HOME="/Library/Java/Home" 68 | fi 69 | fi 70 | ;; 71 | esac 72 | 73 | if [ -z "$JAVA_HOME" ] ; then 74 | if [ -r /etc/gentoo-release ] ; then 75 | JAVA_HOME=`java-config --jre-home` 76 | fi 77 | fi 78 | 79 | if [ -z "$M2_HOME" ] ; then 80 | ## resolve links - $0 may be a link to maven's home 81 | PRG="$0" 82 | 83 | # need this for relative symlinks 84 | while [ -h "$PRG" ] ; do 85 | ls=`ls -ld "$PRG"` 86 | link=`expr "$ls" : '.*-> \(.*\)$'` 87 | if expr "$link" : '/.*' > /dev/null; then 88 | PRG="$link" 89 | else 90 | PRG="`dirname "$PRG"`/$link" 91 | fi 92 | done 93 | 94 | saveddir=`pwd` 95 | 96 | M2_HOME=`dirname "$PRG"`/.. 97 | 98 | # make it fully qualified 99 | M2_HOME=`cd "$M2_HOME" && pwd` 100 | 101 | cd "$saveddir" 102 | # echo Using m2 at $M2_HOME 103 | fi 104 | 105 | # For Cygwin, ensure paths are in UNIX format before anything is touched 106 | if $cygwin ; then 107 | [ -n "$M2_HOME" ] && 108 | M2_HOME=`cygpath --unix "$M2_HOME"` 109 | [ -n "$JAVA_HOME" ] && 110 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 111 | [ -n "$CLASSPATH" ] && 112 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 113 | fi 114 | 115 | # For Mingw, ensure paths are in UNIX format before anything is touched 116 | if $mingw ; then 117 | [ -n "$M2_HOME" ] && 118 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 119 | [ -n "$JAVA_HOME" ] && 120 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 121 | fi 122 | 123 | if [ -z "$JAVA_HOME" ]; then 124 | javaExecutable="`which javac`" 125 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 126 | # readlink(1) is not available as standard on Solaris 10. 127 | readLink=`which readlink` 128 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 129 | if $darwin ; then 130 | javaHome="`dirname \"$javaExecutable\"`" 131 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 132 | else 133 | javaExecutable="`readlink -f \"$javaExecutable\"`" 134 | fi 135 | javaHome="`dirname \"$javaExecutable\"`" 136 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 137 | JAVA_HOME="$javaHome" 138 | export JAVA_HOME 139 | fi 140 | fi 141 | fi 142 | 143 | if [ -z "$JAVACMD" ] ; then 144 | if [ -n "$JAVA_HOME" ] ; then 145 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 146 | # IBM's JDK on AIX uses strange locations for the executables 147 | JAVACMD="$JAVA_HOME/jre/sh/java" 148 | else 149 | JAVACMD="$JAVA_HOME/bin/java" 150 | fi 151 | else 152 | JAVACMD="`\\unset -f command; \\command -v java`" 153 | fi 154 | fi 155 | 156 | if [ ! -x "$JAVACMD" ] ; then 157 | echo "Error: JAVA_HOME is not defined correctly." >&2 158 | echo " We cannot execute $JAVACMD" >&2 159 | exit 1 160 | fi 161 | 162 | if [ -z "$JAVA_HOME" ] ; then 163 | echo "Warning: JAVA_HOME environment variable is not set." 164 | fi 165 | 166 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 167 | 168 | # traverses directory structure from process work directory to filesystem root 169 | # first directory with .mvn subdirectory is considered project base directory 170 | find_maven_basedir() { 171 | 172 | if [ -z "$1" ] 173 | then 174 | echo "Path not specified to find_maven_basedir" 175 | return 1 176 | fi 177 | 178 | basedir="$1" 179 | wdir="$1" 180 | while [ "$wdir" != '/' ] ; do 181 | if [ -d "$wdir"/.mvn ] ; then 182 | basedir=$wdir 183 | break 184 | fi 185 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 186 | if [ -d "${wdir}" ]; then 187 | wdir=`cd "$wdir/.."; pwd` 188 | fi 189 | # end of workaround 190 | done 191 | echo "${basedir}" 192 | } 193 | 194 | # concatenates all lines of a file 195 | concat_lines() { 196 | if [ -f "$1" ]; then 197 | echo "$(tr -s '\n' ' ' < "$1")" 198 | fi 199 | } 200 | 201 | BASE_DIR=`find_maven_basedir "$(pwd)"` 202 | if [ -z "$BASE_DIR" ]; then 203 | exit 1; 204 | fi 205 | 206 | ########################################################################################## 207 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 208 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 209 | ########################################################################################## 210 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Found .mvn/wrapper/maven-wrapper.jar" 213 | fi 214 | else 215 | if [ "$MVNW_VERBOSE" = true ]; then 216 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 217 | fi 218 | if [ -n "$MVNW_REPOURL" ]; then 219 | jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 220 | else 221 | jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 222 | fi 223 | while IFS="=" read key value; do 224 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 225 | esac 226 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 227 | if [ "$MVNW_VERBOSE" = true ]; then 228 | echo "Downloading from: $jarUrl" 229 | fi 230 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 231 | if $cygwin; then 232 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 233 | fi 234 | 235 | if command -v wget > /dev/null; then 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Found wget ... using wget" 238 | fi 239 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 240 | wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 241 | else 242 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 243 | fi 244 | elif command -v curl > /dev/null; then 245 | if [ "$MVNW_VERBOSE" = true ]; then 246 | echo "Found curl ... using curl" 247 | fi 248 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 249 | curl -o "$wrapperJarPath" "$jarUrl" -f 250 | else 251 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 252 | fi 253 | 254 | else 255 | if [ "$MVNW_VERBOSE" = true ]; then 256 | echo "Falling back to using Java to download" 257 | fi 258 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 259 | # For Cygwin, switch paths to Windows format before running javac 260 | if $cygwin; then 261 | javaClass=`cygpath --path --windows "$javaClass"` 262 | fi 263 | if [ -e "$javaClass" ]; then 264 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 265 | if [ "$MVNW_VERBOSE" = true ]; then 266 | echo " - Compiling MavenWrapperDownloader.java ..." 267 | fi 268 | # Compiling the Java class 269 | ("$JAVA_HOME/bin/javac" "$javaClass") 270 | fi 271 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 272 | # Running the downloader 273 | if [ "$MVNW_VERBOSE" = true ]; then 274 | echo " - Running MavenWrapperDownloader.java ..." 275 | fi 276 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 277 | fi 278 | fi 279 | fi 280 | fi 281 | ########################################################################################## 282 | # End of extension 283 | ########################################################################################## 284 | 285 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 286 | if [ "$MVNW_VERBOSE" = true ]; then 287 | echo $MAVEN_PROJECTBASEDIR 288 | fi 289 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 290 | 291 | # For Cygwin, switch paths to Windows format before running java 292 | if $cygwin; then 293 | [ -n "$M2_HOME" ] && 294 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 295 | [ -n "$JAVA_HOME" ] && 296 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 297 | [ -n "$CLASSPATH" ] && 298 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 299 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 300 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 301 | fi 302 | 303 | # Provide a "standardized" way to retrieve the CLI args that will 304 | # work with both Windows and non-Windows executions. 305 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 306 | export MAVEN_CMD_LINE_ARGS 307 | 308 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 309 | 310 | exec "$JAVACMD" \ 311 | $MAVEN_OPTS \ 312 | $MAVEN_DEBUG_OPTS \ 313 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 314 | "-Dmaven.home=${M2_HOME}" \ 315 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 316 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 317 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 50 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 124 | 125 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% ^ 162 | %JVM_CONFIG_MAVEN_PROPS% ^ 163 | %MAVEN_OPTS% ^ 164 | %MAVEN_DEBUG_OPTS% ^ 165 | -classpath %WRAPPER_JAR% ^ 166 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 167 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 168 | if ERRORLEVEL 1 goto error 169 | goto end 170 | 171 | :error 172 | set ERROR_CODE=1 173 | 174 | :end 175 | @endlocal & set ERROR_CODE=%ERROR_CODE% 176 | 177 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 178 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 179 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 180 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 181 | :skipRcPost 182 | 183 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 184 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 185 | 186 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 187 | 188 | cmd /C exit /B %ERROR_CODE% 189 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.example 8 | book 9 | 1.0-SNAPSHOT 10 | book 11 | war 12 | 13 | 14 | UTF-8 15 | 1.8 16 | 1.8 17 | 5.8.2 18 | 19 | 20 | 21 | 22 | javax.servlet 23 | javax.servlet-api 24 | 4.0.1 25 | provided 26 | 27 | 28 | org.junit.jupiter 29 | junit-jupiter-api 30 | ${junit.version} 31 | test 32 | 33 | 34 | org.junit.jupiter 35 | junit-jupiter-engine 36 | ${junit.version} 37 | test 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.apache.maven.plugins 45 | maven-war-plugin 46 | 3.3.2 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/druid.properties: -------------------------------------------------------------------------------- 1 | #key=value 2 | driverClassName=com.mysql.jdbc.Driver 3 | url=jdbc:mysql://localhost:3306/book?rewriteBatchedStatements=true 4 | username=root 5 | password=123456 6 | #initial connection Size 7 | initialSize=10 8 | #min idle connecton size 9 | minIdle=5 10 | #max active connection size 11 | maxActive=50 12 | #max wait time (5000 mil seconds) 13 | maxWait=5000 -------------------------------------------------------------------------------- /src/main/java/com/bookshop/dao/BookDao.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.dao; 2 | 3 | import com.bookshop.pojo.Book; 4 | 5 | import java.util.List; 6 | 7 | @SuppressWarnings("all") 8 | public interface BookDao { 9 | /** 10 | * 添加图书 11 | * @param book 12 | * @return 13 | */ 14 | public int addBook(Book book); 15 | 16 | /** 17 | * 根据id删除图书 18 | * @param id 19 | * @return 20 | */ 21 | public int deleteBookById(Integer id); 22 | /** 23 | * 更新图书 24 | * @param book 25 | * @return 26 | */ 27 | public int updateBook(Book book); 28 | /** 29 | * 根据id查询图书 30 | * @param id 31 | * @return 32 | */ 33 | public Book queryBookById(Integer id); 34 | /** 35 | * 查询全部图书 36 | * @return 37 | */ 38 | public List queryBooks(); 39 | /** 40 | * 查询总记录数 41 | * @return 42 | */ 43 | public Object queryValue(); 44 | /** 45 | * 查询当前页数据 46 | * @param begin 47 | * @param pageSize 48 | * @return 49 | */ 50 | Integer queryForPageTotalCount(); 51 | /** 52 | * 查询当前页数据 53 | * @param begin 54 | * @param pageSize 55 | * @return 56 | */ 57 | List queryForPageItems(int begin, int pageSize); 58 | /** 59 | * 查询当前页数据 60 | * @param begin 61 | * @param pageSize 62 | * @return 63 | */ 64 | List queryForPageItemsByPrice(int begin, int pageSize, int min, int max); 65 | /** 66 | * 查询当前页数据 67 | * @param begin 68 | * @param pageSize 69 | * @return 70 | */ 71 | Integer queryForPageTotalCountByPrice(int min, int max); 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/dao/CartDao.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.dao; 2 | 3 | import com.bookshop.pojo.Cart; 4 | 5 | public interface CartDao { 6 | 7 | /** 8 | * 根据用户id查询购物车 9 | * @param userid 10 | * @return 11 | */ 12 | public Cart queryCart(Integer userid); 13 | 14 | /** 15 | * 是否存在该用户 16 | */ 17 | public boolean isExist(Integer userid); 18 | 19 | 20 | 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/dao/CartItemDao.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.dao; 2 | 3 | 4 | import com.bookshop.pojo.CartItem; 5 | 6 | import java.util.List; 7 | 8 | public interface CartItemDao { 9 | /** 10 | * 添加商品项 11 | * @param cartItem 12 | */ 13 | public void addItem(CartItem cartItem); 14 | 15 | /** 16 | * 删除商品项 17 | * @param id 18 | */ 19 | public void deleteItem(Integer id,CartItem cartItem); 20 | 21 | /** 22 | * 清空购物车 23 | */ 24 | public void clear(CartItem cartItem); 25 | 26 | /** 27 | * 修改商品数量 28 | * @param id 29 | * @param 30 | */ 31 | public void updateCount(Integer id,CartItem cartItem); 32 | 33 | /** 34 | * 查询购物车 35 | * @return 36 | */ 37 | public List queryCart( Integer userid); 38 | 39 | /** 40 | * 查询购物车 41 | * @return 42 | */ 43 | public List queryCartid(Integer id); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/dao/OrderDao.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.dao; 2 | 3 | import com.bookshop.pojo.Order; 4 | 5 | import java.util.List; 6 | 7 | public interface OrderDao { 8 | 9 | /** 10 | * 查询所有订单 11 | * @return 12 | */ 13 | public List queryOrders(); 14 | /** 15 | * 保存订单 16 | * @param order 17 | */ 18 | public void saveOrder(Order order); 19 | 20 | /** 21 | * 删除订单 22 | * @param orderid 23 | */ 24 | public void deleteOrder(Integer orderid); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.dao; 2 | 3 | import com.bookshop.pojo.User; 4 | 5 | import java.util.List; 6 | 7 | public interface UserDao { 8 | 9 | 10 | 11 | /** 12 | * 根据用户名查询用户信息 13 | * @param username 用户名 14 | * @return 如果返回null,说明没有这个用户。反之亦然 15 | */ 16 | public List queryUserByUsername(String username); 17 | 18 | /** 19 | * 根据 用户名和密码查询用户信息 20 | * @param username 21 | * @param password 22 | * @return 如果返回null,说明用户名或密码错误,反之亦然 23 | */ 24 | public List queryUserByUsernameAndPassword(String username,String password); 25 | 26 | /** 27 | * 保存用户信息 28 | * @param user 29 | * @return 返回-1表示操作失败,其他是sql语句影响的行数 30 | */ 31 | public int saveUser(User user); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/dao/impl/BasicDAO.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.dao.impl; 2 | 3 | 4 | 5 | import com.bookshop.utils.JDBCUtilsByDruid; 6 | import org.apache.commons.dbutils.QueryRunner; 7 | import org.apache.commons.dbutils.handlers.BeanHandler; 8 | import org.apache.commons.dbutils.handlers.BeanListHandler; 9 | import org.apache.commons.dbutils.handlers.ScalarHandler; 10 | 11 | import java.sql.Connection; 12 | import java.sql.SQLException; 13 | import java.util.List; 14 | 15 | 16 | public class BasicDAO { //泛型指定具体类型 17 | 18 | private QueryRunner qr = new QueryRunner(); 19 | 20 | /* 21 | * 通用的增删改的方法 22 | */ 23 | public int update(String sql, Object... parameters) { 24 | 25 | Connection connection = null; 26 | 27 | try { 28 | connection = JDBCUtilsByDruid.getConnection(); 29 | int update = qr.update(connection, sql, parameters); 30 | return update; 31 | } catch (SQLException e) { 32 | throw new RuntimeException(e); 33 | } 34 | 35 | } 36 | 37 | 38 | /** 39 | * 40 | * @param sql sql 语句,可以有 ? 41 | * @param clazz 传入一个类的Class对象 比如 Actor.class 42 | * @param parameters 传入 ? 的具体的值,可以是多个 43 | * @return 根据Actor.class 返回对应的 ArrayList 集合 44 | */ 45 | public List queryMulti(String sql, Class clazz, Object... parameters) { 46 | 47 | Connection connection = null; 48 | try { 49 | connection = JDBCUtilsByDruid.getConnection(); 50 | return qr.query(connection, sql, new BeanListHandler(clazz), parameters); 51 | 52 | } catch (SQLException e) { 53 | throw new RuntimeException(e); 54 | } 55 | 56 | } 57 | 58 | /* 59 | * 通用的查询单行的方法 60 | */ 61 | public T querySingle(String sql, Class clazz, Object... parameters) { 62 | 63 | Connection connection = null; 64 | try { 65 | connection = JDBCUtilsByDruid.getConnection(); 66 | return qr.query(connection, sql, new BeanHandler(clazz), parameters); 67 | 68 | } catch (SQLException e) { 69 | throw new RuntimeException(e); 70 | } 71 | } 72 | 73 | /* 74 | * 通用的查询单个值的方法 75 | */ 76 | 77 | public Object queryScalar(String sql, Object... parameters) { 78 | 79 | Connection connection = null; 80 | try { 81 | connection = JDBCUtilsByDruid.getConnection(); 82 | return qr.query(connection, sql, new ScalarHandler(), parameters); 83 | 84 | } catch (SQLException e) { 85 | throw new RuntimeException(e); 86 | } 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/dao/impl/BookDaoImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @version 1.0 3 | */ 4 | 5 | 6 | package com.bookshop.dao.impl; 7 | 8 | import com.bookshop.dao.BookDao; 9 | import com.bookshop.pojo.Book; 10 | 11 | import java.util.List; 12 | 13 | public class BookDaoImpl extends BasicDAO implements BookDao { 14 | @Override 15 | public int addBook(Book book) { 16 | String sql = "insert into t_book(`name`,`author`,`price`,`sales`,`stock`,`img_path`) values(?,?,?,?,?,?)"; 17 | return update(sql, book.getName(), book.getAuthor(), book.getPrice(), book.getSales(), book.getStock(), book.getImgPath()); 18 | } 19 | 20 | @Override 21 | public int deleteBookById(Integer id) { 22 | String sql = "delete from t_book where id = ?"; 23 | return update(sql, id); 24 | } 25 | 26 | @Override 27 | public int updateBook(Book book) { 28 | String sql = "update t_book set `name` = ?,`author` = ?,`price` = ?,`sales` = ?,`stock` = ?,`img_path` = ? where id = ?"; 29 | return update(sql, book.getName(), book.getAuthor(), book.getPrice(), book.getSales(), book.getStock(), book.getImgPath(), book.getId()); 30 | } 31 | 32 | @Override 33 | public Book queryBookById(Integer id){ 34 | String sql = "select `id`,`name`,`author`,`price`,`sales`,`stock`,`img_path` imgPath from t_book where id = ?"; 35 | return querySingle(sql, Book.class, id); 36 | } 37 | 38 | @Override 39 | public List queryBooks() { 40 | String sql = "select `id`,`name`,`author`,`price`,`sales`,`stock`,`img_path` imgPath from t_book"; 41 | return queryMulti(sql, Book.class); 42 | } 43 | 44 | @Override 45 | public Integer queryForPageTotalCount() { 46 | String sql = "select count(*) from t_book"; 47 | Number count = (Number) queryScalar(sql); 48 | return count.intValue(); 49 | } 50 | 51 | @Override 52 | public Integer queryForPageTotalCountByPrice(int min, int max) { 53 | String sql = "select count(*) from t_book where price between ? and ?"; 54 | Number count = (Number) queryScalar(sql, min, max); 55 | return count.intValue(); 56 | } 57 | 58 | @Override 59 | public List queryForPageItemsByPrice(int begin, int pageSize, int min, int max) {// 价格区间 60 | String sql = "select `id`,`name`,`author`,`price`,`sales`,`stock`,`img_path` imgPath from t_book where price between ? and ? order by price limit ?,?"; 61 | return queryMulti(sql, Book.class, min, max, begin, pageSize); 62 | } 63 | 64 | @Override 65 | public List queryForPageItems(int begin, int pageSize) { 66 | String sql = "select `id`,`name`,`author`,`price`,`sales`,`stock`,`img_path` imgPath from t_book limit ?,?"; 67 | return queryMulti(sql, Book.class, begin, pageSize); 68 | } 69 | 70 | @Override 71 | public Object queryValue() { 72 | String sql = "select count(*) from t_book"; 73 | return queryScalar(sql); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/dao/impl/CartDaoImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @version 1.0 3 | */ 4 | 5 | 6 | package com.bookshop.dao.impl; 7 | 8 | import com.bookshop.dao.CartDao; 9 | import com.bookshop.pojo.Cart; 10 | 11 | 12 | 13 | public class CartDaoImpl extends BasicDAO implements CartDao { 14 | @Override 15 | public Cart queryCart(Integer userid) {//根据用户id查询购物车 16 | String sql = "select * from t_cart where userid = ?"; 17 | return querySingle(sql,Cart.class,userid); 18 | } 19 | 20 | @Override 21 | public boolean isExist(Integer userid) { 22 | //判断是否存在该用户 23 | String sql = "select *from t_cart where userid = ?"; 24 | Cart cart = querySingle(sql, Cart.class, userid); 25 | //如果存在返回true 26 | if(cart != null){ 27 | return true; 28 | }else { 29 | //如果不存在返回创建 该用户的购物车 30 | String add = "insert into t_cart(`userid`,`totalPrice`,`totalCount`) values(?,?,?)"; 31 | update(add,userid,0,0); 32 | return false; 33 | } 34 | 35 | } 36 | 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/dao/impl/CartDaoItemImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @version 1.0 3 | */ 4 | 5 | 6 | package com.bookshop.dao.impl; 7 | 8 | import com.bookshop.dao.CartItemDao; 9 | import com.bookshop.pojo.Cart; 10 | import com.bookshop.pojo.CartItem; 11 | 12 | import java.math.BigDecimal; 13 | import java.util.List; 14 | 15 | 16 | @SuppressWarnings("all") 17 | public class CartDaoItemImpl extends BasicDAO implements CartItemDao { 18 | private CartItem cartItem = new CartItem(); 19 | private Cart cart = new Cart(); 20 | 21 | 22 | @Override 23 | public void addItem(CartItem cartItem) { 24 | 25 | String select = "select * from t_cart_item where id = ? "; 26 | CartItem cart = querySingle(select, CartItem.class, cartItem.getId()); 27 | if (cart == null){ 28 | String add = "insert into t_cart_item(`id`,`name`,`count`,`price`,`userid`) values(?,?,?,?,?)"; 29 | update(add,cartItem.getId(),cartItem.getName(),cartItem.getCount(),cartItem.getPrice(),cartItem.getUserid()); 30 | }else { 31 | //如果存在该商品,就修改商品数量 32 | String update = "update t_cart_item set count = count + 1 where id = ?"; 33 | update(update,cartItem.getId()); 34 | } 35 | String updateCart = "update t_cart set totalPrice = totalPrice + ?,totalCount = totalCount + 1 where userid = ?"; 36 | update(updateCart,cartItem.getPrice(),cartItem.getUserid()); 37 | 38 | 39 | 40 | 41 | } 42 | 43 | @Override 44 | public void deleteItem(Integer id,CartItem cartItem) { 45 | String sql = "delete from t_cart_item where id = ?"; 46 | update(sql,id); 47 | String update = "update t_cart set totalcount = totalcount - ?,totalprice = totalprice - ? where userid = ?"; 48 | BigDecimal price = cartItem.getPrice().multiply(new BigDecimal(cartItem.getCount())); 49 | update(update,cartItem.getCount(),price,cartItem.getUserid()); 50 | 51 | } 52 | 53 | @Override 54 | public void clear(CartItem cartItem) { 55 | String sql = "delete from t_cart_item where userid = ?"; 56 | update(sql,cartItem.getUserid()); 57 | String update = "delete from t_cart where userid = ?"; 58 | update(update,cartItem.getUserid()); 59 | 60 | } 61 | 62 | @Override 63 | public void updateCount(Integer id, CartItem cartItem) { 64 | //获取原来的数量及价格 65 | String sql ="select count,price from t_cart_item where id = ?"; 66 | CartItem cart = querySingle(sql, CartItem.class, id); 67 | 68 | Integer num = cart.getCount(); 69 | 70 | //原来的价格 71 | BigDecimal price = cart.getPrice(); 72 | BigDecimal total = price.multiply(new BigDecimal(num)); 73 | 74 | //修改数量及价格 75 | String update = "update t_cart_item set count = ? where id = ?"; 76 | Integer count = cartItem.getCount(); 77 | update(update,cartItem.getCount(),id); 78 | 79 | //计算修改后的价格 80 | BigDecimal newPrice = price.multiply(new BigDecimal(count)); 81 | 82 | String add = "update t_cart set totalcount = totalcount - ? + ?,totalprice = totalprice - ? + ? where userid = ?"; 83 | update(add,num,count,total,newPrice,cartItem.getUserid()); 84 | 85 | } 86 | 87 | @Override 88 | public List queryCart(Integer userid) { 89 | String sql = "select * from t_cart_item where userid = ?"; 90 | List cartItems = queryMulti(sql, CartItem.class, userid); 91 | return cartItems; 92 | } 93 | 94 | @Override 95 | public List queryCartid(Integer id) { 96 | String sql = "select * from t_cart_item where id = ?"; 97 | List cartItems = queryMulti(sql, CartItem.class, id); 98 | return cartItems; 99 | } 100 | 101 | 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/dao/impl/OrderDaoImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author 何伟健 3 | * @version 1.0 4 | * @date 2023/6/3 23:27 5 | */ 6 | 7 | 8 | package com.bookshop.dao.impl; 9 | 10 | import com.bookshop.dao.OrderDao; 11 | import com.bookshop.pojo.Order; 12 | 13 | import java.util.List; 14 | 15 | public class OrderDaoImpl extends BasicDAO implements OrderDao { 16 | 17 | 18 | @Override 19 | public List queryOrders() { 20 | String sql = "select * from t_order"; 21 | return queryMulti(sql, Order.class); 22 | } 23 | 24 | @Override 25 | public void saveOrder(Order order) { 26 | String sql = "insert into t_order(orderid, userid) values(?,?)"; 27 | update(sql, order.getOrderid(), order.getUserid()); 28 | String cart = "delete from t_cart where userid = ?"; 29 | update(cart,order.getUserid()); 30 | String cartItem = "delete from t_cart_item where userid = ?"; 31 | update(cartItem,order.getUserid()); 32 | 33 | } 34 | 35 | @Override 36 | public void deleteOrder(Integer orderid) { 37 | String sql = "delete from t_order where orderid = ?"; 38 | update(sql,orderid); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/dao/impl/UserDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.dao.impl; 2 | 3 | import com.bookshop.dao.UserDao; 4 | import com.bookshop.pojo.User; 5 | 6 | import java.util.List; 7 | 8 | public class UserDaoImpl extends BasicDAO implements UserDao { 9 | @Override 10 | public List queryUserByUsername(String username) { 11 | String sql = "select `id`,`username`,`password`,`email` from user where username = ?"; 12 | return queryMulti(sql, User.class, username); 13 | } 14 | 15 | @Override 16 | public ListqueryUserByUsernameAndPassword(String username, String password) { 17 | String sql = "select `id`,`username`,`password`,`email` from user where username = ? and password = ?"; 18 | return queryMulti(sql, User.class, username, password); 19 | } 20 | 21 | @Override 22 | public int saveUser(User user) { 23 | String sql = "insert into user(`username`,`password`,`email`) values(?,?,?)"; 24 | return update(sql, user.getUsername(),user.getPassword(),user.getEmail()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/filter/ManagerFilter.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.filter; 2 | 3 | import javax.servlet.*; 4 | import javax.servlet.http.HttpServletRequest; 5 | import java.io.IOException; 6 | 7 | public class ManagerFilter implements Filter { 8 | 9 | @Override 10 | public void init(FilterConfig filterConfig) throws ServletException { 11 | 12 | } 13 | 14 | @Override 15 | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { 16 | 17 | 18 | HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest; 19 | 20 | Object user = httpServletRequest.getSession().getAttribute("user"); 21 | 22 | if (user == null) { 23 | httpServletRequest.getRequestDispatcher("/pages/user/login.jsp").forward(servletRequest,servletResponse); 24 | } else { 25 | filterChain.doFilter(servletRequest,servletResponse); 26 | } 27 | } 28 | 29 | @Override 30 | public void destroy() { 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/filter/TransactionFilter.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.filter; 2 | 3 | import com.bookshop.utils.JDBCUtilsByDruid; 4 | 5 | import javax.servlet.*; 6 | import java.io.IOException; 7 | 8 | public class TransactionFilter implements Filter { 9 | 10 | @Override 11 | public void init(FilterConfig filterConfig) throws ServletException { 12 | 13 | } 14 | 15 | @Override 16 | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { 17 | try { 18 | filterChain.doFilter(servletRequest,servletResponse); 19 | JDBCUtilsByDruid.commitAndClose(); 20 | } catch (Exception e) { 21 | JDBCUtilsByDruid.rollbackAndClose(); 22 | e.printStackTrace(); 23 | throw new RuntimeException(e); 24 | } 25 | } 26 | 27 | @Override 28 | public void destroy() { 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/pojo/Book.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @version 1.0 3 | */ 4 | 5 | 6 | package com.bookshop.pojo; 7 | 8 | import java.math.BigDecimal; 9 | 10 | public class Book { 11 | private Integer id; 12 | private String name; 13 | private String author; 14 | private BigDecimal price; 15 | private Integer sales; 16 | private Integer stock; 17 | private String imgPath = "static/img/default.jpg"; 18 | 19 | public Book() { 20 | } 21 | 22 | public Book(Integer id, String name, String author, BigDecimal price, Integer sales, Integer stock, String imgPath) { 23 | this.id = id; 24 | this.name = name; 25 | this.author = author; 26 | this.price = price; 27 | this.sales = sales; 28 | this.stock = stock; 29 | if (imgPath != null && !"".equals(imgPath)) { 30 | this.imgPath = imgPath; 31 | } 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "Book{" + 37 | "id=" + id + 38 | ", name='" + name + '\'' + 39 | ", author='" + author + '\'' + 40 | ", price=" + price + 41 | ", sales=" + sales + 42 | ", stock=" + stock + 43 | ", imgPath='" + imgPath + '\'' + 44 | '}'; 45 | } 46 | 47 | public Integer getId() { 48 | return id; 49 | } 50 | 51 | public void setId(Integer id) { 52 | this.id = id; 53 | } 54 | 55 | public String getName() { 56 | return name; 57 | } 58 | 59 | public void setName(String name) { 60 | this.name = name; 61 | } 62 | 63 | public String getAuthor() { 64 | return author; 65 | } 66 | 67 | public void setAuthor(String author) { 68 | this.author = author; 69 | } 70 | 71 | public BigDecimal getPrice() { 72 | return price; 73 | } 74 | 75 | public void setPrice(BigDecimal price) { 76 | this.price = price; 77 | } 78 | 79 | public Integer getSales() { 80 | return sales; 81 | } 82 | 83 | public void setSales(Integer sales) { 84 | this.sales = sales; 85 | } 86 | 87 | public Integer getStock() { 88 | return stock; 89 | } 90 | 91 | public void setStock(Integer stock) { 92 | this.stock = stock; 93 | } 94 | 95 | public String getImgPath() { 96 | return imgPath; 97 | } 98 | 99 | public void setImgPath(String imgPath) { 100 | if (imgPath != null && !"".equals(imgPath)) { 101 | this.imgPath = imgPath; 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/pojo/Cart.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @version 1.0 3 | */ 4 | 5 | 6 | package com.bookshop.pojo; 7 | 8 | 9 | 10 | @SuppressWarnings("all") 11 | public class Cart { 12 | private Integer totalCount; 13 | private Integer totalPrice; 14 | 15 | private Integer userid; 16 | 17 | 18 | public Cart() { 19 | } 20 | 21 | public Cart(Integer totalCount, Integer totalPrice, Integer userid) { 22 | this.totalCount = totalCount; 23 | this.totalPrice = totalPrice; 24 | this.userid = userid; 25 | } 26 | 27 | public Integer getTotalCount() { 28 | return totalCount; 29 | } 30 | 31 | public void setTotalCount(Integer totalCount) { 32 | this.totalCount = totalCount; 33 | } 34 | 35 | public Integer getTotalPrice() { 36 | return totalPrice; 37 | } 38 | 39 | public void setTotalPrice(Integer totalPrice) { 40 | this.totalPrice = totalPrice; 41 | } 42 | 43 | public Integer getUserid() { 44 | return userid; 45 | } 46 | 47 | public void setUserid(Integer userid) { 48 | this.userid = userid; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return "Cart{" + 54 | "totalCount=" + totalCount + 55 | ", totalPrice=" + totalPrice + 56 | ", userid=" + userid + 57 | '}'; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/pojo/CartItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @version 1.0 3 | */ 4 | 5 | 6 | package com.bookshop.pojo; 7 | 8 | import java.math.BigDecimal; 9 | 10 | public class CartItem { 11 | private Integer id; 12 | private String name; 13 | private Integer count; 14 | private BigDecimal price; 15 | 16 | private Integer userid; 17 | 18 | 19 | public CartItem() { 20 | } 21 | 22 | public CartItem(Integer id, String name, Integer count, BigDecimal price, Integer userid) { 23 | this.id = id; 24 | this.name = name; 25 | this.count = count; 26 | this.price = price; 27 | this.userid = userid; 28 | } 29 | public CartItem(Integer count, BigDecimal price, Integer userid){ 30 | this.count = count; 31 | this.price = price; 32 | this.userid = userid; 33 | } 34 | public CartItem(Integer userid){ 35 | this.userid = userid; 36 | } 37 | 38 | public Integer getId() { 39 | return id; 40 | } 41 | 42 | public void setId(Integer id) { 43 | this.id = id; 44 | } 45 | 46 | public String getName() { 47 | return name; 48 | } 49 | 50 | public void setName(String name) { 51 | this.name = name; 52 | } 53 | 54 | public Integer getCount() { 55 | return count; 56 | } 57 | 58 | public void setCount(Integer count) { 59 | this.count = count; 60 | } 61 | 62 | public BigDecimal getPrice() { 63 | return price; 64 | } 65 | 66 | public void setPrice(BigDecimal price) { 67 | this.price = price; 68 | } 69 | 70 | public Integer getUserid() { 71 | return userid; 72 | } 73 | 74 | public void setUserid(Integer userid) { 75 | this.userid = userid; 76 | } 77 | 78 | @Override 79 | public String toString() { 80 | return "CartItem{" + 81 | "id=" + id + 82 | ", name='" + name + '\'' + 83 | ", count=" + count + 84 | ", price=" + price + 85 | ", userid=" + userid + 86 | '}'; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/pojo/Order.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author 何伟健 3 | * @version 1.0 4 | * @date 2023/6/3 23:23 5 | */ 6 | 7 | 8 | package com.bookshop.pojo; 9 | 10 | 11 | public class Order { 12 | private Integer orderid; 13 | 14 | private Integer userid; 15 | 16 | @Override 17 | public String toString() { 18 | return "Order{" + 19 | "orderid=" + orderid + 20 | ", userid=" + userid + 21 | '}'; 22 | } 23 | 24 | public Integer getUserid() { 25 | return userid; 26 | } 27 | 28 | public void setUserid(Integer userid) { 29 | this.userid = userid; 30 | } 31 | 32 | public Integer getOrderid() { 33 | return orderid; 34 | } 35 | 36 | public void setOrderid(Integer orderid) { 37 | this.orderid = orderid; 38 | } 39 | 40 | public Order() { 41 | } 42 | 43 | public Order(Integer orderid, Integer userid) { 44 | this.orderid = orderid; 45 | this.userid = userid; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/pojo/Page.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.pojo; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Page是分页的模型对象 7 | * @param 是具体的模块的javaBean类 8 | */ 9 | public class Page { 10 | public static final Integer PAGE_SIZE = 4; 11 | // 当前页码 12 | private Integer pageNo; 13 | // 总页码 14 | private Integer pageTotal; 15 | // 当前页显示数量 16 | private Integer pageSize = PAGE_SIZE; 17 | // 总记录数 18 | private Integer pageTotalCount; 19 | // 当前页数据 20 | private List items; 21 | // 分页条的请求地址 22 | private String url; 23 | 24 | public String getUrl() { 25 | return url; 26 | } 27 | 28 | public void setUrl(String url) { 29 | this.url = url; 30 | } 31 | 32 | public Integer getPageNo() { 33 | return pageNo; 34 | } 35 | 36 | public void setPageNo(Integer pageNo) { 37 | /* 数据边界的有效检查 */ 38 | if (pageNo < 1) { 39 | pageNo = 1; 40 | } 41 | if (pageNo > pageTotal) { 42 | pageNo = pageTotal; 43 | } 44 | 45 | this.pageNo = pageNo; 46 | } 47 | 48 | public Integer getPageTotal() { 49 | return pageTotal; 50 | } 51 | 52 | public void setPageTotal(Integer pageTotal) { 53 | this.pageTotal = pageTotal; 54 | } 55 | 56 | public Integer getPageSize() { 57 | return pageSize; 58 | } 59 | 60 | public void setPageSize(Integer pageSize) { 61 | this.pageSize = pageSize; 62 | } 63 | 64 | public Integer getPageTotalCount() { 65 | return pageTotalCount; 66 | } 67 | 68 | public void setPageTotalCount(Integer pageTotalCount) { 69 | this.pageTotalCount = pageTotalCount; 70 | } 71 | 72 | public List getItems() { 73 | return items; 74 | } 75 | 76 | public void setItems(List items) { 77 | this.items = items; 78 | } 79 | 80 | @Override 81 | public String toString() { 82 | return "Page{" + 83 | "pageNo=" + pageNo + 84 | ", pageTotal=" + pageTotal + 85 | ", pageSize=" + pageSize + 86 | ", pageTotalCount=" + pageTotalCount + 87 | ", items=" + items + 88 | ", url='" + url + '\'' + 89 | '}'; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/pojo/User.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.pojo; 2 | 3 | public class User { 4 | private Integer id; 5 | private String username; 6 | private String password; 7 | private String email; 8 | 9 | public Integer getId() { 10 | return id; 11 | } 12 | 13 | public void setId(Integer id) { 14 | this.id = id; 15 | } 16 | 17 | public String getUsername() { 18 | return username; 19 | } 20 | 21 | public void setUsername(String username) { 22 | this.username = username; 23 | } 24 | 25 | public String getPassword() { 26 | return password; 27 | } 28 | 29 | public void setPassword(String password) { 30 | this.password = password; 31 | } 32 | 33 | public String getEmail() { 34 | return email; 35 | } 36 | 37 | public void setEmail(String email) { 38 | this.email = email; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return "User{" + 44 | "id=" + id + 45 | ", username='" + username + '\'' + 46 | ", password='" + password + '\'' + 47 | ", email='" + email + '\'' + 48 | '}'; 49 | } 50 | 51 | public User() { 52 | } 53 | 54 | public User(Integer id, String username, String password, String email) { 55 | this.id = id; 56 | this.username = username; 57 | this.password = password; 58 | this.email = email; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/service/BookService.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.service; 2 | 3 | import com.bookshop.pojo.Book; 4 | import com.bookshop.pojo.Page; 5 | 6 | import java.util.List; 7 | 8 | @SuppressWarnings("all") 9 | public interface BookService { 10 | 11 | /** 12 | * 添加图书 13 | * @param book 14 | */ 15 | public void addBook(Book book); 16 | /** 17 | * 根据id删除图书 18 | * @param id 19 | */ 20 | public void deleteBookById(Integer id); 21 | /** 22 | * 更新图书 23 | * @param book 24 | */ 25 | public void updateBook(Book book); 26 | /** 27 | * 根据id查询图书 28 | * @param id 29 | * @return 30 | */ 31 | public Book queryBookById(Integer id); 32 | /** 33 | * 查询全部图书 34 | * @return 35 | */ 36 | public List queryBooks(); 37 | /** 38 | * 查询总记录数 39 | * @return 40 | */ 41 | public Object queryValue(); 42 | /** 43 | * 分页 44 | * @param pageNo 45 | * @param pageSize 46 | * @return 47 | */ 48 | Page page(int pageNo, int pageSize); 49 | /** 50 | * 分页 51 | * @param pageNo 52 | * @param pageSize 53 | * @param min 54 | * @param max 55 | * @return 56 | */ 57 | Page pageByPrice(int pageNo, int pageSize, int min, int max); 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/service/CartItemService.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.service; 2 | 3 | 4 | import com.bookshop.pojo.CartItem; 5 | 6 | import java.util.List; 7 | 8 | @SuppressWarnings("all") 9 | public interface CartItemService { 10 | /** 11 | * 添加商品项 12 | * @param cartItem 13 | */ 14 | 15 | public void addItem(CartItem cartItem); 16 | /** 17 | * 删除商品项 18 | * @param id 19 | */ 20 | 21 | public void deleteItem(Integer id,CartItem cartItem); 22 | /** 23 | * 清空购物车 24 | */ 25 | 26 | public void clear(CartItem cartItem); 27 | 28 | /** 29 | * 修改商品数量 30 | * @param id 31 | * @param count 32 | */ 33 | 34 | public void updateCount(Integer id,CartItem cartItem); 35 | 36 | /** 37 | * 查询购物车 38 | * @return 39 | */ 40 | public List queryCart(Integer userid); 41 | 42 | 43 | /** 44 | * 查询购物车 45 | * @return 46 | */ 47 | public List queryCartid(Integer id); 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/service/CartService.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.service; 2 | 3 | import com.bookshop.pojo.Cart; 4 | 5 | 6 | public interface CartService { 7 | /** 8 | * 查询购物车 9 | * @param userid 10 | * @return 11 | */ 12 | public Cart queryCart(Integer userid); 13 | 14 | /** 15 | * 查询用户是否存在 16 | * @param userid 17 | */ 18 | public boolean isExist(Integer userid); 19 | 20 | 21 | 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.service; 2 | 3 | import com.bookshop.pojo.Order; 4 | 5 | import java.util.List; 6 | 7 | public interface OrderService { 8 | /** 9 | * 查询订单 10 | * @return 11 | */ 12 | public List queryOrder(); 13 | 14 | /** 15 | * 保存订单 16 | * @param order 17 | */ 18 | public void saveOrder(Order order); 19 | 20 | /** 21 | * 删除订单 22 | * @param orderid 23 | */ 24 | public void deleteOrder(Integer orderid); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.service; 2 | 3 | import com.bookshop.pojo.User; 4 | 5 | import java.util.List; 6 | 7 | public interface UserService { 8 | /** 9 | * 注册用户 10 | * @param user 11 | */ 12 | public void registUser(User user); 13 | 14 | /** 15 | * 登录 16 | * @param user 17 | * @return 如果返回null,说明登录失败,返回有值,是登录成功 18 | */ 19 | public List login(User user); 20 | 21 | /** 22 | * 检查 用户名是否可用 23 | * @param username 24 | * @return 返回true表示用户名已存在,返回false表示用户名可用 25 | */ 26 | public boolean existsUsername(String username); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/service/impl/BookSerbviceimpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @version 1.0 3 | */ 4 | 5 | 6 | package com.bookshop.service.impl; 7 | 8 | import com.bookshop.dao.BookDao; 9 | import com.bookshop.dao.impl.BookDaoImpl; 10 | import com.bookshop.pojo.Book; 11 | import com.bookshop.pojo.Page; 12 | import com.bookshop.service.BookService; 13 | 14 | import java.util.List; 15 | @SuppressWarnings("all") 16 | public class BookSerbviceimpl implements BookService { 17 | private BookDao bookDao = new BookDaoImpl(); 18 | 19 | @Override 20 | public void addBook(Book book) { 21 | bookDao.addBook(book); 22 | 23 | } 24 | 25 | @Override 26 | public void deleteBookById(Integer id) { 27 | bookDao.deleteBookById(id); 28 | } 29 | 30 | @Override 31 | public void updateBook(Book book) { 32 | bookDao.updateBook(book); 33 | } 34 | 35 | @Override 36 | public Book queryBookById(Integer id) { 37 | return bookDao.queryBookById(id); 38 | } 39 | 40 | @Override 41 | public List queryBooks() { 42 | return bookDao.queryBooks(); 43 | } 44 | 45 | @Override 46 | public Object queryValue() { 47 | return bookDao.queryValue(); 48 | } 49 | 50 | @Override 51 | public Page pageByPrice(int pageNo, int pageSize, int min, int max) {//做分页,数据量大的时候,不要一次性把所有数据都查出来,而是分页查询 52 | Page page = new Page(); 53 | 54 | // 设置每页显示的数量 55 | page.setPageSize(pageSize); 56 | // 求总记录数 57 | Integer pageTotalCount = bookDao.queryForPageTotalCountByPrice(min,max); 58 | // 设置总记录数 59 | page.setPageTotalCount(pageTotalCount); 60 | // 求总页码 61 | Integer pageTotal = pageTotalCount / pageSize; 62 | if (pageTotalCount % pageSize > 0) { 63 | pageTotal+=1; 64 | } 65 | // 设置总页码 66 | page.setPageTotal(pageTotal); 67 | 68 | // 设置当前页码 69 | page.setPageNo(pageNo); 70 | 71 | // 求当前页数据的开始索引 72 | int begin = (page.getPageNo() - 1) * pageSize; 73 | // 求当前页数据 74 | List items = bookDao.queryForPageItemsByPrice(begin,pageSize,min,max); 75 | // 设置当前页数据 76 | page.setItems(items); 77 | 78 | return page; 79 | 80 | } 81 | 82 | @Override 83 | public Page page(int pageNo, int pageSize) { 84 | Page page = new Page(); 85 | 86 | // 设置每页显示的数量 87 | page.setPageSize(pageSize); 88 | // 求总记录数 89 | Integer pageTotalCount = bookDao.queryForPageTotalCount(); 90 | // 设置总记录数 91 | page.setPageTotalCount(pageTotalCount); 92 | // 求总页码 93 | Integer pageTotal = pageTotalCount / pageSize; 94 | if (pageTotalCount % pageSize > 0) { 95 | pageTotal+=1; 96 | } 97 | // 设置总页码 98 | page.setPageTotal(pageTotal); 99 | // 设置当前页码 100 | page.setPageNo(pageNo); 101 | 102 | // 求当前页数据的开始索引 103 | int begin = (page.getPageNo() - 1) * pageSize; 104 | // 求当前页数据 105 | List items = bookDao.queryForPageItems(begin,pageSize); 106 | // 设置当前页数据 107 | page.setItems(items); 108 | 109 | return page; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/service/impl/CartItemSericeimpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @version 1.0 3 | */ 4 | 5 | 6 | package com.bookshop.service.impl; 7 | 8 | import com.bookshop.dao.CartItemDao; 9 | import com.bookshop.dao.impl.CartDaoItemImpl; 10 | import com.bookshop.pojo.CartItem; 11 | import com.bookshop.service.CartItemService; 12 | 13 | import java.util.List; 14 | 15 | @SuppressWarnings("all") 16 | public class CartItemSericeimpl implements CartItemService { 17 | 18 | private CartItemDao cartDao = new CartDaoItemImpl(); 19 | @Override 20 | public void addItem(CartItem cartItem) { 21 | cartDao.addItem(cartItem); 22 | 23 | } 24 | 25 | @Override 26 | public void deleteItem(Integer id,CartItem cartItem) { 27 | cartDao.deleteItem(id,cartItem); 28 | 29 | } 30 | 31 | @Override 32 | public void clear(CartItem cartItem) { 33 | cartDao.clear(cartItem); 34 | 35 | 36 | } 37 | 38 | @Override 39 | public void updateCount(Integer id, CartItem cartItem) { 40 | cartDao.updateCount(id,cartItem); 41 | 42 | 43 | } 44 | 45 | @Override 46 | public List queryCart(Integer userid) { 47 | return cartDao.queryCart(userid); 48 | } 49 | 50 | @Override 51 | public List queryCartid(Integer id) { 52 | return cartDao.queryCartid(id); 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/service/impl/CartServiceImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @version 1.0 3 | */ 4 | 5 | 6 | package com.bookshop.service.impl; 7 | 8 | 9 | import com.bookshop.dao.CartDao; 10 | import com.bookshop.dao.impl.CartDaoImpl; 11 | import com.bookshop.pojo.Cart; 12 | import com.bookshop.service.CartService; 13 | 14 | 15 | 16 | public class CartServiceImpl implements CartService { 17 | private CartDao cartDao = new CartDaoImpl(); 18 | 19 | @Override 20 | public Cart queryCart(Integer userid) { 21 | return cartDao.queryCart(userid); 22 | 23 | } 24 | 25 | @Override 26 | public boolean isExist(Integer userid) { 27 | return cartDao.isExist(userid); 28 | } 29 | 30 | 31 | 32 | 33 | } 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/service/impl/OrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author 何伟健 3 | * @version 1.0 4 | * @date 2023/6/3 23:29 5 | */ 6 | 7 | 8 | package com.bookshop.service.impl; 9 | 10 | import com.bookshop.dao.OrderDao; 11 | import com.bookshop.dao.impl.OrderDaoImpl; 12 | import com.bookshop.pojo.Order; 13 | import com.bookshop.service.OrderService; 14 | 15 | import java.util.List; 16 | 17 | public class OrderServiceImpl implements OrderService { 18 | 19 | private OrderDao orderDao = new OrderDaoImpl(); 20 | 21 | 22 | @Override 23 | public List queryOrder() { 24 | return orderDao.queryOrders(); 25 | } 26 | 27 | @Override 28 | public void saveOrder(Order order) { 29 | orderDao.saveOrder(order); 30 | } 31 | 32 | @Override 33 | public void deleteOrder(Integer orderid) { 34 | orderDao.deleteOrder(orderid); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.service.impl; 2 | 3 | import com.bookshop.dao.impl.UserDaoImpl; 4 | import com.bookshop.pojo.User; 5 | import com.bookshop.service.UserService; 6 | 7 | import java.util.List; 8 | 9 | public class UserServiceImpl implements UserService { 10 | 11 | private UserDaoImpl userDao = new UserDaoImpl(); 12 | 13 | @Override 14 | public void registUser(User user) { 15 | userDao.saveUser(user); 16 | } 17 | 18 | @Override 19 | public List login(User user) { 20 | return userDao.queryUserByUsernameAndPassword(user.getUsername(), user.getPassword()); 21 | } 22 | 23 | @Override 24 | public boolean existsUsername(String username) { 25 | if (userDao.queryUserByUsername(username) == null||userDao.queryUserByUsername(username).size() == 0) { 26 | return false; 27 | } 28 | return true; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/utils/JDBCUtilsByDruid.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.utils; 2 | 3 | import com.alibaba.druid.pool.DruidDataSourceFactory; 4 | import com.alibaba.druid.util.JdbcUtils; 5 | 6 | import javax.sql.DataSource; 7 | import java.io.InputStream; 8 | import java.sql.Connection; 9 | import java.sql.ResultSet; 10 | import java.sql.SQLException; 11 | import java.sql.Statement; 12 | import java.util.Properties; 13 | 14 | 15 | public class JDBCUtilsByDruid { 16 | 17 | private static DataSource ds; 18 | 19 | private static ThreadLocal conns = new ThreadLocal(); 20 | //在静态代码块完成 ds初始化 21 | static { 22 | Properties properties = new Properties(); 23 | try { 24 | InputStream is = JdbcUtils.class.getClassLoader().getResourceAsStream("jdbc.properties"); 25 | properties.load(is); 26 | ds = DruidDataSourceFactory.createDataSource(properties); 27 | } catch (Exception e) { 28 | e.printStackTrace(); 29 | } 30 | 31 | } 32 | 33 | /** 34 | * 获取数据库连接池中的连接 35 | * @return 如果返回null,说明获取连接失败
有值就是获取连接成功 36 | */ 37 | public static Connection getConnection() { 38 | Connection conn = null; 39 | 40 | try { 41 | conn = ds.getConnection(); 42 | } catch (Exception e) { 43 | e.printStackTrace(); 44 | } 45 | 46 | return conn; 47 | 48 | } 49 | /** 50 | * 提交事务,并关闭释放连接 51 | */ 52 | public static void commitAndClose(){ 53 | Connection connection = conns.get(); 54 | if (connection != null) { // 如果不等于null,说明 之前使用过连接,操作过数据库 55 | try { 56 | connection.commit(); // 提交 事务 57 | } catch (SQLException e) { 58 | e.printStackTrace(); 59 | } finally { 60 | try { 61 | connection.close(); // 关闭连接,资源资源 62 | } catch (SQLException e) { 63 | e.printStackTrace(); 64 | } 65 | } 66 | } 67 | // 一定要执行remove操作,否则就会出错。(因为Tomcat服务器底层使用了线程池技术) 68 | conns.remove(); 69 | } 70 | 71 | /** 72 | * 回滚事务,并关闭释放连接 73 | */ 74 | public static void rollbackAndClose(){ 75 | Connection connection = conns.get(); 76 | if (connection != null) { // 如果不等于null,说明 之前使用过连接,操作过数据库 77 | try { 78 | connection.rollback();//回滚事务 79 | } catch (SQLException e) { 80 | e.printStackTrace(); 81 | } finally { 82 | try { 83 | connection.close(); // 关闭连接,资源资源 84 | } catch (SQLException e) { 85 | e.printStackTrace(); 86 | } 87 | } 88 | } 89 | // 一定要执行remove操作,否则就会出错。(因为Tomcat服务器底层使用了线程池技术) 90 | conns.remove(); 91 | } 92 | 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/utils/WebUtils.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.utils; 2 | 3 | import org.apache.commons.beanutils.BeanUtils; 4 | 5 | import java.util.Map; 6 | 7 | public class WebUtils { 8 | /** 9 | * 把Map中的值注入到对应的JavaBean属性中。 10 | * @param value 11 | * @param bean 12 | */ 13 | public static T copyParamToBean( Map value , T bean ){//多个参数,但是只有一个返回值,也可以是一个参数,但是有多个返回值 14 | try { 15 | System.out.println("注入之前:" + bean); 16 | /** 17 | * 把所有请求的参数都注入到user对象中 18 | */ 19 | BeanUtils.populate(bean, value); 20 | System.out.println("注入之后:" + bean); 21 | } catch (Exception e) { 22 | throw new RuntimeException(e); 23 | } 24 | return bean; 25 | } 26 | /** 27 | * 将字符串转换成为int类型的数据 28 | * @param strInt 29 | * @param defaultValue 30 | * @return 31 | */ 32 | public static int parseInt(String strInt,int defaultValue) {//多个参数,但是只有一个返回值 33 | try { 34 | return Integer.parseInt(strInt); 35 | } catch (Exception e) { 36 | System.out.println("转换出错了"); 37 | 38 | } 39 | return defaultValue; 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/web/BaseServlet.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.web; 2 | 3 | import javax.servlet.ServletException; 4 | import javax.servlet.http.HttpServlet; 5 | import javax.servlet.http.HttpServletRequest; 6 | import javax.servlet.http.HttpServletResponse; 7 | import java.io.IOException; 8 | import java.lang.reflect.Method; 9 | 10 | public abstract class BaseServlet extends HttpServlet { 11 | 12 | protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 13 | //只可以获取提交的action的值 14 | String action = req.getParameter("action"); 15 | try { 16 | // 获取action业务鉴别字符串,获取相应的业务 方法反射对象 17 | Method method = this.getClass().getDeclaredMethod(action, HttpServletRequest.class, HttpServletResponse.class); 18 | method.invoke(this, req, resp); 19 | } catch (Exception e) { 20 | throw new RuntimeException(e); 21 | } 22 | } 23 | 24 | @Override 25 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 26 | doPost(req, resp); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/web/BookServlet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @version 1.0 3 | */ 4 | 5 | 6 | package com.bookshop.web; 7 | 8 | import com.bookshop.pojo.Book; 9 | import com.bookshop.pojo.Page; 10 | import com.bookshop.service.BookService; 11 | import com.bookshop.service.impl.BookSerbviceimpl; 12 | import com.bookshop.utils.WebUtils; 13 | 14 | import javax.servlet.ServletException; 15 | import javax.servlet.http.HttpServletRequest; 16 | import javax.servlet.http.HttpServletResponse; 17 | import java.io.IOException; 18 | import java.util.List; 19 | 20 | @SuppressWarnings("all") 21 | public class BookServlet extends BaseServlet{ 22 | 23 | private BookService bookService = new BookSerbviceimpl(); 24 | /* 25 | * @Description : 添加图书 26 | * @param req 27 | */ 28 | protected void add(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 29 | 30 | int pageNo = WebUtils.parseInt(req.getParameter("pageNo"),0); 31 | pageNo += 1; 32 | Book book = WebUtils.copyParamToBean(req.getParameterMap(),new Book()); 33 | bookService.addBook(book); 34 | resp.sendRedirect(req.getContextPath() + "/manager/bookServlet?action=page&pageNo=" + pageNo); 35 | } 36 | /* 37 | * @Description : 删除图书 38 | * @param req 39 | */ 40 | protected void delete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 41 | 42 | String id = req.getParameter("id"); 43 | int i = Integer.parseInt(id); 44 | bookService.deleteBookById(i); 45 | resp.sendRedirect(req.getContextPath() + "/manager/bookServlet?action=page&pageNo=" + req.getParameter("pageNo"));//重定向到图书列表页面 46 | } 47 | /* 48 | * @Description : 修改图书 49 | * @param req 50 | */ 51 | protected void update(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 52 | Book book = WebUtils.copyParamToBean(req.getParameterMap(),new Book());//获取请求的参数封装成为Book对象 53 | bookService.updateBook(book); 54 | resp.sendRedirect(req.getContextPath() + "/manager/bookServlet?action=page&pageNo=" + req.getParameter("pageNo"));//回到图书列表页面 55 | 56 | } 57 | /* 58 | * @Description : 获取图书列表 59 | * @param req 60 | */ 61 | protected void get(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 62 | int id = WebUtils.parseInt(req.getParameter("id"), 0); 63 | Book book = bookService.queryBookById(id); 64 | req.setAttribute("book", book) ; 65 | req.getRequestDispatcher("/pages/manager/book_edit.jsp").forward(req,resp); 66 | } 67 | /* 68 | * @Description : 获取图书列表 69 | * @param req 70 | */ 71 | protected void list(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 72 | List books = bookService.queryBooks(); 73 | req.setAttribute("books",books); 74 | req.getRequestDispatcher("/pages/manager/book_manager.jsp").forward(req,resp); 75 | } 76 | /* 77 | * @Description : 分页 78 | * @param req 79 | */ 80 | protected void page(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{ 81 | int pageNo = WebUtils.parseInt(req.getParameter("pageNo"), 1); 82 | int pageSize = WebUtils.parseInt(req.getParameter("pageSize"), Page.PAGE_SIZE); 83 | Page page = bookService.page(pageNo,pageSize); 84 | page.setUrl("manager/bookServlet?action=page"); 85 | req.setAttribute("page",page); 86 | req.getRequestDispatcher("/pages/manager/book_manager.jsp").forward(req,resp); 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/web/CartServlet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @version 1.0 3 | */ 4 | 5 | 6 | package com.bookshop.web; 7 | 8 | 9 | import com.bookshop.pojo.Book; 10 | import com.bookshop.pojo.Cart; 11 | import com.bookshop.pojo.CartItem; 12 | import com.bookshop.pojo.User; 13 | import com.bookshop.service.BookService; 14 | import com.bookshop.service.CartItemService; 15 | import com.bookshop.service.CartService; 16 | import com.bookshop.service.impl.BookSerbviceimpl; 17 | import com.bookshop.service.impl.CartItemSericeimpl; 18 | import com.bookshop.service.impl.CartServiceImpl; 19 | import com.bookshop.utils.WebUtils; 20 | 21 | import javax.servlet.ServletException; 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.servlet.http.HttpServletResponse; 24 | import java.io.IOException; 25 | import java.util.List; 26 | 27 | @SuppressWarnings("all") 28 | public class CartServlet extends BaseServlet{ 29 | private BookService bookService = new BookSerbviceimpl(); 30 | private CartItemService cartService = new CartItemSericeimpl(); 31 | private CartService cartcar= new CartServiceImpl(); 32 | private CartItem cartItem = new CartItem(); 33 | private User user = new User(); 34 | private Cart cart = new Cart(); 35 | 36 | 37 | /** 38 | * 添加商品项到购物车 39 | * @param req 40 | * @param resp 41 | * @throws ServletException 42 | * @throws IOException 43 | */ 44 | protected void addItem(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 45 | 46 | int id = WebUtils.parseInt(req.getParameter("id"), 0); 47 | Book book = bookService.queryBookById(id); 48 | user = (User) req.getSession().getAttribute("user"); 49 | int userid = user.getId(); 50 | cartItem =new CartItem(book.getId(),book.getName(),1,book.getPrice(),userid); 51 | CartItem cartid = WebUtils.copyParamToBean(req.getParameterMap(), cartItem); 52 | 53 | req.getSession().setAttribute("lastName",cartid.getName()); 54 | 55 | if (cartcar.isExist(userid)){ 56 | cartService.addItem(cartid); 57 | }else { 58 | cartService.addItem(cartid); 59 | } 60 | Cart count = cartcar.queryCart(userid); 61 | req.getSession().setAttribute("totalCount",count.getTotalCount()); 62 | 63 | resp.sendRedirect(req.getHeader("Referer")); 64 | 65 | } 66 | 67 | /** 68 | * 删除购物车商品项 69 | * @param req 70 | * @param resp 71 | * @throws ServletException 72 | * @throws IOException 73 | */ 74 | protected void deleteItem(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 75 | int id = WebUtils.parseInt(req.getParameter("id"), 0); 76 | user = (User) req.getSession().getAttribute("user"); 77 | int userid = user.getId(); 78 | List cartItemsid = cartService.queryCartid(id); 79 | cartItem= new CartItem(cartItemsid.get(0).getCount(),cartItemsid.get(0).getPrice(),userid); 80 | cartService.deleteItem(id,cartItem); 81 | resp.sendRedirect(req.getHeader("Referer")); 82 | } 83 | 84 | /** 85 | * 清空购物车 86 | * @param req 87 | * @param resp 88 | * @throws ServletException 89 | * @throws IOException 90 | */ 91 | protected void clearItem(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 92 | user = (User) req.getSession().getAttribute("user"); 93 | int userid = user.getId(); 94 | cartItem= new CartItem(userid); 95 | cartService.clear(cartItem); 96 | resp.sendRedirect(req.getHeader("Referer")); 97 | } 98 | /** 99 | * 修改购物车商品项数量 100 | * @param req 101 | * @param resp 102 | * @throws ServletException 103 | * @throws IOException 104 | */ 105 | protected void updateCount(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 106 | int id = WebUtils.parseInt(req.getParameter("id"), 0); 107 | user = (User) req.getSession().getAttribute("user"); 108 | int userid = user.getId(); 109 | List cartItemsid = cartService.queryCartid(id); 110 | cartItemsid.get(0).setCount(WebUtils.parseInt(req.getParameter("count"), 1)); 111 | //修改商品价格 112 | int price = WebUtils.parseInt(req.getParameter("price"), 1); 113 | cartItem= new CartItem(cartItemsid.get(0).getCount(),cartItemsid.get(0).getPrice(),userid); 114 | cartService.updateCount(id,cartItem); 115 | resp.sendRedirect(req.getHeader("Referer")); 116 | } 117 | /** 118 | * 展示购物车商品 信息 119 | * @param req 120 | * @param resp 121 | * @throws ServletException 122 | * @throws IOException 123 | */ 124 | protected void showCart(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 125 | user = (User) req.getSession().getAttribute("user"); 126 | int userid = user.getId(); 127 | //获取购物车商品信息 128 | List cartItems = cartService.queryCart(userid); 129 | //获取购物车总金额与总数量 130 | Cart runcar = cartcar.queryCart(userid); 131 | req.setAttribute("cartItems", cartItems); 132 | req.setAttribute("runcar", runcar); 133 | req.getRequestDispatcher("/pages/cart/cart.jsp").forward(req, resp); 134 | 135 | } 136 | /** 137 | * 结算购物车商品 138 | * @param req 139 | * @param resp 140 | * @throws ServletException 141 | * @throws IOException 142 | */ 143 | protected void checkout(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 144 | user = (User) req.getSession().getAttribute("user"); 145 | int userid = user.getId(); 146 | //获取购物车商品信息 147 | List cartItems = cartService.queryCart(userid); 148 | //获取购物车总金额与总数量 149 | Cart runcar = cartcar.queryCart(userid); 150 | req.setAttribute("cartItems", cartItems); 151 | req.setAttribute("runcar", runcar); 152 | req.getRequestDispatcher("/pages/cart/checkout.jsp").forward(req, resp); 153 | } 154 | 155 | } 156 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/web/ClientBookServlet.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.web; 2 | 3 | import com.bookshop.pojo.Book; 4 | import com.bookshop.pojo.Page; 5 | import com.bookshop.service.BookService; 6 | 7 | import com.bookshop.service.impl.BookSerbviceimpl; 8 | import com.bookshop.utils.WebUtils; 9 | 10 | import javax.servlet.ServletException; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | import java.io.IOException; 14 | 15 | public class ClientBookServlet extends BaseServlet { 16 | 17 | private BookService bookService = new BookSerbviceimpl(); 18 | 19 | /** 20 | * 处理分页功能 21 | * @param req 22 | * @param resp 23 | * @throws ServletException 24 | * @throws IOException 25 | */ 26 | protected void page(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 27 | int pageNo = WebUtils.parseInt(req.getParameter("pageNo"), 1); 28 | int pageSize = WebUtils.parseInt(req.getParameter("pageSize"), Page.PAGE_SIZE); 29 | Page page = bookService.page(pageNo,pageSize); 30 | page.setUrl("client/bookServlet?action=page"); 31 | req.setAttribute("page",page); 32 | req.getRequestDispatcher("/pages/client/index.jsp").forward(req,resp); 33 | } 34 | /** 35 | * 处理分页功能 36 | * @param req 37 | * @param resp 38 | * @throws ServletException 39 | * @throws IOException 40 | */ 41 | protected void pageByPrice(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 42 | int pageNo = WebUtils.parseInt(req.getParameter("pageNo"), 1); 43 | int pageSize = WebUtils.parseInt(req.getParameter("pageSize"), Page.PAGE_SIZE); 44 | int min = WebUtils.parseInt(req.getParameter("min"), 0); 45 | int max = WebUtils.parseInt(req.getParameter("max"), Integer.MAX_VALUE); 46 | 47 | Page page = bookService.pageByPrice(pageNo,pageSize,min,max); 48 | 49 | StringBuilder sb = new StringBuilder("client/bookServlet?action=pageByPrice"); 50 | if (req.getParameter("min") != null) { 51 | sb.append("&min=").append(req.getParameter("min")); 52 | } 53 | if (req.getParameter("max") != null) { 54 | sb.append("&max=").append(req.getParameter("max")); 55 | } 56 | page.setUrl(sb.toString()); 57 | req.setAttribute("page",page); 58 | req.getRequestDispatcher("/pages/client/index.jsp").forward(req,resp); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/web/OrderServlet.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.web; 2 | 3 | import com.bookshop.pojo.Order; 4 | import com.bookshop.pojo.User; 5 | import com.bookshop.service.OrderService; 6 | import com.bookshop.service.impl.OrderServiceImpl; 7 | import com.bookshop.utils.WebUtils; 8 | 9 | import javax.servlet.ServletException; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | import javax.servlet.http.HttpSession; 13 | import java.io.IOException; 14 | import java.util.List; 15 | import java.util.Random; 16 | 17 | 18 | public class OrderServlet extends BaseServlet { 19 | private OrderService orderService = new OrderServiceImpl(); 20 | private static int orderCount = 0; 21 | 22 | /** 23 | * 生成订单 24 | * 25 | * @param req 26 | * @param resp 27 | * @throws ServletException 28 | * @throws IOException 29 | */ 30 | protected void createOrder(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 31 | 32 | 33 | User loginUser = (User) req.getSession().getAttribute("user"); 34 | 35 | if (loginUser == null) { 36 | req.getRequestDispatcher("/pages/user/login.jsp").forward(req, resp); 37 | return; 38 | } 39 | 40 | 41 | int userId = loginUser.getId(); 42 | String orderNumber = generateOrderNumber(); 43 | int orderNumberInt = Integer.parseInt(orderNumber); 44 | 45 | Order order = new Order(orderNumberInt, userId); 46 | orderService.saveOrder(order); 47 | req.getSession().setAttribute("orderNumberInt", orderNumberInt); 48 | resp.sendRedirect(req.getContextPath() + "/pages/cart/checkout.jsp"); 49 | } 50 | 51 | /** 52 | * 查看所有订单 53 | * 54 | * @param req 55 | * @param resp 56 | * @throws ServletException 57 | * @throws IOException 58 | */ 59 | protected void showAllOrders(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 60 | List orders = orderService.queryOrder(); 61 | req.setAttribute("orders", orders); 62 | req.getRequestDispatcher("/pages/manager/order.jsp").forward(req, resp); 63 | } 64 | /** 65 | * 查看所有订单 66 | * 67 | * @param req 68 | * @param resp 69 | * @throws ServletException 70 | * @throws IOException 71 | */ 72 | 73 | protected void deleteOrder(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 74 | String id = req.getParameter("id"); 75 | int i = Integer.parseInt(id); 76 | orderService.deleteOrder(i); 77 | resp.sendRedirect(req.getContextPath() + "/pages/cart/cart.jsp"); 78 | } 79 | 80 | public static synchronized String generateOrderNumber() { 81 | Random random = new Random(); 82 | StringBuilder sb = new StringBuilder(); 83 | 84 | for (int i = 0; i < 9; i++) { 85 | int digit = random.nextInt(10); 86 | sb.append(digit); 87 | } 88 | 89 | return sb.toString(); 90 | } 91 | 92 | 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/com/bookshop/web/UserServlet.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.web; 2 | 3 | import com.bookshop.pojo.User; 4 | import com.bookshop.service.UserService; 5 | import com.bookshop.service.impl.UserServiceImpl; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | import java.util.List; 12 | 13 | import static com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY; 14 | 15 | @SuppressWarnings("all") 16 | public class UserServlet extends BaseServlet { 17 | 18 | private UserService userService = new UserServiceImpl(); 19 | 20 | /** 21 | * 注销登录 22 | * @param req 23 | * @param resp 24 | * @throws ServletException 25 | * @throws IOException 26 | */ 27 | protected void loginout(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 28 | req.getSession().invalidate(); 29 | resp.sendRedirect(req.getContextPath()); 30 | } 31 | 32 | /** 33 | * 处理登录的功能 34 | * 35 | * @param req 36 | * @param resp 37 | * @throws ServletException 38 | * @throws IOException 39 | */ 40 | protected void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 41 | String username = req.getParameter("username"); 42 | String password = req.getParameter("password"); 43 | List login = userService.login(new User(null, username, password, null)); 44 | if (login != null&&login.size() != 0) { 45 | req.getSession().setAttribute("user", login.get(0)); 46 | req.getRequestDispatcher("/pages/user/login_success.jsp").forward(req, resp); 47 | } else { 48 | req.setAttribute("username", username); 49 | req.setAttribute("errormsg","用户名或密码错误");//错误信息 50 | req.getRequestDispatcher("/pages/user/login.jsp").forward(req, resp); 51 | } 52 | 53 | } 54 | 55 | /** 56 | * 处理注册的功能 57 | * 58 | * @param req 59 | * @param resp 60 | * @throws ServletException 61 | * @throws IOException 62 | */ 63 | protected void regist(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 64 | String username = req.getParameter("username"); 65 | String password = req.getParameter("password"); 66 | String email = req.getParameter("email"); 67 | String code = req.getParameter("code"); 68 | // 获取Session中的验证码 69 | String token = (String) req.getSession().getAttribute(KAPTCHA_SESSION_KEY); 70 | // 删除 Session中的验证码 71 | req.getSession().removeAttribute(KAPTCHA_SESSION_KEY); 72 | 73 | // 获取用户名 74 | if (token != null && token.equalsIgnoreCase(code)) { 75 | if (userService.existsUsername(username)) { 76 | req.setAttribute("errormsg", "用户名已存在"); 77 | req.setAttribute("username", username); 78 | req.setAttribute("email", email); 79 | req.getRequestDispatcher("/pages/user/regist.jsp").forward(req, resp); 80 | } else { 81 | userService.registUser(new User(null, username, password, email)); 82 | req.getRequestDispatcher("/pages/user/regist_success.jsp").forward(req, resp); 83 | } 84 | } else { 85 | System.out.println("验证码[" + code + "]错误"); 86 | req.setAttribute("errormsg", "验证码错误"); 87 | req.setAttribute("username", username); 88 | req.setAttribute("email", email); 89 | req.getRequestDispatcher("/pages/user/regist.jsp").forward(req, resp); 90 | } 91 | } 92 | 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/com/example/book/HelloServlet.java: -------------------------------------------------------------------------------- 1 | package com.example.book; 2 | 3 | import java.io.*; 4 | import javax.servlet.http.*; 5 | import javax.servlet.annotation.*; 6 | 7 | @WebServlet(name = "helloServlet", value = "/hello-servlet") 8 | public class HelloServlet extends HttpServlet { 9 | private String message; 10 | 11 | public void init() { 12 | message = "Hello World!"; 13 | } 14 | 15 | public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { 16 | response.setContentType("text/html"); 17 | 18 | // Hello 19 | PrintWriter out = response.getWriter(); 20 | out.println(""); 21 | out.println("

" + message + "

"); 22 | out.println(""); 23 | } 24 | 25 | public void destroy() { 26 | } 27 | } -------------------------------------------------------------------------------- /src/main/resources/jdbc.properties: -------------------------------------------------------------------------------- 1 | #key=value 2 | driverClassName=com.mysql.jdbc.Driver 3 | url=jdbc:mysql://localhost:3306/book?rewriteBatchedStatements=true 4 | username=root 5 | password=123456 6 | #initial connection Size 7 | initialSize=10 8 | #min idle connecton size 9 | minIdle=5 10 | #max active connection size 11 | maxActive=50 12 | #max wait time (5000 mil seconds) 13 | maxWait=5000 -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/lib/commons-beanutils-1.8.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/WEB-INF/lib/commons-beanutils-1.8.0.jar -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/lib/commons-dbutils-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/WEB-INF/lib/commons-dbutils-1.3.jar -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/lib/commons-logging-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/WEB-INF/lib/commons-logging-1.1.1.jar -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/lib/druid-1.1.10.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/WEB-INF/lib/druid-1.1.10.jar -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/lib/hamcrest-core-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/WEB-INF/lib/hamcrest-core-1.3.jar -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/lib/junit-4.12.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/WEB-INF/lib/junit-4.12.jar -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/lib/kaptcha-2.3.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/WEB-INF/lib/kaptcha-2.3.2.jar -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/lib/mysql-connector-java-5.1.37-bin.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/WEB-INF/lib/mysql-connector-java-5.1.37-bin.jar -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/lib/taglibs-standard-impl-1.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/WEB-INF/lib/taglibs-standard-impl-1.2.1.jar -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/lib/taglibs-standard-spec-1.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/WEB-INF/lib/taglibs-standard-spec-1.2.1.jar -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | userServlet 9 | com.bookshop.web.UserServlet 10 | 11 | 12 | userServlet 13 | /userServlet 14 | 15 | 16 | 17 | bookServlet 18 | com.bookshop.web.BookServlet 19 | 20 | 21 | bookServlet 22 | /manager/bookServlet 23 | 24 | 25 | 26 | 27 | ClientBookServlet 28 | com.bookshop.web.ClientBookServlet 29 | 30 | 31 | ClientBookServlet 32 | /client/bookServlet 33 | 34 | 35 | 36 | 37 | KaptchaServlet 38 | com.google.code.kaptcha.servlet.KaptchaServlet 39 | 40 | 41 | 42 | 43 | KaptchaServlet 44 | /kaptcha.jpg 45 | 46 | 47 | 48 | CartServlet 49 | com.bookshop.web.CartServlet 50 | 51 | 52 | CartServlet 53 | /client/cartServlet 54 | 55 | 56 | 57 | 58 | OrderServlet 59 | com.bookshop.web.OrderServlet 60 | 61 | 62 | OrderServlet 63 | /orderServlet 64 | 65 | 66 | 67 | TransactionFilter 68 | com.bookshop.filter.TransactionFilter 69 | 70 | 71 | TransactionFilter 72 | /* 73 | 74 | 75 | 76 | ManagerFilter 77 | com.bookshop.filter.ManagerFilter 78 | 79 | 80 | ManagerFilter 81 | /pages/manager/* 82 | /manager/bookServlet 83 | 84 | 85 | 86 | 87 | 500 88 | /pages/error/error500.jsp 89 | 90 | 91 | 92 | 404 93 | /pages/error/error404.jsp 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | -------------------------------------------------------------------------------- /src/main/webapp/pages/cart/cart.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 购物车 8 | 9 | <%@ include file="/pages/common/head.jsp"%> 10 | 11 | 12 | 13 | 14 | 46 | 47 |
48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 70 | 71 | 72 | 73 | 74 | 75 | 76 |
商品名称数量单价金额操作
亲,当前购物车为空!快跟小伙伴们去浏览商品吧!!!
${entry.name} 67 | 69 | ${entry.price}${entry.price*entry.count}删除
77 | <%--如果购物车非空才输出页面的内容--%> 78 | 79 |
80 | 购物车中共有${requestScope.runcar.totalCount}件商品 81 | 总金额${requestScope.runcar.totalPrice} 82 | 清空购物车 83 | 一键结账 84 |
85 |
86 | 87 |
88 | 购物车中件商品 89 | 快去选购吧 90 |
91 |
92 | 93 |
94 | 查看订单 95 |
96 | 97 | 98 |
99 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /src/main/webapp/pages/cart/checkout.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 订单页面 8 | <%@include file="/pages/common/head.jsp"%> 9 | 37 | 52 | 53 | 54 | 55 | 60 | 61 |
62 |

你的订单已结算,订单号为:${sessionScope.orderNumberInt}

63 | 64 |
65 | 退款 66 |
67 |
68 |
69 | 70 |
71 |

你还没有订单

72 |
73 |
74 | 75 | 76 | 79 | 80 | -------------------------------------------------------------------------------- /src/main/webapp/pages/client/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 书城首页 8 | 9 | <%@ include file="/pages/common/head.jsp"%> 10 | 23 | 24 | 25 | 26 | 27 | 28 | 43 | 44 |
45 |
46 | 47 |
48 |
49 | 50 | 价格: 元 - 51 | 元 52 | 53 |
54 |
55 |
56 |
57 | 58 | 您的购物车中有${totalCount}件商品 59 |
60 | 您刚刚将${lastName}加入到了购物车中 61 |
62 |
63 | 64 | 您还没有登录,不能查看购物车 65 | 66 |
67 | 68 | 69 |
70 |
71 | 72 |
73 |
74 |
75 | 书名: 76 | ${book.name} 77 |
78 |
79 | 作者: 80 | ${book.author} 81 |
82 |
83 | 价格: 84 | ${book.price} 85 |
86 |
87 | 销量: 88 | ${book.sales} 89 |
90 |
91 | 库存: 92 | ${book.stock} 93 |
94 |
95 | 96 |
97 |
98 |
99 |
100 |
101 | 102 | 103 |
104 | 您还没有登录,请先登录 105 |
106 |
107 | 108 |
109 | 110 | 111 | <%@include file="/pages/common/page_nav.jsp"%> 112 | 113 | 114 |
115 | 116 |
117 |
118 | 119 | 120 | 121 | 122 | 123 |
124 | 125 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /src/main/webapp/pages/common/footer.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 |
3 | 4 | 易书城.Copyright ©2023 5 | 6 |
7 | -------------------------------------------------------------------------------- /src/main/webapp/pages/common/head.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | <% 3 | String basePath = request.getScheme()//获取协议 4 | + "://" 5 | + request.getServerName()//获取服务器地址 6 | + ":" 7 | + request.getServerPort()//获取端口号 8 | + request.getContextPath()//获取项目名称 9 | + "/"; 10 | pageContext.setAttribute("basePath",basePath); 11 | %> 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/main/webapp/pages/common/login_success_menu.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 |
4 | 欢迎${sessionScope.user.username}光临易书城 5 | 注销   6 | 返回 7 |
-------------------------------------------------------------------------------- /src/main/webapp/pages/common/manager_menu.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | -------------------------------------------------------------------------------- /src/main/webapp/pages/common/page_nav.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | <%--分页条的开始--%> 4 | 82 | <%--分页条的结束--%> 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/main/webapp/pages/error/error404.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 404 - Page Not Found 8 | 9 | <%-- 静态包含 base标签、css样式、jQuery文件 --%> 10 | <%@ include file="/pages/common/head.jsp"%> 11 | 12 | 42 | 43 | 44 | 45 |
46 |

404 - Page Not Found

47 |

很抱歉,您请求的页面未找到,请确认您输入的URL是否正确。


48 |

或者访问的页面不存在,或已经被删除!!!

49 |

返回首页

50 |
51 | 52 | 53 | -------------------------------------------------------------------------------- /src/main/webapp/pages/error/error500.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 500 - Internal Server Error 8 | 9 | <%-- 静态包含 base标签、css样式、jQuery文件 --%> 10 | <%@ include file="/pages/common/head.jsp"%> 11 | 12 | 42 | 43 | 44 | 45 |
46 |

500 - Internal Server Error

47 |

很抱歉,您访问的后台程序出现了错误,程序猿小哥,正在努力的为您抢修!!!

48 |

返回首页

49 |
50 | 51 | 52 | -------------------------------------------------------------------------------- /src/main/webapp/pages/manager/book_edit.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 编辑图书 8 | <%@include file="/pages/common/head.jsp"%> 9 | 23 | 24 | 25 | 35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
名称价格作者销量库存操作
60 |
61 | 62 | 63 |
64 | 65 | 68 | 69 | -------------------------------------------------------------------------------- /src/main/webapp/pages/manager/book_manager.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 图书管理 8 | <%@include file="/pages/common/head.jsp"%> 9 | 24 | 25 | 26 | 27 | 34 | 35 |
36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
名称价格作者销量库存操作
${book.name}${book.price}${book.author}${book.sales}${book.stock}删除修改
添加图书
70 | <%@include file="/pages/common/page_nav.jsp"%> 71 |
72 | 73 | 76 | 77 | -------------------------------------------------------------------------------- /src/main/webapp/pages/manager/manager.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 5 | 6 | 后台管理 7 | <%@include file="/pages/common/head.jsp"%> 8 | 14 | 15 | 16 | 17 | 22 | 23 |
24 |

欢迎管理员进入后台管理系统

25 |
26 | 27 | 30 | 31 | -------------------------------------------------------------------------------- /src/main/webapp/pages/manager/order.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 订单管理 8 | <%@ include file="/pages/common/head.jsp"%> 9 | 10 | 16 | 17 | 27 | 28 | 29 | 30 | 31 | 36 | 37 |
38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 55 | 56 | 57 |
订单号用户ID状态操作
${order.orderid}${order.userid}未发货 53 | 54 |
58 |
59 | 60 |

暂无订单

61 |
62 |
63 | 64 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /src/main/webapp/pages/user/login.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 5 | 6 | 易书城会员登录页面 7 | <%@include file="/pages/common/head.jsp"%> 8 | 9 | 10 |
11 | 12 |
13 | 14 | 55 | 58 | 59 | -------------------------------------------------------------------------------- /src/main/webapp/pages/user/login_success.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 | 4 | 5 | 6 | 7 | 易书城会员登录成功页面 8 | <%@include file="/pages/common/head.jsp"%> 9 | 19 | 20 | 21 | 25 | 26 |
27 | 28 |

欢迎回来 转到主页

29 |
30 | 31 |

请管理员转入后台管理

32 |
33 | 34 |
35 | 36 | 39 | 40 | -------------------------------------------------------------------------------- /src/main/webapp/pages/user/regist.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 5 | 6 | 易书城会员注册页面 7 | 8 | <%@include file="/pages/common/head.jsp"%> 9 | 69 | 76 | 77 | 78 |
79 | 80 |
81 | 82 | 138 | 141 | 142 | -------------------------------------------------------------------------------- /src/main/webapp/pages/user/regist_success.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 5 | 6 | 易书城会员注册成功页面 7 | <%@include file="/pages/common/head.jsp"%> 8 | 19 | 20 | 21 | 22 | 27 | 28 |
29 |

注册成功! 转到主页

30 |
31 | 32 | 35 | 36 | -------------------------------------------------------------------------------- /src/main/webapp/static/css/style.css: -------------------------------------------------------------------------------- 1 | @CHARSET "UTF-8"; 2 | 3 | body { 4 | overflow: hidden; 5 | } 6 | 7 | * { 8 | margin: 0; 9 | font-family:"Microsoft Yahei"; 10 | color: #666; 11 | } 12 | 13 | div{ 14 | margin: auto; 15 | margin-bottom: 10px; 16 | margin-top: 10px; 17 | 18 | } 19 | 20 | #header { 21 | height: 82px; 22 | width: 1200px; 23 | } 24 | 25 | #main { 26 | height: 600px; 27 | width: 1200px; 28 | border: 1px black solid; 29 | overflow: auto; 30 | position: absolute; 31 | top: 50%; 32 | left: 50%; 33 | transform: translate(-50%, -50%); 34 | } 35 | #footer { 36 | position: absolute; 37 | bottom: 0; 38 | right: 0; 39 | } 40 | 41 | 42 | #bottom { 43 | height: 30px; 44 | width: 1200px; 45 | text-align: center; 46 | } 47 | 48 | #book{ 49 | width: 100%; 50 | height: 90%; 51 | margin: auto; 52 | 53 | } 54 | 55 | .b_list{ 56 | height:300px; 57 | width:250px; 58 | margin: 20px; 59 | float: left; 60 | margin-top:0px; 61 | margin-bottom:0px; 62 | border: 1px #e3e3e3 solid; 63 | } 64 | 65 | #page_nav{ 66 | width: 100%; 67 | height: 10px; 68 | margin: auto; 69 | 70 | text-align: center; 71 | } 72 | 73 | #pn_input { 74 | width: 30px; 75 | text-align: center; 76 | } 77 | 78 | .img_div{ 79 | height: 150px; 80 | text-align: center; 81 | } 82 | 83 | .book_img { 84 | height:150px; 85 | width:150px; 86 | } 87 | 88 | .book_info { 89 | 90 | text-align: center; 91 | } 92 | 93 | .book_info div{ 94 | height: 10px; 95 | width: 300px; 96 | text-align: left; 97 | } 98 | 99 | .wel_word{ 100 | font-size: 60px; 101 | float: left; 102 | } 103 | 104 | .logo_img{ 105 | float: left; 106 | } 107 | 108 | #header div a { 109 | text-decoration: none; 110 | font-size: 20px; 111 | } 112 | 113 | #header div{ 114 | float: right; 115 | margin-top: 55px; 116 | } 117 | 118 | .book_cond{ 119 | margin-left: 500px; 120 | } 121 | 122 | .book_cond input{ 123 | width: 50px; 124 | text-align: center; 125 | } 126 | 127 | 128 | /*登录页面CSS样式 */ 129 | 130 | #login_header{ 131 | height: 82px; 132 | width: 1200px; 133 | } 134 | 135 | .login_banner{ 136 | height:475px; 137 | background-color: #39987c; 138 | } 139 | 140 | .login_form{ 141 | height:310px; 142 | width:406px; 143 | float: right; 144 | margin-right:50px; 145 | margin-top: 50px; 146 | background-color: #fff; 147 | } 148 | 149 | #content { 150 | height: 475px; 151 | width: 1200px; 152 | } 153 | 154 | .login_box{ 155 | margin: 20px; 156 | height: 260px; 157 | width: 366px; 158 | } 159 | 160 | h1 { 161 | font-size: 20px; 162 | } 163 | .msg_cont{ 164 | background: none repeat scroll 0 0 #fff6d2; 165 | border: 1px solid #ffe57d; 166 | color: #666; 167 | height: 18px; 168 | line-height: 18px; 169 | padding: 3px 10px 3px 40px; 170 | position: relative; 171 | border: none; 172 | } 173 | 174 | .msg_cont b { 175 | background: url("../img/pwd-icons-new.png") no-repeat scroll -104px -22px rgba(0, 0, 0, 0); 176 | display: block; 177 | height: 17px; 178 | left: 10px; 179 | margin-top: -8px; 180 | overflow: hidden; 181 | position: absolute; 182 | top: 50%; 183 | width: 16px; 184 | } 185 | 186 | .form .itxt { 187 | border: 0 none; 188 | float: none; 189 | font-family: "宋体"; 190 | font-size: 14px; 191 | height: 18px; 192 | line-height: 18px; 193 | overflow: hidden; 194 | padding: 10px 0 10px 10px; 195 | width: 220px; 196 | border: 1px #e3e3e3 solid; 197 | } 198 | 199 | #sub_btn{ 200 | background-color: #39987c; 201 | border: none; 202 | color: #fff; 203 | width: 360px; 204 | height: 40px; 205 | } 206 | 207 | #l_content { 208 | float: left; 209 | margin-top: 150px; 210 | margin-left: 300px; 211 | } 212 | 213 | #l_content span { 214 | font-size: 60px; 215 | color: white; 216 | } 217 | 218 | .tit h1 { 219 | float: left; 220 | margin-top: 5px; 221 | } 222 | 223 | .tit a { 224 | float: right; 225 | margin-left: 10px; 226 | margin-top: 10px; 227 | color: red; 228 | text-decoration: none; 229 | } 230 | 231 | .tit .errorMsg { 232 | float: right; 233 | margin-left: 10px; 234 | margin-top: 10px; 235 | color: red; 236 | } 237 | 238 | .tit { 239 | height: 30px; 240 | } 241 | /*购物车*/ 242 | #main table{ 243 | margin: auto; 244 | margin-top: 80px; 245 | border-collapse: collapse; 246 | } 247 | 248 | #main table td{ 249 | width: 120px; 250 | text-align:center; 251 | border-bottom: 1px #e3e3e3 solid; 252 | padding: 10px; 253 | } 254 | 255 | .cart_info{ 256 | width: 700px; 257 | text-align: right; 258 | } 259 | 260 | .cart_span { 261 | margin-left: 20px; 262 | } 263 | 264 | .cart_span span{ 265 | color: red; 266 | font-size: 20px; 267 | margin: 10px; 268 | } 269 | 270 | .cart_span a , td a{ 271 | font-size: 20px; 272 | color: blue; 273 | } 274 | 275 | #header div span { 276 | margin: 10px; 277 | } 278 | 279 | #header div .um_span{ 280 | color: red; 281 | font-size: 25px; 282 | margin: 10px; 283 | } 284 | 285 | #header div a { 286 | color: blue; 287 | } 288 | -------------------------------------------------------------------------------- /src/main/webapp/static/img/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/1.gif -------------------------------------------------------------------------------- /src/main/webapp/static/img/ajax.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/ajax.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/default.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/flash1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/flash1.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/java1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/java1.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/java10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/java10.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/java11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/java11.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/java2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/java2.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/java3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/java3.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/java4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/java4.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/java5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/java5.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/java6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/java6.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/java7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/java7.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/java8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/java8.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/java9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/java9.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/javascript.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/javascript.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/javascript2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/javascript2.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/javaweb1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/javaweb1.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/javaweb2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/javaweb2.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/javaweb3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/javaweb3.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/javaweb4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/javaweb4.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/junit.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/junit.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/log.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/log.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/logo.gif -------------------------------------------------------------------------------- /src/main/webapp/static/img/node.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/node.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/osgi1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/osgi1.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/osgi2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/osgi2.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/pwd-icons-new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/pwd-icons-new.png -------------------------------------------------------------------------------- /src/main/webapp/static/img/spring1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/spring1.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/spring2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/spring2.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/tomcat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heweijiqn/bookshop-JavaWeb/6c6d25a480cce2722b8f759af1db0c5b2e99fed7/src/main/webapp/static/img/tomcat.jpg -------------------------------------------------------------------------------- /src/test/java/com/bookshop/dao/impl/BookDaoImplTest.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.dao.impl; 2 | 3 | import com.bookshop.dao.BookDao; 4 | import com.bookshop.pojo.Book; 5 | import com.bookshop.pojo.Page; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import java.math.BigDecimal; 9 | 10 | class BookDaoImplTest { 11 | 12 | private BookDao bookDao = new BookDaoImpl(); 13 | 14 | /* 15 | * 1.添加图书 16 | */ 17 | @Test 18 | void addBook() { 19 | bookDao.addBook(new Book(null,"为什么这么帅!", "191125", new BigDecimal(9999),1100000,0,null)); 20 | 21 | } 22 | /* 23 | * 2.删除图书 24 | */ 25 | 26 | @Test 27 | void deleteBookById() { 28 | bookDao.deleteBookById(21); 29 | } 30 | /* 31 | * 3.修改图书 32 | */ 33 | @Test 34 | void updateBook() { 35 | bookDao.updateBook(new Book(21,"这么帅!", "国哥", new BigDecimal(9999),1100000,0,null)); 36 | } 37 | 38 | /* 39 | * 4.查询图书 40 | */ 41 | @Test 42 | void queryBookById() { 43 | System.out.println( bookDao.queryBookById(21) ); 44 | } 45 | 46 | /* 47 | * 5.查询所有图书 48 | */ 49 | @Test 50 | void queryBooks() { 51 | for (Book queryBook : bookDao.queryBooks()) { 52 | System.out.println(queryBook); 53 | } 54 | } 55 | 56 | /* 57 | * 6.查询总记录数 58 | */ 59 | @Test 60 | void queryForPageTotalCount() { 61 | System.out.println( bookDao.queryForPageTotalCount() ); 62 | } 63 | 64 | /* 65 | * 7.查询当前页数据 66 | */ 67 | @Test 68 | void queryForPageTotalCountByPrice() { 69 | System.out.println( bookDao.queryForPageTotalCountByPrice(10, 50) ); 70 | } 71 | 72 | /* 73 | * 8.价格区间查询 74 | */ 75 | @Test 76 | void queryForPageItemsByPrice() { 77 | for (Book book : bookDao.queryForPageItemsByPrice(0, Page.PAGE_SIZE, 10, 50)) { 78 | System.out.println(book); 79 | } 80 | 81 | } 82 | 83 | /* 84 | * 9.分页查询 85 | */ 86 | @Test 87 | void queryForPageItems() { 88 | for (Book book : bookDao.queryForPageItems(8, Page.PAGE_SIZE)) { 89 | System.out.println(book); 90 | } 91 | } 92 | 93 | } -------------------------------------------------------------------------------- /src/test/java/com/bookshop/dao/impl/CartDaoImplTest.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.dao.impl; 2 | 3 | import com.bookshop.dao.CartDao; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class CartDaoImplTest { 9 | private CartDao cartDao = new CartDaoImpl(); 10 | 11 | /* 12 | * 1.添加图书 13 | */ 14 | @Test 15 | void queryCart() { 16 | System.out.println(cartDao.queryCart(1)); 17 | 18 | } 19 | /* 20 | * 2.判断购物车是否存在 21 | */ 22 | @Test 23 | void isExist() { 24 | System.out.println(cartDao.isExist(1)); 25 | } 26 | } -------------------------------------------------------------------------------- /src/test/java/com/bookshop/dao/impl/CartDaoItemImplTest.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.dao.impl; 2 | 3 | import com.bookshop.dao.CartItemDao; 4 | import com.bookshop.pojo.CartItem; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import java.math.BigDecimal; 8 | 9 | class CartDaoItemImplTest { 10 | private CartItemDao cartItemDao = new CartDaoItemImpl(); 11 | 12 | /* 13 | * 1.添加图书 14 | */ 15 | @Test 16 | void addItem() { 17 | cartItemDao.addItem(new CartItem(1,"1",1,new BigDecimal(1),1)); 18 | 19 | } 20 | /* 21 | * 2.删除图书 22 | */ 23 | @Test 24 | void deleteItem() { 25 | cartItemDao.deleteItem(1,new CartItem(1,"1",1,new BigDecimal(1),1)); 26 | } 27 | 28 | /* 29 | * 3.清空购物车 30 | */ 31 | @Test 32 | void clear() { 33 | cartItemDao.clear(new CartItem(1,"1",1,new BigDecimal(1),1)); 34 | } 35 | 36 | /* 37 | * 4.修改图书数量 38 | */ 39 | @Test 40 | void updateCount() { 41 | cartItemDao.updateCount(1,new CartItem(1,"1",1,new BigDecimal(1),1)); 42 | } 43 | 44 | 45 | 46 | /* 47 | * 5.查询购物车是否存在 48 | */ 49 | @Test 50 | void queryCartid() { 51 | cartItemDao.queryCartid(1); 52 | } 53 | } -------------------------------------------------------------------------------- /src/test/java/com/bookshop/dao/impl/OrderDaoImplTest.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.dao.impl; 2 | 3 | import com.bookshop.dao.OrderDao; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class OrderDaoImplTest { 9 | 10 | private OrderDao orderDao = new OrderDaoImpl(); 11 | 12 | @Test 13 | void queryOrders() { 14 | } 15 | 16 | @Test 17 | void saveOrder() { 18 | } 19 | 20 | @Test 21 | void deleteOrder() { 22 | orderDao.deleteOrder(1); 23 | } 24 | } -------------------------------------------------------------------------------- /src/test/java/com/bookshop/dao/impl/UserDaoImplTest.java: -------------------------------------------------------------------------------- 1 | package com.bookshop.dao.impl; 2 | 3 | import com.bookshop.dao.UserDao; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class UserDaoImplTest { 9 | private UserDao userDao = new UserDaoImpl(); 10 | 11 | @Test 12 | void queryUserByUsername() { 13 | System.out.println(userDao.queryUserByUsername("admin")); 14 | 15 | } 16 | 17 | @Test 18 | void queryUserByUsernameAndPassword() { 19 | userDao.queryUserByUsernameAndPassword("admin","admin"); 20 | } 21 | 22 | @Test 23 | void saveUser() { 24 | userDao.saveUser(null); 25 | } 26 | } --------------------------------------------------------------------------------