├── .DS_Store ├── .gitattributes ├── README.md ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── hwua │ │ ├── dao │ │ ├── CommentDaoImpl.java │ │ ├── I │ │ │ ├── CommentDao.java │ │ │ ├── NewDao.java │ │ │ ├── OrderDao.java │ │ │ ├── OrderDetailDao.java │ │ │ ├── ProductCategoryDao.java │ │ │ ├── ProductDao.java │ │ │ ├── ShopCartDao.java │ │ │ └── UserDao.java │ │ ├── NewDaoImpl.java │ │ ├── OrderDaoImpl.java │ │ ├── OrderDetailDaoImpl.java │ │ ├── ProductCategoryDaoImpl.java │ │ ├── ProductDaoImpl.java │ │ ├── ShopCartDaoImpl.java │ │ └── UserDaoImpl.java │ │ ├── entity │ │ ├── Comment.java │ │ ├── News.java │ │ ├── Order.java │ │ ├── OrderDetail.java │ │ ├── Paging.java │ │ ├── Product.java │ │ ├── ProductCategory.java │ │ ├── ShopCart.java │ │ └── User.java │ │ ├── service │ │ ├── CommentServiceImpl.java │ │ ├── I │ │ │ ├── CommentService.java │ │ │ ├── NewService.java │ │ │ ├── OrderDetailService.java │ │ │ ├── OrderService.java │ │ │ ├── ProductCategoryService.java │ │ │ ├── ProductService.java │ │ │ ├── ShopCartService.java │ │ │ └── UserService.java │ │ ├── NewServiceImpl.java │ │ ├── OrderDetailServiceImpl.java │ │ ├── OrderServiceImpl.java │ │ ├── ProductCategoryServiceImpl.java │ │ ├── ProductServiceImpl.java │ │ ├── ShopCartServiceImpl.java │ │ └── UserServiceImpl.java │ │ ├── utils │ │ ├── DrawImage.java │ │ └── DruidPool.java │ │ └── web │ │ ├── filter │ │ └── AllFilter.java │ │ └── servlet │ │ ├── BuyServlet.java │ │ ├── CodeServlet.java │ │ ├── CommentServlet.java │ │ ├── NewsServlet.java │ │ ├── ProCategoryServlet.java │ │ ├── ProductServlet.java │ │ ├── ShopCarServlet.java │ │ └── UserServlet.java ├── resources │ └── druid.properties └── webapp │ ├── WEB-INF │ └── web.xml │ ├── back.jsp │ ├── chat-room.jsp │ ├── code.jsp │ ├── css │ ├── adv.css │ ├── guestbook.css │ ├── index.css │ ├── querydiv.css │ └── style.css │ ├── guestbook.jsp │ ├── hotproduct.jsp │ ├── images │ ├── 15.jpg │ ├── 16.jpg │ ├── 17.jpg │ ├── 20.jpg │ ├── 21.jpg │ ├── T1.jpg │ ├── T2.jpg │ ├── T3.jpg │ ├── T4.jpg │ ├── T5.jpg │ ├── an_bj01.png │ ├── bg.png │ ├── buyNow.png │ ├── cartbutton.png │ ├── icon_1.png │ ├── icon_2.png │ ├── icon_3.png │ ├── icon_4.png │ ├── icon_5.png │ ├── icon_Recommend.png │ ├── icon_news.png │ ├── icon_sale.png │ ├── icon_sj.png │ ├── logo.gif │ ├── logo.png │ ├── product │ │ ├── 0.jpg │ │ ├── 0_tiny.gif │ │ ├── 1.jpg │ │ ├── 10.jpg │ │ ├── 11.jpg │ │ ├── 12.jpg │ │ ├── 13.jpg │ │ ├── 14.jpg │ │ ├── 15.jpg │ │ ├── 16.jpg │ │ ├── 17.jpg │ │ ├── 18.jpg │ │ ├── 19.jpg │ │ ├── 2.jpg │ │ ├── 20.jpg │ │ ├── 21.jpg │ │ ├── 23.jpg │ │ ├── 24.jpg │ │ ├── 29.jpg │ │ ├── 3.jpg │ │ ├── 4.jpg │ │ ├── 5.jpg │ │ ├── 6.jpg │ │ ├── 7.jpg │ │ ├── 8.jpg │ │ ├── 9.jpg │ │ ├── Microphone1.jpg │ │ ├── Microphone10.jpg │ │ ├── Microphone2.jpg │ │ ├── Microphone3.jpg │ │ ├── Microphone4.jpg │ │ ├── Microphone5.jpg │ │ ├── Microphone6.jpg │ │ ├── Microphone7.jpg │ │ ├── Microphone8.jpg │ │ ├── Microphone9.jpg │ │ ├── clothes1.jpg │ │ ├── clothes10.jpg │ │ ├── clothes2.jpg │ │ ├── clothes3.jpg │ │ ├── clothes4.jpg │ │ ├── clothes5.jpg │ │ ├── clothes6.jpg │ │ ├── clothes7.jpg │ │ ├── clothes8.jpg │ │ ├── clothes9.jpg │ │ ├── shoes1.jpg │ │ ├── shoes10.jpg │ │ ├── shoes2.jpg │ │ ├── shoes3.jpg │ │ ├── shoes4.jpg │ │ ├── shoes5.jpg │ │ ├── shoes6.jpg │ │ ├── shoes7.jpg │ │ ├── shoes8.jpg │ │ ├── shoes9.jpg │ │ ├── sunglass1.jpg │ │ ├── sunglass10.jpg │ │ ├── sunglass2.jpg │ │ ├── sunglass3.jpg │ │ ├── sunglass4.jpg │ │ ├── sunglass5.jpg │ │ ├── sunglass6.jpg │ │ ├── sunglass7.jpg │ │ ├── sunglass8.jpg │ │ ├── sunglass9.jpg │ │ ├── television1.jpg │ │ ├── television10.jpg │ │ ├── television2.jpg │ │ ├── television3.jpg │ │ ├── television4.jpg │ │ ├── television5.jpg │ │ ├── television6.jpg │ │ ├── television7.jpg │ │ ├── television8.jpg │ │ └── television9.jpg │ ├── query.png │ ├── spritel.png │ └── spriter.png │ ├── index.jsp │ ├── index_news.jsp │ ├── index_pre_look.jsp │ ├── index_product_sort.jsp │ ├── index_top.jsp │ ├── login.jsp │ ├── method.jsp │ ├── news_view.jsp │ ├── orders_view.jsp │ ├── product-list.jsp │ ├── product_view.jsp │ ├── queryproduct-list.jsp │ ├── reg-result.jsp │ ├── register.jsp │ ├── retrieve_password.jsp │ ├── scripts │ ├── adv.js │ ├── comment.js │ ├── function-manage.js │ ├── function.js │ ├── index.js │ ├── jquery-2.1.0.js │ ├── product_view.js │ ├── register.js │ └── shopping.js │ ├── shopping-result.jsp │ └── shopping.jsp └── test └── java └── com └── hwua └── test └── NewsTest.java /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaGraduationProject/DepartmentStoreManagementSystem/058324e22ac42e42ad35ce4589601a2b766e4503/.DS_Store -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.js linguist-language=java 2 | *.css linguist-language=java 3 | *.html linguist-language=java 4 | *.vue linguist-language=java -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 全目录 2 | 3 | [更多系统、论文,供君选择 ~~>](https://www.yuque.com/wisebit/blog) 4 | 5 | # 283.DepartmentStoreManagementSystem 6 | 7 |

群: 983063232(入群获取sql文件)

8 |

QQ: 206157502(加好友获取sql文件)

9 | 10 |

283.百货商城管理系统

11 | 12 | 13 |

14 | 15 | 16 | 17 | 18 | 19 |

20 | 21 | # 简介 22 | 23 | > 本代码来源于网络,仅供学习参考使用,请入群(983063232)后联系群主索要sql文件! 24 | > 25 | > 提供1.远程部署/2.修改代码/3.设计文档指导/4.框架代码讲解等服务 26 | > 27 | > http://localhost:8080/ 28 | > 29 | > 用户: admin 密码: 123456 30 | > 31 | 32 | > 33 | 34 | # 环境 35 | 36 | - IntelliJ IDEA 2021.3 37 | 38 | - Mysql 5.7.26 39 | 40 | - Tomcat 7.0.73 41 | 42 | - JDK 1.8 43 | 44 | 45 | 46 | 47 | ## 缩略图 48 | 49 | ![](https://bitwise.oss-cn-heyuan.aliyuncs.com/2024/9/10/99534836-6e7f-4d31-b01e-cb192025ef1b.png) 50 | ![](https://bitwise.oss-cn-heyuan.aliyuncs.com/2024/9/10/05399f8e-b50b-4b81-abc3-a16365e322e4.png) 51 | ![](https://bitwise.oss-cn-heyuan.aliyuncs.com/2024/9/10/8ebaeb58-b9d4-493f-8625-b79d93881dbd.png) 52 | ![](https://bitwise.oss-cn-heyuan.aliyuncs.com/2024/9/10/296d517d-8620-4dfc-8989-08b70d6b44ac.png) 53 | ![](https://bitwise.oss-cn-heyuan.aliyuncs.com/2024/9/10/bbd72364-de17-4b5e-a7f3-ae6b87a42e16.png) 54 | ![](https://bitwise.oss-cn-heyuan.aliyuncs.com/2024/9/10/1c444c28-2694-43d5-891b-4b0bb61fc508.png) 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 4.0.0 6 | 7 | com.pr 8 | market_system 9 | 0.0.1-SNAPSHOT 10 | war 11 | 12 | market_system Maven Webapp 13 | 14 | http://www.example.com 15 | 16 | 17 | UTF-8 18 | 1.8 19 | 1.8 20 | 21 | 22 | 23 | 24 | junit 25 | junit 26 | 4.11 27 | test 28 | 29 | 30 | 31 | 32 | org.projectlombok 33 | lombok 34 | 1.18.8 35 | provided 36 | 37 | 38 | 43 | 44 | commons-dbutils 45 | commons-dbutils 46 | 1.7 47 | 48 | 49 | 50 | 51 | com.alibaba 52 | druid 53 | 1.1.10 54 | 55 | 56 | 57 | 58 | com.alibaba 59 | fastjson 60 | 1.2.58 61 | 62 | 63 | 64 | com.mchange 65 | c3p0 66 | 0.9.5.4 67 | 68 | 69 | 70 | javax.servlet 71 | javax.servlet-api 72 | 4.0.1 73 | provided 74 | 75 | 76 | 77 | 78 | javax.servlet.jsp 79 | jsp-api 80 | 2.2 81 | provided 82 | 83 | 84 | 85 | mysql 86 | mysql-connector-java 87 | 8.0.15 88 | 89 | 90 | 91 | 92 | 93 | 94 | jstl 95 | jstl 96 | 1.2 97 | 98 | 99 | 100 | javax.persistence 101 | persistence-api 102 | 1.0.2 103 | 104 | 105 | 106 | 107 | taglibs 108 | standard 109 | 1.1.2 110 | 111 | 112 | 113 | 114 | 115 | 116 | com.fasterxml.jackson.core 117 | jackson-databind 118 | 2.9.9 119 | 120 | 121 | 122 | 123 | market_system 124 | 125 | 126 | 127 | maven-clean-plugin 128 | 3.1.0 129 | 130 | 131 | 132 | maven-resources-plugin 133 | 3.0.2 134 | 135 | 136 | maven-compiler-plugin 137 | 3.8.0 138 | 139 | 140 | maven-surefire-plugin 141 | 2.22.1 142 | 143 | 144 | maven-war-plugin 145 | 3.2.2 146 | 147 | 148 | maven-install-plugin 149 | 2.5.2 150 | 151 | 152 | maven-deploy-plugin 153 | 2.8.2 154 | 155 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/dao/CommentDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.hwua.dao; 2 | 3 | 4 | import com.hwua.dao.I.CommentDao; 5 | import com.hwua.entity.Comment; 6 | 7 | import com.hwua.utils.DruidPool; 8 | import org.apache.commons.dbutils.QueryRunner; 9 | import org.apache.commons.dbutils.handlers.BeanListHandler; 10 | import org.apache.commons.dbutils.handlers.ScalarHandler; 11 | 12 | import java.sql.SQLException; 13 | import java.util.List; 14 | 15 | public class CommentDaoImpl implements CommentDao { 16 | private QueryRunner queryRunner = new QueryRunner(DruidPool.getDruidDS()); 17 | @Override 18 | public List QueryAllComment() throws SQLException { 19 | String sql= "select id, reply, content, create_time, reply_time, nick_name, state from amz_comment order by create_time desc "; 20 | return queryRunner.query(sql,new BeanListHandler<>(Comment.class)); 21 | } 22 | 23 | /** 24 | * 添加留言 25 | * @param comment 26 | * @return 27 | */ 28 | @Override 29 | public Integer addComment(Comment comment) throws SQLException { 30 | String sql = "insert into amz_comment ( reply, content, create_time, reply_time, nick_name) VALUES (?,?,?,?,?)"; 31 | return queryRunner.update(sql,comment.getReply(),comment.getContent(),comment.getCreate_Time(),comment.getReply_Time(),comment.getNick_Name() ); 32 | } 33 | 34 | @Override 35 | public List querypageComment(Integer start, Integer number) throws SQLException { 36 | String sql = "select id, reply, content, create_time, reply_time, nick_name, state from amz_comment order by create_time desc limit ?,?"; 37 | return queryRunner.query(sql,new BeanListHandler<>(Comment.class),start,number); 38 | } 39 | 40 | /** 41 | * 查询留言个数 42 | * @return 43 | */ 44 | @Override 45 | public Long queryCount() throws SQLException { 46 | String sql = "select count(id) from amz_comment"; 47 | return queryRunner.query(sql,new ScalarHandler<>()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/dao/I/CommentDao.java: -------------------------------------------------------------------------------- 1 | package com.hwua.dao.I; 2 | 3 | import com.hwua.entity.Comment; 4 | 5 | import java.sql.SQLException; 6 | import java.util.List; 7 | 8 | /*留言*/ 9 | public interface CommentDao { 10 | /** 11 | * 查询所有评论 12 | * @return 13 | */ 14 | public List QueryAllComment() throws SQLException; 15 | 16 | /** 17 | * 添加留言 18 | * @param comment 19 | * @return 20 | */ 21 | public Integer addComment(Comment comment) throws SQLException; 22 | 23 | /** 24 | * 分页查询 25 | * @param start 26 | * @param number 27 | * @return 28 | * @throws SQLException 29 | */ 30 | public List querypageComment(Integer start, Integer number) throws SQLException; 31 | 32 | /** 33 | * 查询留言个数 34 | * @return 35 | */ 36 | public Long queryCount() throws SQLException; 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/dao/I/NewDao.java: -------------------------------------------------------------------------------- 1 | package com.hwua.dao.I; 2 | 3 | import com.hwua.entity.News; 4 | 5 | import java.sql.SQLException; 6 | import java.util.List; 7 | 8 | public interface NewDao { 9 | public abstract List queryNews() throws SQLException;//查询所有的新闻 10 | public abstract News queryNewById(Integer id) throws SQLException;//通过新闻编号查询新闻 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/dao/I/OrderDao.java: -------------------------------------------------------------------------------- 1 | package com.hwua.dao.I; 2 | 3 | import com.hwua.entity.Order; 4 | 5 | import java.sql.SQLException; 6 | import java.util.List; 7 | 8 | public interface OrderDao { 9 | public abstract List queryOrderByUid(Long uid) throws SQLException;//通过用户id查询订单信息 10 | public abstract Integer insertOrder(Order order) throws SQLException;//添加订单信息 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/dao/I/OrderDetailDao.java: -------------------------------------------------------------------------------- 1 | package com.hwua.dao.I; 2 | 3 | import com.hwua.entity.OrderDetail; 4 | 5 | import java.sql.SQLException; 6 | import java.util.List; 7 | 8 | public interface OrderDetailDao { 9 | public abstract List queryOrderDetailByOid(Long oid) throws SQLException;//通过订单id查询订单明细 10 | public abstract Integer insertOrderDetail(OrderDetail orderDetail) throws SQLException;//插入订单明细 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/dao/I/ProductCategoryDao.java: -------------------------------------------------------------------------------- 1 | package com.hwua.dao.I; 2 | 3 | import com.hwua.entity.ProductCategory; 4 | 5 | import java.sql.SQLException; 6 | import java.util.List; 7 | 8 | public interface ProductCategoryDao { 9 | //查询一级产品分类 10 | public abstract List queryParent() throws SQLException; 11 | //查询一级产品分类的id 12 | public abstract List queryParentById() throws SQLException; 13 | //查询二级产品分类 14 | public abstract List querySon(Long id) throws SQLException; 15 | public abstract Long queryParentId(Long sonId) throws SQLException;//通过二级ID查询一级ID 16 | public abstract String queryProName(Long id) throws SQLException;//通过id查询分类名 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/dao/I/ProductDao.java: -------------------------------------------------------------------------------- 1 | package com.hwua.dao.I; 2 | 3 | import com.hwua.entity.Product; 4 | 5 | import java.sql.SQLException; 6 | import java.util.List; 7 | 8 | public interface ProductDao { 9 | public abstract List queryAllProduct() throws SQLException;//查询所有商品 10 | public abstract List queryMaxProduct() throws SQLException;//查询库存最多的商品 11 | public abstract List queryProductLimit(Integer start,Integer pageSize) throws SQLException;//分页查询 12 | public abstract Product queryProductById(Integer id) throws SQLException;//通过id查询 13 | public abstract Long queryProductCount() throws SQLException;//查询出商品总记录数 14 | public abstract List queryProByParentId(Long parentId) throws SQLException;//通过一级ID查询商品 15 | public abstract List queryProBySonId(Long sonId) throws SQLException;//通过二级ID查询商品 16 | public abstract List queryLikeByName(String proName) throws SQLException;//通过字段查询到宝贝 17 | public abstract Integer delProStock(Long id,Long pnum) throws SQLException;//删除对应的库存 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/dao/I/ShopCartDao.java: -------------------------------------------------------------------------------- 1 | package com.hwua.dao.I; 2 | 3 | import com.hwua.entity.ShopCart; 4 | 5 | import java.sql.SQLException; 6 | import java.util.List; 7 | 8 | public interface ShopCartDao { 9 | public abstract Integer addProduct(ShopCart shopCart) throws SQLException;//添加商品 10 | public abstract Integer delProduct(Long id) throws SQLException;//删除商品 11 | public abstract Integer updateNum(int pnum,Long id) throws SQLException;//修改商品数量 12 | public abstract List showCart(Long uid) throws SQLException;//显示购物车明细 13 | public abstract Integer clearShopCart(Long uid) throws SQLException;//请空购物车 14 | public abstract ShopCart queryShopCart(Integer pid,Long uid) throws SQLException;//根据指定pid和uid查询购物项 15 | public abstract ShopCart queryShopCart(Long id)throws SQLException;//根据指定购物项id查询 16 | public abstract Integer updateUid(Long loginID) throws SQLException;//更改用户id 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/dao/I/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.hwua.dao.I; 2 | 3 | import com.hwua.entity.User; 4 | 5 | import java.sql.SQLException; 6 | 7 | public interface UserDao { 8 | public abstract User queryUser(String name, String pwd) throws SQLException;//通过姓名,密码查找 9 | public abstract Integer insertUser(User user) throws SQLException;//添加用户信息 10 | public abstract User queryName(String name) throws SQLException;//通过姓名查询用户 11 | public abstract User queryUserById(Long id) throws SQLException;//通过id查询用户 12 | public abstract User queryUserByEmail(String uname,String email) throws SQLException;//通过姓名和邮箱查询 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/dao/NewDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.hwua.dao; 2 | 3 | import com.hwua.dao.I.NewDao; 4 | import com.hwua.entity.News; 5 | import com.hwua.utils.DruidPool; 6 | import org.apache.commons.dbutils.QueryRunner; 7 | import org.apache.commons.dbutils.handlers.BeanHandler; 8 | import org.apache.commons.dbutils.handlers.BeanListHandler; 9 | 10 | import java.sql.SQLException; 11 | import java.util.List; 12 | 13 | public class NewDaoImpl implements NewDao { 14 | private static QueryRunner qr = new QueryRunner(DruidPool.getDruidDS()); 15 | @Override 16 | public List queryNews() throws SQLException { 17 | String sql = "select id,title,content,create_time from amz_news"; 18 | return qr.query(sql,new BeanListHandler<>(News.class)); 19 | } 20 | 21 | @Override 22 | public News queryNewById(Integer id) throws SQLException { 23 | String sql = "select id,title,content,create_time from amz_news where id = ?"; 24 | return qr.query(sql,new BeanHandler<>(News.class),id); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/dao/OrderDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.hwua.dao; 2 | 3 | import com.hwua.dao.I.OrderDao; 4 | import com.hwua.entity.Order; 5 | import com.hwua.utils.DruidPool; 6 | import org.apache.commons.dbutils.QueryRunner; 7 | import org.apache.commons.dbutils.handlers.BeanListHandler; 8 | 9 | import java.math.BigDecimal; 10 | import java.sql.SQLException; 11 | import java.sql.Timestamp; 12 | import java.util.Date; 13 | import java.util.List; 14 | 15 | public class OrderDaoImpl implements OrderDao { 16 | private static QueryRunner qr = new QueryRunner(DruidPool.getDruidDS()); 17 | @Override 18 | public List queryOrderByUid(Long uid) throws SQLException { 19 | String sql = "select * from amz_order where uid = ? order by create_time desc "; 20 | return qr.query(sql,new BeanListHandler<>(Order.class),uid); 21 | } 22 | 23 | @Override 24 | public Integer insertOrder(Order order) throws SQLException { 25 | String sql = "insert amz_order values(null,?,?,?,?,?,1,1)"; 26 | return qr.update(sql,order.getUid(),order.getUname(),order.getUaddress(),order.getCreate_time(),order.getMoney()); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/dao/OrderDetailDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.hwua.dao; 2 | 3 | import com.hwua.dao.I.OrderDetailDao; 4 | import com.hwua.entity.OrderDetail; 5 | import com.hwua.utils.DruidPool; 6 | import org.apache.commons.dbutils.QueryRunner; 7 | import org.apache.commons.dbutils.handlers.BeanHandler; 8 | import org.apache.commons.dbutils.handlers.BeanListHandler; 9 | 10 | import java.sql.SQLException; 11 | import java.util.List; 12 | 13 | public class OrderDetailDaoImpl implements OrderDetailDao { 14 | private static QueryRunner qr = new QueryRunner(DruidPool.getDruidDS()); 15 | @Override 16 | public List queryOrderDetailByOid(Long oid) throws SQLException { 17 | String sql = "select id,oid,pid,quantity,money from amz_order_detail where oid = ?"; 18 | return qr.query(sql,new BeanListHandler<>(OrderDetail.class),oid); 19 | } 20 | 21 | @Override 22 | public Integer insertOrderDetail(OrderDetail orderDetail) throws SQLException { 23 | String sql = "insert amz_order_detail values(null,?,?,?,?)"; 24 | return qr.update(sql,orderDetail.getOid(),orderDetail.getPid(),orderDetail.getQuantity(),orderDetail.getMoney()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/dao/ProductCategoryDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.hwua.dao; 2 | 3 | import com.hwua.dao.I.ProductCategoryDao; 4 | import com.hwua.entity.ProductCategory; 5 | import com.hwua.utils.DruidPool; 6 | import org.apache.commons.dbutils.QueryRunner; 7 | import org.apache.commons.dbutils.handlers.BeanListHandler; 8 | import org.apache.commons.dbutils.handlers.ColumnListHandler; 9 | import org.apache.commons.dbutils.handlers.ScalarHandler; 10 | 11 | import java.sql.SQLException; 12 | import java.util.List; 13 | 14 | public class ProductCategoryDaoImpl implements ProductCategoryDao { 15 | private static QueryRunner qr = new QueryRunner(DruidPool.getDruidDS()); 16 | @Override 17 | public List queryParent() throws SQLException { 18 | String sql = "select DISTINCT a1.id,a1.`name`,a1.parent_id FROM amz_product_category a1,amz_product_category a2 WHERE a1.id = a2.parent_id"; 19 | return qr.query(sql,new BeanListHandler<>(ProductCategory.class)); 20 | } 21 | 22 | @Override 23 | public List queryParentById() throws SQLException { 24 | String sql = "select distinct parent_id from amz_product_category"; 25 | return qr.query(sql,new ColumnListHandler<>()); 26 | } 27 | 28 | @Override 29 | public List querySon(Long id) throws SQLException { 30 | String sql = "select id,name,parent_id from amz_product_category where parent_id = ?"; 31 | return qr.query(sql,new BeanListHandler<>(ProductCategory.class),id); 32 | } 33 | 34 | @Override 35 | public Long queryParentId(Long sonId) throws SQLException { 36 | String sql = "select parent_id from amz_product_category where id = ?"; 37 | return qr.query(sql,new ScalarHandler<>(),sonId); 38 | } 39 | 40 | @Override 41 | public String queryProName(Long id) throws SQLException { 42 | String sql = "select name from amz_product_category where id = ?"; 43 | return qr.query(sql,new ScalarHandler<>(),id); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/dao/ProductDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.hwua.dao; 2 | 3 | import com.hwua.dao.I.ProductDao; 4 | import com.hwua.entity.Product; 5 | import com.hwua.utils.DruidPool; 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.SQLException; 12 | import java.util.List; 13 | 14 | public class ProductDaoImpl implements ProductDao { 15 | QueryRunner qr = new QueryRunner(DruidPool.getDruidDS()); 16 | 17 | @Override 18 | public List queryAllProduct() throws SQLException { 19 | String sql = "select id,name,description,price,stock,major_id,minor_id,img_source from amz_product"; 20 | return qr.query(sql,new BeanListHandler<>(Product.class)); 21 | } 22 | 23 | @Override 24 | public List queryMaxProduct() throws SQLException { 25 | String sql = "select id,name,description,price,stock,major_id,minor_id,img_source from amz_product order by stock desc limit 0,6"; 26 | return qr.query(sql,new BeanListHandler<>(Product.class)); 27 | } 28 | 29 | 30 | 31 | @Override 32 | public List queryProductLimit(Integer start,Integer pageSize) throws SQLException { 33 | String sql = "select id,name,description,price,stock,major_id,minor_id,img_source from amz_product limit ?,?"; 34 | return qr.query(sql,new BeanListHandler<>(Product.class),start,pageSize); 35 | } 36 | 37 | @Override 38 | public Product queryProductById(Integer id) throws SQLException { 39 | String sql = "select id,name,description,price,stock,major_id,minor_id,img_source from amz_product where id = ?"; 40 | return qr.query(sql,new BeanHandler<>(Product.class),id); 41 | } 42 | 43 | @Override 44 | public Long queryProductCount() throws SQLException { 45 | String sql = "select count(*) from amz_product"; 46 | return qr.query(sql,new ScalarHandler<>()); 47 | } 48 | 49 | @Override 50 | public List queryProByParentId(Long parentId) throws SQLException { 51 | String sql = "select id,name,description,price,stock,major_id,minor_id,img_source from amz_product where major_id = ?"; 52 | return qr.query(sql,new BeanListHandler<>(Product.class),parentId); 53 | } 54 | 55 | @Override 56 | public List queryProBySonId(Long sonId) throws SQLException { 57 | String sql = "select id,name,description,price,stock,major_id,minor_id,img_source from amz_product where minor_id = ?"; 58 | return qr.query(sql,new BeanListHandler<>(Product.class),sonId); 59 | } 60 | 61 | @Override 62 | public List queryLikeByName(String proName) throws SQLException { 63 | String sql = "select id,name,description,price,stock,major_id,minor_id,img_source from amz_product where 1=1 "; 64 | StringBuilder sb = new StringBuilder(); 65 | if (proName!=""){ 66 | for (int i = 0; i < proName.length(); i++) { 67 | if (i==0) { 68 | sb.append("'%"); 69 | } 70 | sb.append(proName.charAt(i)); 71 | sb.append("%"); 72 | if (i==(proName.length()-1)){ 73 | sb.append("'"); 74 | } 75 | } 76 | sql = sql+"and name like "+sb; 77 | } 78 | return qr.query(sql,new BeanListHandler<>(Product.class)); 79 | } 80 | 81 | @Override 82 | public Integer delProStock(Long id, Long pnum) throws SQLException { 83 | String sql = "UPDATE amz_product SET stock = ? WHERE id = ? "; 84 | return qr.update(sql,pnum,id); 85 | } 86 | 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/dao/ShopCartDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.hwua.dao; 2 | 3 | import com.hwua.dao.I.ShopCartDao; 4 | import com.hwua.entity.ShopCart; 5 | import com.hwua.utils.DruidPool; 6 | import org.apache.commons.dbutils.QueryRunner; 7 | import org.apache.commons.dbutils.handlers.BeanHandler; 8 | import org.apache.commons.dbutils.handlers.BeanListHandler; 9 | 10 | import java.sql.SQLException; 11 | import java.util.List; 12 | 13 | public class ShopCartDaoImpl implements ShopCartDao { 14 | private static QueryRunner qr = new QueryRunner(DruidPool.getDruidDS()); 15 | @Override 16 | public Integer addProduct(ShopCart shopCart) throws SQLException { 17 | String sql = "insert amz_shop_cart values(null,?,?,?)"; 18 | return qr.update(sql,shopCart.getPid(),shopCart.getPnum(),shopCart.getUid()); 19 | } 20 | 21 | @Override 22 | public Integer delProduct(Long id) throws SQLException { 23 | String sql = "delete from amz_shop_cart where id = ?"; 24 | return qr.update(sql,id); 25 | } 26 | 27 | @Override 28 | public Integer updateNum(int pnum,Long id) throws SQLException { 29 | String sql = "update amz_shop_cart set pnum = ? where id = ?"; 30 | return qr.update(sql,pnum,id); 31 | } 32 | 33 | @Override 34 | public List showCart(Long uid) throws SQLException { 35 | String sql = "select id,pid,pnum,uid from amz_shop_cart where uid = ?"; 36 | return qr.query(sql, new BeanListHandler<>(ShopCart.class),uid); 37 | } 38 | 39 | @Override 40 | public Integer clearShopCart(Long uid) throws SQLException { 41 | String sql = "delete from amz_shop_cart where uid = ?"; 42 | return qr.update(sql,uid); 43 | } 44 | 45 | @Override 46 | public ShopCart queryShopCart(Integer pid, Long uid) throws SQLException { 47 | String sql = "select id,pid,pnum,uid from amz_shop_cart where pid = ? and uid = ?"; 48 | return qr.query(sql, new BeanHandler<>(ShopCart.class),pid,uid); 49 | } 50 | 51 | @Override 52 | public ShopCart queryShopCart(Long id) throws SQLException { 53 | String sql = "select id,pid,pnum,uid from amz_shop_cart where id = ?"; 54 | return qr.query(sql, new BeanHandler<>(ShopCart.class),id); 55 | } 56 | 57 | @Override 58 | public Integer updateUid(Long loginID) throws SQLException { 59 | String sql = "update amz_shop_cart set uid = ? where uid = 0"; 60 | return qr.update(sql,loginID); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/dao/UserDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.hwua.dao; 2 | 3 | import com.hwua.dao.I.UserDao; 4 | import com.hwua.entity.User; 5 | import com.hwua.utils.DruidPool; 6 | import org.apache.commons.dbutils.QueryRunner; 7 | import org.apache.commons.dbutils.handlers.BeanHandler; 8 | 9 | import java.sql.Connection; 10 | import java.sql.SQLException; 11 | 12 | public class UserDaoImpl implements UserDao { 13 | //创建JDBC的对象 14 | private static QueryRunner qr = new QueryRunner(DruidPool.getDruidDS()); 15 | 16 | @Override 17 | public User queryUser(String name, String pwd) throws SQLException { 18 | String sql = "select id,uname,pwd,sex,birthday,idcard,email,mobile,address,utype from amz_user where uname = ? and pwd = ?"; 19 | return qr.query(sql, new BeanHandler<>(User.class),name,pwd); 20 | } 21 | 22 | @Override 23 | public Integer insertUser(User user) throws SQLException{ 24 | String sql = "insert amz_user values(null,?,?,?,?,?,?,?,?,0)"; 25 | return qr.update(sql,user.getUname(),user.getPwd(),user.getSex(),user.getBirthday(),user.getIdcard(),user.getEmail(),user.getMobile(),user.getAddress()); 26 | } 27 | 28 | @Override 29 | public User queryName(String name) throws SQLException { 30 | String sql = "select id,uname,pwd,sex,birthday,idcard,email,mobile,address,utype from amz_user where uname = ?"; 31 | return qr.query(sql,new BeanHandler<>(User.class),name); 32 | } 33 | 34 | @Override 35 | public User queryUserById(Long id) throws SQLException { 36 | String sql = "select id,uname,pwd,sex,birthday,idcard,email,mobile,address,utype from amz_user where id = ?"; 37 | return qr.query(sql,new BeanHandler<>(User.class),id); 38 | } 39 | 40 | @Override 41 | public User queryUserByEmail(String uname, String email) throws SQLException { 42 | String sql = "select id,uname,pwd,sex,birthday,idcard,email,mobile,address,utype from amz_user where uname = ? and email = ?"; 43 | return qr.query(sql,new BeanHandler<>(User.class),uname,email); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/entity/Comment.java: -------------------------------------------------------------------------------- 1 | package com.hwua.entity; 2 | 3 | 4 | import java.sql.Timestamp; 5 | 6 | public class Comment { 7 | /*评论*/ 8 | private long id;/*评论id*/ 9 | private String reply;/*标题*/ 10 | private String content;/*内容*/ 11 | private String create_Time;/*提问时间*/ 12 | private String reply_Time;/*回答时间*/ 13 | private String nick_Name;/*回答人姓名*/ 14 | private String state;/*状态*/ 15 | 16 | public Comment() { 17 | } 18 | 19 | public Comment(long id, String reply, String content, String createTime, String replyTime, String nickName, String state) { 20 | this.id = id; 21 | this.reply = reply; 22 | this.content = content; 23 | this.create_Time = createTime; 24 | this.reply_Time = replyTime; 25 | this.nick_Name = nickName; 26 | this.state = state; 27 | } 28 | public Comment( String reply, String content, String createTime, String replyTime, String nickName, String state) { 29 | 30 | this.reply = reply; 31 | this.content = content; 32 | this.create_Time = createTime; 33 | this.reply_Time = replyTime; 34 | this.nick_Name = nickName; 35 | this.state = state; 36 | } 37 | 38 | public long getId() { 39 | return id; 40 | } 41 | 42 | public void setId(long id) { 43 | this.id = id; 44 | } 45 | 46 | 47 | public String getReply() { 48 | return reply; 49 | } 50 | 51 | public void setReply(String reply) { 52 | this.reply = reply; 53 | } 54 | 55 | 56 | public String getContent() { 57 | return content; 58 | } 59 | 60 | public void setContent(String content) { 61 | this.content = content; 62 | } 63 | 64 | 65 | public String getCreate_Time() { 66 | return create_Time; 67 | } 68 | 69 | public void setCreate_Time(String create_Time) { 70 | this.create_Time = create_Time; 71 | } 72 | 73 | 74 | public String getReply_Time() { 75 | return reply_Time; 76 | } 77 | 78 | public void setReply_Time(String reply_Time) { 79 | this.reply_Time = reply_Time; 80 | } 81 | 82 | 83 | public String getNick_Name() { 84 | return nick_Name; 85 | } 86 | 87 | public void setNick_Name(String nick_Name) { 88 | this.nick_Name = nick_Name; 89 | } 90 | 91 | 92 | public String getState() { 93 | return state; 94 | } 95 | 96 | public void setState(String state) { 97 | this.state = state; 98 | } 99 | 100 | @Override 101 | public String toString() { 102 | return "Comment{" + 103 | "id=" + id + 104 | ", reply='" + reply + '\'' + 105 | ", content='" + content + '\'' + 106 | ", create_Time=" + create_Time + 107 | ", reply_Time=" + reply_Time + 108 | ", nick_Name='" + nick_Name + '\'' + 109 | ", state='" + state + '\'' + 110 | '}'; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/entity/News.java: -------------------------------------------------------------------------------- 1 | package com.hwua.entity; 2 | 3 | import javax.persistence.*; 4 | import java.sql.Timestamp; 5 | 6 | /*新闻类*/ 7 | @Table(name = "amz_news", schema = "d_shop", catalog = "") 8 | public class News { 9 | private Integer id;//id 10 | private String title;//标题 11 | private String content;//内容 12 | private Timestamp create_time;//创建时间 13 | private String time;//字符串时间 14 | 15 | 16 | //把时间戳转换为字符串 17 | public String getTime() { 18 | time = create_time.toString(); 19 | return time; 20 | } 21 | 22 | public void setTime(String time) { 23 | this.time = time; 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return "News{" + 29 | "id=" + id + 30 | ", title='" + title + '\'' + 31 | ", content='" + content + '\'' + 32 | ", create_time=" + create_time + 33 | '}'; 34 | } 35 | 36 | @Id 37 | @Column(name = "id") 38 | public Integer getId() { 39 | return id; 40 | } 41 | 42 | public void setId(Integer id) { 43 | this.id = id; 44 | } 45 | 46 | @Basic 47 | @Column(name = "title") 48 | public String getTitle() { 49 | return title; 50 | } 51 | 52 | public void setTitle(String title) { 53 | this.title = title; 54 | } 55 | 56 | @Basic 57 | @Column(name = "content") 58 | public String getContent() { 59 | return content; 60 | } 61 | 62 | public void setContent(String content) { 63 | this.content = content; 64 | } 65 | 66 | @Basic 67 | @Column(name = "create_time") 68 | public Timestamp getCreate_time() { 69 | return create_time; 70 | } 71 | 72 | public void setCreate_time(Timestamp create_time) { 73 | this.create_time = create_time; 74 | } 75 | 76 | @Override 77 | public boolean equals(Object o) { 78 | if (this == o) return true; 79 | if (o == null || getClass() != o.getClass()) return false; 80 | 81 | News amzNews = (News) o; 82 | 83 | if (id != amzNews.id) return false; 84 | if (title != null ? !title.equals(amzNews.title) : amzNews.title != null) return false; 85 | if (content != null ? !content.equals(amzNews.content) : amzNews.content != null) return false; 86 | if (create_time != null ? !create_time.equals(amzNews.create_time) : amzNews.create_time != null) return false; 87 | 88 | return true; 89 | } 90 | 91 | @Override 92 | public int hashCode() { 93 | int result = (int) (id ^ (id >>> 32)); 94 | result = 31 * result + (title != null ? title.hashCode() : 0); 95 | result = 31 * result + (content != null ? content.hashCode() : 0); 96 | result = 31 * result + (create_time != null ? create_time.hashCode() : 0); 97 | return result; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/entity/Order.java: -------------------------------------------------------------------------------- 1 | package com.hwua.entity; 2 | 3 | import com.hwua.service.I.OrderDetailService; 4 | import com.hwua.service.I.OrderService; 5 | import com.hwua.service.OrderDetailServiceImpl; 6 | import com.hwua.service.OrderServiceImpl; 7 | 8 | import javax.persistence.*; 9 | import java.math.BigDecimal; 10 | import java.sql.SQLException; 11 | import java.sql.Timestamp; 12 | import java.util.List; 13 | 14 | /*订单类*/ 15 | @Table(name = "amz_order", schema = "d_shop", catalog = "") 16 | public class Order { 17 | private long id;//订单id 18 | private long uid;//用户id 19 | private String uname;//用户姓名 20 | private String uaddress;//用户地址 21 | private Timestamp create_time;//订单创建时间 22 | private BigDecimal money;//订单金额 23 | private int status;//订单状态 24 | private int type;//订单类型 25 | private List odList;//订单明细 26 | private long order_number;//订单编号 27 | 28 | @Override 29 | public String toString() { 30 | return "Order{" + 31 | "id=" + id + 32 | ", uid=" + uid + 33 | ", uname='" + uname + '\'' + 34 | ", uaddress='" + uaddress + '\'' + 35 | ", create_time=" + create_time + 36 | ", money=" + money + 37 | ", status=" + status + 38 | ", type=" + type + 39 | '}'; 40 | } 41 | 42 | @Id 43 | @Column(name = "id") 44 | public long getId() { 45 | return id; 46 | } 47 | 48 | public void setId(long id) { 49 | this.id = id; 50 | } 51 | 52 | @Basic 53 | @Column(name = "uid") 54 | public long getUid() { 55 | return uid; 56 | } 57 | 58 | public void setUid(long uid) { 59 | this.uid = uid; 60 | } 61 | 62 | @Basic 63 | @Column(name = "uname") 64 | public String getUname() { 65 | return uname; 66 | } 67 | 68 | public void setUname(String uname) { 69 | this.uname = uname; 70 | } 71 | 72 | @Basic 73 | @Column(name = "uaddress") 74 | public String getUaddress() { 75 | return uaddress; 76 | } 77 | 78 | public void setUaddress(String uaddress) { 79 | this.uaddress = uaddress; 80 | } 81 | 82 | @Basic 83 | @Column(name = "create_time") 84 | public Timestamp getCreate_time() { 85 | return create_time; 86 | } 87 | 88 | public void setCreate_time(Timestamp create_time) { 89 | this.create_time = create_time; 90 | } 91 | 92 | @Basic 93 | @Column(name = "money") 94 | public BigDecimal getMoney() { 95 | return money; 96 | } 97 | 98 | public void setMoney(BigDecimal money) { 99 | this.money = money; 100 | } 101 | 102 | @Basic 103 | @Column(name = "status") 104 | public int getStatus() { 105 | return status; 106 | } 107 | 108 | public void setStatus(int status) { 109 | this.status = status; 110 | } 111 | 112 | @Basic 113 | @Column(name = "type") 114 | public int getType() { 115 | return type; 116 | } 117 | 118 | public void setType(int type) { 119 | this.type = type; 120 | } 121 | 122 | @Override 123 | public boolean equals(Object o) { 124 | if (this == o) return true; 125 | if (o == null || getClass() != o.getClass()) return false; 126 | 127 | Order amzOrder = (Order) o; 128 | 129 | if (id != amzOrder.id) return false; 130 | if (uid != amzOrder.uid) return false; 131 | if (status != amzOrder.status) return false; 132 | if (type != amzOrder.type) return false; 133 | if (uname != null ? !uname.equals(amzOrder.uname) : amzOrder.uname != null) return false; 134 | if (uaddress != null ? !uaddress.equals(amzOrder.uaddress) : amzOrder.uaddress != null) return false; 135 | if (create_time != null ? !create_time.equals(amzOrder.create_time) : amzOrder.create_time != null) return false; 136 | if (money != null ? !money.equals(amzOrder.money) : amzOrder.money != null) return false; 137 | 138 | return true; 139 | } 140 | 141 | @Override 142 | public int hashCode() { 143 | int result = (int) (id ^ (id >>> 32)); 144 | result = 31 * result + (int) (uid ^ (uid >>> 32)); 145 | result = 31 * result + (uname != null ? uname.hashCode() : 0); 146 | result = 31 * result + (uaddress != null ? uaddress.hashCode() : 0); 147 | result = 31 * result + (create_time != null ? create_time.hashCode() : 0); 148 | result = 31 * result + (money != null ? money.hashCode() : 0); 149 | result = 31 * result + status; 150 | result = 31 * result + type; 151 | return result; 152 | } 153 | 154 | /** 155 | * 通过订单id获取订单明细 156 | * @return 157 | */ 158 | public List getOdList() { 159 | odList = null; 160 | OrderDetailService orderSvs = new OrderDetailServiceImpl(); 161 | try { 162 | odList = orderSvs.queryOrderDetailByOid(getId()); 163 | } catch (SQLException e) { 164 | e.printStackTrace(); 165 | } 166 | return odList; 167 | } 168 | 169 | public void setOdList(List odList) { 170 | this.odList = odList; 171 | } 172 | 173 | public long getOrder_number() { 174 | return order_number; 175 | } 176 | 177 | public void setOrder_number(long order_number) { 178 | this.order_number = order_number; 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/entity/OrderDetail.java: -------------------------------------------------------------------------------- 1 | package com.hwua.entity; 2 | 3 | import com.hwua.service.I.ProductService; 4 | import com.hwua.service.ProductServiceImpl; 5 | 6 | import javax.persistence.*; 7 | import java.math.BigDecimal; 8 | import java.sql.SQLException; 9 | 10 | /*OrderDetail订单明细*/ 11 | @Table(name = "amz_order_detail", schema = "d_shop", catalog = "") 12 | public class OrderDetail { 13 | private long id;//订单明细id 14 | private long oid;//订单编号 15 | private long pid;//商品id 16 | private long quantity;//订单总数量 17 | private BigDecimal money;//订单总金额 18 | private Product product;//商品信息 19 | 20 | @Override 21 | public String toString() { 22 | return "OrderDetail{" + 23 | "id=" + id + 24 | ", oid=" + oid + 25 | ", pid=" + pid + 26 | ", quantity=" + quantity + 27 | ", money=" + money + 28 | '}'; 29 | } 30 | 31 | @Id 32 | @Column(name = "id") 33 | public long getId() { 34 | return id; 35 | } 36 | 37 | public void setId(long id) { 38 | this.id = id; 39 | } 40 | 41 | @Basic 42 | @Column(name = "oid") 43 | public long getOid() { 44 | return oid; 45 | } 46 | 47 | public void setOid(long oid) { 48 | this.oid = oid; 49 | } 50 | 51 | @Basic 52 | @Column(name = "pid") 53 | public long getPid() { 54 | return pid; 55 | } 56 | 57 | public void setPid(long pid) { 58 | this.pid = pid; 59 | } 60 | 61 | @Basic 62 | @Column(name = "quantity") 63 | public long getQuantity() { 64 | return quantity; 65 | } 66 | 67 | public void setQuantity(long quantity) { 68 | this.quantity = quantity; 69 | } 70 | 71 | @Basic 72 | @Column(name = "money") 73 | public BigDecimal getMoney() { 74 | return money; 75 | } 76 | 77 | public void setMoney(BigDecimal money) { 78 | this.money = money; 79 | } 80 | 81 | @Override 82 | public boolean equals(Object o) { 83 | if (this == o) return true; 84 | if (o == null || getClass() != o.getClass()) return false; 85 | 86 | OrderDetail that = (OrderDetail) o; 87 | 88 | if (id != that.id) return false; 89 | if (oid != that.oid) return false; 90 | if (pid != that.pid) return false; 91 | if (quantity != that.quantity) return false; 92 | if (money != null ? !money.equals(that.money) : that.money != null) return false; 93 | 94 | return true; 95 | } 96 | 97 | @Override 98 | public int hashCode() { 99 | int result = (int) (id ^ (id >>> 32)); 100 | result = 31 * result + (int) (oid ^ (oid >>> 32)); 101 | result = 31 * result + (int) (pid ^ (pid >>> 32)); 102 | result = 31 * result + (int) (quantity ^ (quantity >>> 32)); 103 | result = 31 * result + (money != null ? money.hashCode() : 0); 104 | return result; 105 | } 106 | 107 | /** 108 | * 通过id获取商品信息 109 | * @return 110 | */ 111 | public Product getProduct() { 112 | product = null; 113 | //通过id获取商品信息 114 | ProductService proSvs = new ProductServiceImpl(); 115 | try { 116 | product = proSvs.queryProductById((int)getPid()); 117 | } catch (SQLException e) { 118 | e.printStackTrace(); 119 | } 120 | return product; 121 | } 122 | 123 | public void setProduct(Product product) { 124 | this.product = product; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/entity/Paging.java: -------------------------------------------------------------------------------- 1 | package com.hwua.entity; 2 | 3 | import java.util.List; 4 | 5 | public class Paging { 6 | private Integer topPage;//上一页 7 | private Integer nextPage;//下一页 8 | private Integer totalPage;//总页数 9 | private Long totalNumber;//总记录数 10 | private Integer currentPage;//当前页 11 | private Integer pageSize;//每一页的记录数 12 | private List list;//每一页的商品 13 | private List cList;//每一页的留言 14 | 15 | /** 16 | * 获得上一页 17 | * @return 18 | */ 19 | public Integer getTopPage() { 20 | //如果当前页已经是首页 21 | if (currentPage==1){ 22 | return 1; 23 | } 24 | //上一页= 当前页-1 25 | topPage = currentPage - 1; 26 | return topPage; 27 | } 28 | 29 | public void setTopPage(Integer topPage) { 30 | this.topPage = topPage; 31 | } 32 | 33 | /** 34 | * 获得下一页 35 | * @return 36 | */ 37 | public Integer getNextPage() { 38 | //如果当前页已经是最后页 39 | if (currentPage>=getTotalPage()){ 40 | return currentPage; 41 | }else { 42 | //下一页 = 当前页+1 43 | nextPage = currentPage + 1; 44 | } 45 | return nextPage; 46 | } 47 | 48 | public void setNextPage(Integer nextPage) { 49 | this.nextPage = nextPage; 50 | } 51 | 52 | /** 53 | * 获得总页数 54 | * @return 55 | */ 56 | public Integer getTotalPage() { 57 | //总页数= 总记录数/每一页的记录数 58 | totalPage = (int)(totalNumber/pageSize); 59 | if (totalNumber%pageSize>0){ 60 | totalPage += 1; 61 | } 62 | return totalPage; 63 | } 64 | 65 | public void setTotalPage(Integer totalPage) { 66 | this.totalPage = totalPage; 67 | } 68 | 69 | public Long getTotalNumber() { 70 | return totalNumber; 71 | } 72 | 73 | public void setTotalNumber(Long totalNumber) { 74 | this.totalNumber = totalNumber; 75 | } 76 | 77 | public Integer getCurrentPage() { 78 | return currentPage; 79 | } 80 | 81 | public void setCurrentPage(Integer currentPage) { 82 | this.currentPage = currentPage; 83 | } 84 | 85 | public Integer getPageSize() { 86 | return pageSize; 87 | } 88 | 89 | public void setPageSize(Integer pageSize) { 90 | this.pageSize = pageSize; 91 | } 92 | 93 | public List getList() { 94 | return list; 95 | } 96 | 97 | public void setList(List list) { 98 | this.list = list; 99 | } 100 | 101 | @Override 102 | public String toString() { 103 | return "Paging{" + 104 | "topPage=" + topPage + 105 | ", nextPage=" + nextPage + 106 | ", totalPage=" + totalPage + 107 | ", totalNumber=" + totalNumber + 108 | ", currentPage=" + currentPage + 109 | ", pageSize=" + pageSize + 110 | ", list=" + list + 111 | '}'; 112 | } 113 | 114 | public List getCList() { 115 | return cList; 116 | } 117 | 118 | public void setCList(List cList) { 119 | this.cList = cList; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/entity/Product.java: -------------------------------------------------------------------------------- 1 | package com.hwua.entity; 2 | 3 | import javax.persistence.*; 4 | import java.math.BigDecimal; 5 | 6 | /*商品类*/ 7 | @Table(name = "amz_product", schema = "d_shop", catalog = "") 8 | public class Product { 9 | private long id;//商品id 10 | private String name;//商品名 11 | private String description;//商品描述 12 | private BigDecimal price;//商品价格 13 | private long stock;//商品库存 14 | private long major_id;//一级标题 15 | private long minor_id;//二级标题 16 | private String img_source;//商品图片 17 | private BigDecimal maxPrice;//商品最大金额 18 | 19 | @Override 20 | public String toString() { 21 | return "Product{" + 22 | "id=" + id + 23 | ", name='" + name + '\'' + 24 | ", description='" + description + '\'' + 25 | ", price=" + price + 26 | ", stock=" + stock + 27 | ", major_id=" + major_id + 28 | ", minor_id=" + minor_id + 29 | ", img_source='" + img_source + '\'' + 30 | '}'; 31 | } 32 | 33 | @Id 34 | @Column(name = "id") 35 | public long getId() { 36 | return id; 37 | } 38 | 39 | public void setId(long id) { 40 | this.id = id; 41 | } 42 | 43 | @Basic 44 | @Column(name = "name") 45 | public String getName() { 46 | return name; 47 | } 48 | 49 | public void setName(String name) { 50 | this.name = name; 51 | } 52 | 53 | @Basic 54 | @Column(name = "description") 55 | public String getDescription() { 56 | return description; 57 | } 58 | 59 | public void setDescription(String description) { 60 | this.description = description; 61 | } 62 | 63 | @Basic 64 | @Column(name = "price") 65 | public BigDecimal getPrice() { 66 | return price; 67 | } 68 | 69 | public void setPrice(BigDecimal price) { 70 | this.price = price; 71 | } 72 | 73 | @Basic 74 | @Column(name = "stock") 75 | public long getStock() { 76 | return stock; 77 | } 78 | 79 | public void setStock(long stock) { 80 | this.stock = stock; 81 | } 82 | 83 | @Basic 84 | @Column(name = "major_id") 85 | public long getMajor_id() { 86 | return major_id; 87 | } 88 | 89 | public void setMajor_id(long major_id) { 90 | this.major_id = major_id; 91 | } 92 | 93 | @Basic 94 | @Column(name = "minor_id") 95 | public long getMinor_id() { 96 | return minor_id; 97 | } 98 | 99 | public void setMinor_id(long minor_id) { 100 | this.minor_id = minor_id; 101 | } 102 | 103 | @Basic 104 | @Column(name = "img_source") 105 | public String getImg_source() { 106 | return img_source; 107 | } 108 | 109 | public void setImg_source(String img_source) { 110 | this.img_source = img_source; 111 | } 112 | 113 | @Override 114 | public boolean equals(Object o) { 115 | if (this == o) return true; 116 | if (o == null || getClass() != o.getClass()) return false; 117 | 118 | Product that = (Product) o; 119 | 120 | if (id != that.id) return false; 121 | if (stock != that.stock) return false; 122 | if (major_id != that.major_id) return false; 123 | if (minor_id != that.minor_id) return false; 124 | if (name != null ? !name.equals(that.name) : that.name != null) return false; 125 | if (description != null ? !description.equals(that.description) : that.description != null) return false; 126 | if (price != null ? !price.equals(that.price) : that.price != null) return false; 127 | if (img_source != null ? !img_source.equals(that.img_source) : that.img_source != null) return false; 128 | 129 | return true; 130 | } 131 | 132 | @Override 133 | public int hashCode() { 134 | int result = (int) (id ^ (id >>> 32)); 135 | result = 31 * result + (name != null ? name.hashCode() : 0); 136 | result = 31 * result + (description != null ? description.hashCode() : 0); 137 | result = 31 * result + (price != null ? price.hashCode() : 0); 138 | result = 31 * result + (int) (stock ^ (stock >>> 32)); 139 | result = 31 * result + (int) (major_id ^ (major_id >>> 32)); 140 | result = 31 * result + (int) (minor_id ^ (minor_id >>> 32)); 141 | result = 31 * result + (img_source != null ? img_source.hashCode() : 0); 142 | return result; 143 | } 144 | 145 | /** 146 | * 商品最大金额 = 库存*单价 147 | * @return 148 | */ 149 | public BigDecimal getMaxPrice() { 150 | return maxPrice = price.multiply(new BigDecimal(stock)); 151 | 152 | } 153 | 154 | public void setMaxPrice(BigDecimal maxPrice) { 155 | this.maxPrice = maxPrice; 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/entity/ProductCategory.java: -------------------------------------------------------------------------------- 1 | package com.hwua.entity; 2 | 3 | import javax.persistence.*; 4 | 5 | //商品种类 6 | @Table(name = "amz_product_category", schema = "d_shop", catalog = "") 7 | public class ProductCategory { 8 | private long id;//种类id 9 | private String name; //种类名称 10 | private long parentId;//父类id 11 | 12 | @Override 13 | public String toString() { 14 | return "ProductCategoryDao{" + 15 | "id=" + id + 16 | ", name='" + name + '\'' + 17 | ", parentId=" + parentId + 18 | '}'; 19 | } 20 | 21 | @Id 22 | @Column(name = "id") 23 | public long getId() { 24 | return id; 25 | } 26 | 27 | public void setId(long id) { 28 | this.id = id; 29 | } 30 | 31 | @Basic 32 | @Column(name = "name") 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | 41 | @Basic 42 | @Column(name = "parent_id") 43 | public long getParentId() { 44 | return parentId; 45 | } 46 | 47 | public void setParentId(long parentId) { 48 | this.parentId = parentId; 49 | } 50 | 51 | @Override 52 | public boolean equals(Object o) { 53 | if (this == o) return true; 54 | if (o == null || getClass() != o.getClass()) return false; 55 | 56 | ProductCategory that = (ProductCategory) o; 57 | 58 | if (id != that.id) return false; 59 | if (parentId != that.parentId) return false; 60 | if (name != null ? !name.equals(that.name) : that.name != null) return false; 61 | 62 | return true; 63 | } 64 | 65 | @Override 66 | public int hashCode() { 67 | int result = (int) (id ^ (id >>> 32)); 68 | result = 31 * result + (name != null ? name.hashCode() : 0); 69 | result = 31 * result + (int) (parentId ^ (parentId >>> 32)); 70 | return result; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/entity/ShopCart.java: -------------------------------------------------------------------------------- 1 | package com.hwua.entity; 2 | 3 | import com.hwua.service.I.ProductService; 4 | import com.hwua.service.ProductServiceImpl; 5 | 6 | import javax.persistence.*; 7 | import java.math.BigDecimal; 8 | import java.sql.SQLException; 9 | import java.util.List; 10 | 11 | //购物项 12 | @Table(name = "amz_shop_cart", schema = "d_shop", catalog = "") 13 | public class ShopCart { 14 | private long id;//购物车id 15 | private Integer pid;//商品id 16 | private int pnum;//商品数量 17 | private long uid;//用户id 18 | private Product pro;//商品信息 19 | private BigDecimal subtotal;//小计 20 | 21 | @Override 22 | public String toString() { 23 | return "ShopCart{" + 24 | "id=" + id + 25 | ", pid=" + pid + 26 | ", pnum=" + pnum + 27 | ", uid=" + uid + 28 | '}'; 29 | } 30 | 31 | @Id 32 | @Column(name = "id") 33 | public long getId() { 34 | return id; 35 | } 36 | 37 | public void setId(long id) { 38 | this.id = id; 39 | } 40 | 41 | @Basic 42 | @Column(name = "pid") 43 | public Integer getPid() { 44 | return pid; 45 | } 46 | 47 | public void setPid(Integer pid) { 48 | this.pid = pid; 49 | } 50 | 51 | @Basic 52 | @Column(name = "pnum") 53 | public int getPnum() { 54 | return pnum; 55 | } 56 | 57 | public void setPnum(int pnum) { 58 | this.pnum = pnum; 59 | } 60 | 61 | @Basic 62 | @Column(name = "uid") 63 | public long getUid() { 64 | return uid; 65 | } 66 | 67 | public void setUid(long uid) { 68 | this.uid = uid; 69 | } 70 | 71 | @Override 72 | public boolean equals(Object o) { 73 | if (this == o) return true; 74 | if (o == null || getClass() != o.getClass()) return false; 75 | 76 | ShopCart that = (ShopCart) o; 77 | 78 | if (id != that.id) return false; 79 | if (pid != that.pid) return false; 80 | if (pnum != that.pnum) return false; 81 | if (uid != that.uid) return false; 82 | 83 | return true; 84 | } 85 | 86 | @Override 87 | public int hashCode() { 88 | int result = (int) (id ^ (id >>> 32)); 89 | result = 31 * result + (int) (pid ^ (pid >>> 32)); 90 | result = 31 * result + pnum; 91 | result = 31 * result + (int) (uid ^ (uid >>> 32)); 92 | return result; 93 | } 94 | 95 | /** 96 | * 获取对应id的商品 97 | * @return 98 | */ 99 | public Product getPro() { 100 | pro = null; 101 | //通过id获取商品信息 102 | ProductService proSvs = new ProductServiceImpl(); 103 | try { 104 | pro = proSvs.queryProductById(getPid()); 105 | } catch (SQLException e) { 106 | e.printStackTrace(); 107 | } 108 | return pro; 109 | } 110 | 111 | public void setPro(Product pro) { 112 | this.pro = pro; 113 | } 114 | 115 | /** 116 | * 商品小计 = 商品数量*单价 117 | * @return 118 | */ 119 | public BigDecimal getSubtotal() { 120 | //获得商品单价 121 | BigDecimal price = getPro().getPrice(); 122 | //商品数量*单价 123 | subtotal = price.multiply(new BigDecimal(pnum)); 124 | return subtotal; 125 | } 126 | 127 | public void setSubtotal(BigDecimal subtotal) { 128 | this.subtotal = subtotal; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.hwua.entity; 2 | 3 | import javax.persistence.*; 4 | import java.sql.Date; 5 | 6 | //用户类 7 | @Table(name = "amz_user", schema = "d_shop", catalog = "") 8 | public class User { 9 | private long id;//id 10 | private String uname;//用户名 11 | private String pwd;//用户密码 12 | private int sex;//年龄 13 | private Date birthday;//生日 14 | private String idcard;//身份证 15 | private String email;//邮箱 16 | private String mobile;//电话号码 17 | private String address;//地址 18 | private int utype;//用户类型 19 | 20 | @Override 21 | public String toString() { 22 | return "User{" + 23 | "id=" + id + 24 | ", uname='" + uname + '\'' + 25 | ", pwd='" + pwd + '\'' + 26 | ", sex=" + sex + 27 | ", birthday=" + birthday + 28 | ", idcard='" + idcard + '\'' + 29 | ", email='" + email + '\'' + 30 | ", mobile='" + mobile + '\'' + 31 | ", address='" + address + '\'' + 32 | ", utype=" + utype + 33 | '}'; 34 | } 35 | 36 | @Id 37 | @Column(name = "id") 38 | public long getId() { 39 | return id; 40 | } 41 | 42 | public void setId(long id) { 43 | this.id = id; 44 | } 45 | 46 | @Basic 47 | @Column(name = "uname") 48 | public String getUname() { 49 | return uname; 50 | } 51 | 52 | public void setUname(String uname) { 53 | this.uname = uname; 54 | } 55 | 56 | @Basic 57 | @Column(name = "pwd") 58 | public String getPwd() { 59 | return pwd; 60 | } 61 | 62 | public void setPwd(String pwd) { 63 | this.pwd = pwd; 64 | } 65 | 66 | @Basic 67 | @Column(name = "sex") 68 | public int getSex() { 69 | return sex; 70 | } 71 | 72 | public void setSex(int sex) { 73 | this.sex = sex; 74 | } 75 | 76 | @Basic 77 | @Column(name = "birthday") 78 | public Date getBirthday() { 79 | return birthday; 80 | } 81 | 82 | public void setBirthday(Date birthday) { 83 | this.birthday = birthday; 84 | } 85 | 86 | @Basic 87 | @Column(name = "idcard") 88 | public String getIdcard() { 89 | return idcard; 90 | } 91 | 92 | public void setIdcard(String idcard) { 93 | this.idcard = idcard; 94 | } 95 | 96 | @Basic 97 | @Column(name = "email") 98 | public String getEmail() { 99 | return email; 100 | } 101 | 102 | public void setEmail(String email) { 103 | this.email = email; 104 | } 105 | 106 | @Basic 107 | @Column(name = "mobile") 108 | public String getMobile() { 109 | return mobile; 110 | } 111 | 112 | public void setMobile(String mobile) { 113 | this.mobile = mobile; 114 | } 115 | 116 | @Basic 117 | @Column(name = "address") 118 | public String getAddress() { 119 | return address; 120 | } 121 | 122 | public void setAddress(String address) { 123 | this.address = address; 124 | } 125 | 126 | @Basic 127 | @Column(name = "utype") 128 | public int getUtype() { 129 | return utype; 130 | } 131 | 132 | public void setUtype(int utype) { 133 | this.utype = utype; 134 | } 135 | 136 | @Override 137 | public boolean equals(Object o) { 138 | if (this == o) return true; 139 | if (o == null || getClass() != o.getClass()) return false; 140 | 141 | User amzUser = (User) o; 142 | 143 | if (id != amzUser.id) return false; 144 | if (sex != amzUser.sex) return false; 145 | if (utype != amzUser.utype) return false; 146 | if (uname != null ? !uname.equals(amzUser.uname) : amzUser.uname != null) return false; 147 | if (pwd != null ? !pwd.equals(amzUser.pwd) : amzUser.pwd != null) return false; 148 | if (birthday != null ? !birthday.equals(amzUser.birthday) : amzUser.birthday != null) return false; 149 | if (idcard != null ? !idcard.equals(amzUser.idcard) : amzUser.idcard != null) return false; 150 | if (email != null ? !email.equals(amzUser.email) : amzUser.email != null) return false; 151 | if (mobile != null ? !mobile.equals(amzUser.mobile) : amzUser.mobile != null) return false; 152 | if (address != null ? !address.equals(amzUser.address) : amzUser.address != null) return false; 153 | 154 | return true; 155 | } 156 | 157 | @Override 158 | public int hashCode() { 159 | int result = (int) (id ^ (id >>> 32)); 160 | result = 31 * result + (uname != null ? uname.hashCode() : 0); 161 | result = 31 * result + (pwd != null ? pwd.hashCode() : 0); 162 | result = 31 * result + sex; 163 | result = 31 * result + (birthday != null ? birthday.hashCode() : 0); 164 | result = 31 * result + (idcard != null ? idcard.hashCode() : 0); 165 | result = 31 * result + (email != null ? email.hashCode() : 0); 166 | result = 31 * result + (mobile != null ? mobile.hashCode() : 0); 167 | result = 31 * result + (address != null ? address.hashCode() : 0); 168 | result = 31 * result + utype; 169 | return result; 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/service/CommentServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.hwua.service; 2 | 3 | 4 | import com.hwua.dao.CommentDaoImpl; 5 | import com.hwua.dao.I.CommentDao; 6 | import com.hwua.entity.Comment; 7 | import com.hwua.service.I.CommentService; 8 | 9 | 10 | import java.sql.SQLException; 11 | import java.util.List; 12 | 13 | public class CommentServiceImpl implements CommentService { 14 | private CommentDao commentDao = null; 15 | public CommentServiceImpl(){ 16 | commentDao = new CommentDaoImpl(); 17 | } 18 | /** 19 | * 查询所有留言 20 | * @return 21 | * @throws SQLException 22 | */ 23 | @Override 24 | public List QueryAllComment() throws SQLException { 25 | return commentDao.QueryAllComment(); 26 | } 27 | 28 | @Override 29 | public Integer addComment(Comment comment) throws SQLException { 30 | return commentDao.addComment(comment); 31 | } 32 | 33 | /** 34 | * 分页查询 35 | * @param start 36 | * @param number 37 | * @return 38 | * @throws SQLException 39 | */ 40 | @Override 41 | public List querypageComment(Integer start, Integer number) throws SQLException { 42 | return commentDao.querypageComment(start,number ); 43 | } 44 | 45 | /** @Override 46 | * 查询留言个数 47 | * @return 48 | * @throws SQLException 49 | */ 50 | public Long queryCount() throws SQLException { 51 | return commentDao.queryCount(); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/service/I/CommentService.java: -------------------------------------------------------------------------------- 1 | package com.hwua.service.I; 2 | 3 | import com.hwua.entity.Comment; 4 | 5 | import java.sql.SQLException; 6 | import java.util.List; 7 | 8 | public interface CommentService { 9 | /** 10 | * 查询所有留言 11 | * @return 12 | * @throws SQLException 13 | */ 14 | public List QueryAllComment() throws SQLException; 15 | 16 | /** 17 | * 添加留言 18 | * @param comment 19 | * @return 20 | * @throws SQLException 21 | */ 22 | public Integer addComment(Comment comment) throws SQLException; 23 | 24 | /** 25 | * 分页查询 26 | * @param start 27 | * @param number 28 | * @return 29 | * @throws SQLException 30 | */ 31 | public List querypageComment(Integer start, Integer number) throws SQLException; 32 | 33 | /** 34 | * 查询留言个数 35 | * @return 36 | * @throws SQLException 37 | */ 38 | public Long queryCount() throws SQLException; 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/service/I/NewService.java: -------------------------------------------------------------------------------- 1 | package com.hwua.service.I; 2 | 3 | import com.hwua.entity.News; 4 | 5 | import java.sql.SQLException; 6 | import java.util.List; 7 | 8 | public interface NewService { 9 | public abstract List queryNews() throws SQLException;//查询所有的新闻 10 | public abstract News queryNewById(Integer id) throws SQLException;//通过新闻编号查询新闻 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/service/I/OrderDetailService.java: -------------------------------------------------------------------------------- 1 | package com.hwua.service.I; 2 | 3 | import com.hwua.entity.OrderDetail; 4 | 5 | import java.sql.SQLException; 6 | import java.util.List; 7 | 8 | public interface OrderDetailService { 9 | public abstract List queryOrderDetailByOid(Long oid) throws SQLException;//通过订单id查询订单明细 10 | public abstract Integer insertOrderDetail(OrderDetail orderDetail) throws SQLException;//插入订单明细 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/service/I/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.hwua.service.I; 2 | 3 | import com.hwua.entity.Order; 4 | import com.hwua.entity.OrderDetail; 5 | 6 | import java.sql.SQLException; 7 | import java.util.List; 8 | 9 | 10 | public interface OrderService { 11 | public abstract List queryOrderByUid(Long uid) throws SQLException;//通过用户id查询订单信息 12 | public abstract Boolean insertOrder(Order order)throws SQLException;//插入订单和订单明细 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/service/I/ProductCategoryService.java: -------------------------------------------------------------------------------- 1 | package com.hwua.service.I; 2 | 3 | import com.hwua.entity.ProductCategory; 4 | 5 | import java.sql.SQLException; 6 | import java.util.List; 7 | 8 | public interface ProductCategoryService { 9 | //查询一级产品分类 10 | public abstract List queryParent() throws SQLException; 11 | //查询一级产品分类的id 12 | public abstract List queryParentById() throws SQLException; 13 | //查询二级产品分类 14 | public abstract List querySon(Long id) throws SQLException; 15 | public abstract Long queryParentId(Long sonId) throws SQLException;//通过二级ID查询一级ID 16 | public abstract String queryProName(Long id) throws SQLException;//通过id查询分类名 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/service/I/ProductService.java: -------------------------------------------------------------------------------- 1 | package com.hwua.service.I; 2 | 3 | import com.hwua.entity.Product; 4 | 5 | import java.sql.SQLException; 6 | import java.util.List; 7 | 8 | public interface ProductService { 9 | public abstract List queryAllProduct() throws SQLException;//查询所有商品 10 | public abstract List queryMaxProduct() throws SQLException;//查询库存最多的商品 11 | public abstract List queryProductLimit(Integer start,Integer pageSize) throws SQLException;//分页查询 12 | public abstract Product queryProductById(Integer id) throws SQLException;//通过id查询 13 | public abstract Long queryProductCount() throws SQLException;//查询出商品总记录数 14 | public abstract List queryProByParentId(Long parentId) throws SQLException;//通过一级ID查询商品 15 | public abstract List queryProBySonId(Long sonId) throws SQLException;//通过二级ID查询商品 16 | public abstract List queryLikeByName(String proName) throws SQLException;//通过字段查询到宝贝 17 | public abstract Integer delProStock(Long id,Long pnum) throws SQLException;//删除对应的库存 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/service/I/ShopCartService.java: -------------------------------------------------------------------------------- 1 | package com.hwua.service.I; 2 | 3 | import com.hwua.entity.ShopCart; 4 | 5 | import java.sql.SQLException; 6 | import java.util.List; 7 | 8 | public interface ShopCartService { 9 | public abstract boolean addProduct(ShopCart shopCart) throws SQLException;//添加商品 10 | public abstract boolean delProduct(Long id) throws SQLException;//删除商品 11 | public abstract boolean updateNum(int pnum,Long id) throws SQLException;//修改商品数量 12 | public abstract List showCart(Long uid) throws SQLException;//显示购物车明细 13 | public abstract boolean clearShopCart(Long uid) throws SQLException;//请空购物车 14 | public abstract ShopCart queryShopCart(Long id)throws SQLException;//根据指定购物项id查询 15 | public abstract Integer updateUid(Long loginID) throws SQLException;//更改用户id 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/service/I/UserService.java: -------------------------------------------------------------------------------- 1 | package com.hwua.service.I; 2 | 3 | import com.hwua.entity.User; 4 | 5 | import java.sql.SQLException; 6 | 7 | public interface UserService { 8 | public abstract User login(String name,String pwd) throws SQLException;//登陆 9 | public abstract boolean register(User user) throws SQLException;//注册 10 | public abstract boolean queryName(String name) throws SQLException;//通过姓名查询用户 11 | public abstract User queryUserById(Long id) throws SQLException;//通过id查询用户 12 | public abstract User retrievePwd(String uname,String email) throws SQLException;//通过姓名和邮箱找回密码 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/service/NewServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.hwua.service; 2 | 3 | import com.hwua.dao.I.NewDao; 4 | import com.hwua.dao.NewDaoImpl; 5 | import com.hwua.entity.News; 6 | import com.hwua.service.I.NewService; 7 | 8 | import java.sql.SQLException; 9 | import java.util.List; 10 | 11 | public class NewServiceImpl implements NewService { 12 | private static NewDao newDao = new NewDaoImpl(); 13 | 14 | /** 15 | * 查询所有新闻 16 | * @return 17 | * @throws SQLException 18 | */ 19 | @Override 20 | public List queryNews() throws SQLException { 21 | return newDao.queryNews(); 22 | } 23 | 24 | /** 25 | * 通过id查询新闻 26 | * @param id 27 | * @return 28 | * @throws SQLException 29 | */ 30 | @Override 31 | public News queryNewById(Integer id) throws SQLException { 32 | return newDao.queryNewById(id); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/service/OrderDetailServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.hwua.service; 2 | 3 | import com.hwua.dao.I.OrderDetailDao; 4 | import com.hwua.dao.OrderDetailDaoImpl; 5 | import com.hwua.entity.OrderDetail; 6 | import com.hwua.service.I.OrderDetailService; 7 | 8 | import java.sql.SQLException; 9 | import java.util.List; 10 | 11 | public class OrderDetailServiceImpl implements OrderDetailService { 12 | private static OrderDetailDao orderDetailDao = new OrderDetailDaoImpl(); 13 | 14 | /** 15 | * 通过订单id查询订单明细 16 | * @param oid 17 | * @return 18 | * @throws SQLException 19 | */ 20 | @Override 21 | public List queryOrderDetailByOid(Long oid) throws SQLException { 22 | return orderDetailDao.queryOrderDetailByOid(oid); 23 | } 24 | 25 | /** 26 | * 添加订单明细 27 | * @param orderDetail 28 | * @return 29 | * @throws SQLException 30 | */ 31 | @Override 32 | public Integer insertOrderDetail(OrderDetail orderDetail) throws SQLException { 33 | return orderDetailDao.insertOrderDetail(orderDetail); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/service/OrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.hwua.service; 2 | 3 | import com.hwua.dao.I.OrderDao; 4 | import com.hwua.dao.I.OrderDetailDao; 5 | import com.hwua.dao.OrderDaoImpl; 6 | import com.hwua.dao.OrderDetailDaoImpl; 7 | import com.hwua.entity.Order; 8 | import com.hwua.entity.OrderDetail; 9 | import com.hwua.service.I.OrderService; 10 | 11 | import java.sql.SQLException; 12 | import java.util.List; 13 | 14 | public class OrderServiceImpl implements OrderService { 15 | private static OrderDao orderDao = new OrderDaoImpl(); 16 | 17 | /** 18 | * 查询订单 19 | * @param uid 20 | * @return 21 | * @throws SQLException 22 | */ 23 | @Override 24 | public List queryOrderByUid(Long uid) throws SQLException { 25 | return orderDao.queryOrderByUid(uid); 26 | } 27 | 28 | 29 | @Override 30 | public Boolean insertOrder(Order order) throws SQLException{ 31 | //插入订单。 32 | Integer integer = orderDao.insertOrder(order); 33 | if (integer>0){ 34 | return true; 35 | } 36 | return false; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/service/ProductCategoryServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.hwua.service; 2 | 3 | import com.hwua.dao.I.ProductCategoryDao; 4 | import com.hwua.dao.ProductCategoryDaoImpl; 5 | import com.hwua.entity.ProductCategory; 6 | import com.hwua.service.I.ProductCategoryService; 7 | 8 | import java.sql.SQLException; 9 | import java.util.List; 10 | 11 | public class ProductCategoryServiceImpl implements ProductCategoryService { 12 | private static ProductCategoryDao productDao = new ProductCategoryDaoImpl(); 13 | 14 | /** 15 | * 查询一级商品分类 16 | * @return 结果集 17 | * @throws SQLException 18 | */ 19 | @Override 20 | public List queryParent() throws SQLException { 21 | return productDao.queryParent(); 22 | } 23 | 24 | /** 25 | * 查询一级分类的id 26 | * @return 27 | * @throws SQLException 28 | */ 29 | @Override 30 | public List queryParentById() throws SQLException { 31 | return productDao.queryParentById(); 32 | } 33 | 34 | /** 35 | * 查询二级商品分类 36 | * @param id 37 | * @return 38 | * @throws SQLException 39 | */ 40 | @Override 41 | public List querySon(Long id) throws SQLException { 42 | List list = productDao.querySon(id); 43 | //把集合中的一级分类删除 44 | for (int i = 0; i < list.size(); i++) { 45 | //如果id是一级分类的id就删除这个元素 46 | if (list.get(i).getId()==id){ 47 | list.remove(i); 48 | } 49 | } 50 | return list; 51 | } 52 | 53 | /** 54 | * 通过id查询父类id 55 | * @param sonId 56 | * @return 57 | * @throws SQLException 58 | */ 59 | @Override 60 | public Long queryParentId(Long sonId) throws SQLException { 61 | return productDao.queryParentId(sonId); 62 | } 63 | 64 | /** 65 | * 通过id查询到分类名 66 | * @param id 67 | * @return 68 | * @throws SQLException 69 | */ 70 | @Override 71 | public String queryProName(Long id) throws SQLException { 72 | return productDao.queryProName(id); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/service/ProductServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.hwua.service; 2 | 3 | import com.hwua.dao.I.ProductDao; 4 | import com.hwua.dao.ProductDaoImpl; 5 | import com.hwua.entity.Product; 6 | import com.hwua.service.I.ProductService; 7 | 8 | import java.sql.SQLException; 9 | import java.util.List; 10 | 11 | public class ProductServiceImpl implements ProductService { 12 | private static ProductDao ps = new ProductDaoImpl(); 13 | 14 | /** 15 | * 查询商品结果集 16 | * @return 17 | * @throws SQLException 18 | */ 19 | @Override 20 | public List queryAllProduct() throws SQLException { 21 | return ps.queryAllProduct(); 22 | } 23 | 24 | /** 25 | * 查询库存最多的前6个商品 26 | * @return 27 | * @throws SQLException 28 | */ 29 | @Override 30 | public List queryMaxProduct() throws SQLException { 31 | return ps.queryMaxProduct(); 32 | } 33 | 34 | /** 35 | * 分页查询 36 | * @param start 37 | * @param pageSize 38 | * @return 39 | * @throws SQLException 40 | */ 41 | @Override 42 | public List queryProductLimit(Integer start, Integer pageSize) throws SQLException { 43 | return ps.queryProductLimit(start,pageSize); 44 | } 45 | 46 | /** 47 | * 通过id查询商品 48 | * @param id 49 | * @return 50 | * @throws SQLException 51 | */ 52 | @Override 53 | public Product queryProductById(Integer id) throws SQLException { 54 | return ps.queryProductById(id); 55 | } 56 | 57 | /** 58 | * 查询商品数量 59 | * @return 60 | * @throws SQLException 61 | */ 62 | @Override 63 | public Long queryProductCount() throws SQLException { 64 | return ps.queryProductCount(); 65 | } 66 | 67 | @Override 68 | public List queryProByParentId(Long parentId) throws SQLException { 69 | return ps.queryProByParentId(parentId); 70 | } 71 | 72 | @Override 73 | public List queryProBySonId(Long sonId) throws SQLException { 74 | return ps.queryProBySonId(sonId); 75 | } 76 | 77 | @Override 78 | public List queryLikeByName(String proName) throws SQLException { 79 | return ps.queryLikeByName(proName); 80 | } 81 | 82 | @Override 83 | public Integer delProStock(Long id, Long pnum) throws SQLException { 84 | return ps.delProStock(id,pnum); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/service/ShopCartServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.hwua.service; 2 | 3 | import com.hwua.dao.I.ShopCartDao; 4 | import com.hwua.dao.ShopCartDaoImpl; 5 | import com.hwua.entity.ShopCart; 6 | import com.hwua.service.I.ShopCartService; 7 | 8 | import java.sql.SQLException; 9 | import java.util.List; 10 | 11 | public class ShopCartServiceImpl implements ShopCartService { 12 | private static ShopCartDao cartDao = new ShopCartDaoImpl(); 13 | 14 | /** 15 | * 添加商品 16 | * @param shopCart 17 | * @return 18 | * @throws SQLException 19 | */ 20 | @Override 21 | public boolean addProduct(ShopCart shopCart) throws SQLException { 22 | //通过uid和pid查询到他的购物项 23 | ShopCart userCar = cartDao.queryShopCart(shopCart.getPid(), shopCart.getUid()); 24 | int sum = 0; 25 | int num; 26 | //先判断这个商品已存在,如果存在就增加数量 27 | if (userCar!=null){ 28 | sum = shopCart.getPnum()+userCar.getPnum(); 29 | num = cartDao.updateNum(sum,userCar.getId()); 30 | }else { 31 | num = cartDao.addProduct(shopCart); 32 | } 33 | if (num >0 ){ 34 | return true; 35 | } 36 | 37 | return false; 38 | } 39 | 40 | /** 41 | * 删除购物项 42 | * @param id 43 | * @return 44 | * @throws SQLException 45 | */ 46 | @Override 47 | public boolean delProduct(Long id) throws SQLException { 48 | Integer num = cartDao.delProduct(id); 49 | if (num >0 ){ 50 | return true; 51 | } 52 | return false; 53 | } 54 | 55 | /** 56 | * 修改购物项的数量 57 | * @param pnum 58 | * @param id 59 | * @return 60 | * @throws SQLException 61 | */ 62 | @Override 63 | public boolean updateNum(int pnum, Long id) throws SQLException { 64 | Integer num = cartDao.updateNum(pnum, id); 65 | if (num >0 ){ 66 | return true; 67 | } 68 | return false; 69 | } 70 | 71 | /** 72 | * 显示用户购物车 73 | * @param uid 74 | * @return 75 | * @throws SQLException 76 | */ 77 | @Override 78 | public List showCart(Long uid) throws SQLException { 79 | return cartDao.showCart(uid); 80 | } 81 | 82 | /* public static void main(String[] args) throws SQLException { 83 | ShopCartServiceImpl s = new ShopCartServiceImpl(); 84 | List shopCarts = s.showCart(1L); 85 | System.out.println(shopCarts); 86 | }*/ 87 | /** 88 | * 清空购物车 89 | * @param uid 90 | * @return 91 | * @throws SQLException 92 | */ 93 | @Override 94 | public boolean clearShopCart(Long uid) throws SQLException { 95 | Integer num = cartDao.clearShopCart(uid); 96 | if (num >0 ){ 97 | return true; 98 | } 99 | return false; 100 | } 101 | 102 | /** 103 | * 查询指定购物项 104 | * @param id 105 | * @return 106 | * @throws SQLException 107 | */ 108 | @Override 109 | public ShopCart queryShopCart(Long id) throws SQLException { 110 | return cartDao.queryShopCart(id); 111 | } 112 | 113 | /** 114 | * 更改用户id 115 | * @param loginID 116 | * @return 117 | * @throws SQLException 118 | */ 119 | @Override 120 | public Integer updateUid(Long loginID) throws SQLException { 121 | return cartDao.updateUid(loginID); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/service/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.hwua.service; 2 | 3 | import com.hwua.dao.I.UserDao; 4 | import com.hwua.dao.UserDaoImpl; 5 | import com.hwua.entity.User; 6 | import com.hwua.service.I.UserService; 7 | 8 | import java.sql.SQLException; 9 | 10 | public class UserServiceImpl implements UserService { 11 | private static UserDao userDao = new UserDaoImpl(); 12 | 13 | /** 14 | * 登陆 15 | * @param name,pwd 16 | * @return 登陆者信息 17 | * @throws SQLException 18 | */ 19 | @Override 20 | public User login(String name,String pwd) throws SQLException { 21 | return userDao.queryUser(name,pwd); 22 | } 23 | 24 | /** 25 | * 注册 26 | * @param user 27 | * @return 28 | * @throws SQLException 29 | */ 30 | @Override 31 | public boolean register(User user) throws SQLException { 32 | //先判断用户名是否存在 33 | boolean b = queryName(user.getUname()); 34 | if (b) { 35 | //不存在再进行注册 36 | Integer flag = userDao.insertUser(user); 37 | if (flag > 0) { 38 | return true; 39 | } 40 | } 41 | return false; 42 | } 43 | 44 | /** 45 | * 查询用户名 46 | * @param name 47 | * @return 48 | * @throws SQLException 49 | */ 50 | @Override 51 | public boolean queryName(String name) throws SQLException { 52 | //查不到此用户名既可以注册,否则已存在 53 | User user = userDao.queryName(name); 54 | if (user==null){ 55 | return true; 56 | } 57 | return false; 58 | } 59 | 60 | /** 61 | * 通过id查询用户 62 | * @param id 63 | * @return 64 | * @throws SQLException 65 | */ 66 | @Override 67 | public User queryUserById(Long id) throws SQLException { 68 | return userDao.queryUserById(id); 69 | } 70 | 71 | /** 72 | * 通过姓名和email找回密码 73 | * @param uname 74 | * @param email 75 | * @return 76 | * @throws SQLException 77 | */ 78 | @Override 79 | public User retrievePwd(String uname, String email) throws SQLException { 80 | return userDao.queryUserByEmail(uname,email); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/utils/DruidPool.java: -------------------------------------------------------------------------------- 1 | package com.hwua.utils; 2 | 3 | import com.alibaba.druid.pool.DruidDataSourceFactory; 4 | 5 | import javax.sql.DataSource; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.sql.Connection; 9 | import java.sql.SQLException; 10 | import java.util.Properties; 11 | 12 | public class DruidPool { 13 | private static DataSource ds; 14 | private static ThreadLocal tl = new ThreadLocal<>();//生成本地线程类 15 | 16 | public static DataSource getDruidDS(){ 17 | //读取配置文件 18 | InputStream is = DruidPool.class.getClassLoader().getResourceAsStream("druid.properties"); 19 | //调用输入流读取 20 | Properties pro = new Properties(); 21 | try { 22 | pro.load(is); 23 | ds = DruidDataSourceFactory.createDataSource(pro); 24 | } catch (Exception e) { 25 | e.printStackTrace(); 26 | } 27 | 28 | return ds; 29 | } 30 | 31 | //获取一个连接对象,第一次获取是从数据源中取一个绑定到线程上,后面直接从线程上去获取绑定的连接对象 32 | public static Connection getConnection() throws SQLException { 33 | Connection conn = tl.get(); 34 | //如果是第一次,创建一个绑定到本地线程 35 | if (conn==null){ 36 | conn = ds.getConnection(); 37 | tl.set(conn); 38 | } 39 | return conn; 40 | 41 | } 42 | 43 | //开启事务 44 | public static void startTransaction() throws SQLException { 45 | Connection conn = getConnection(); 46 | conn.setAutoCommit(false);//开启事务 47 | } 48 | 49 | //提交事务 50 | public static void commit() throws SQLException { 51 | Connection conn = getConnection(); 52 | conn.commit();//提交事务 53 | conn.close();//关闭资源 54 | tl.remove();//删除本地线程 55 | } 56 | 57 | //回滚事务 58 | public static void rollback() throws SQLException { 59 | Connection conn = getConnection(); 60 | conn.rollback(); 61 | conn.close();//关闭资源 62 | tl.remove();//删除本地线程 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/web/filter/AllFilter.java: -------------------------------------------------------------------------------- 1 | package com.hwua.web.filter; 2 | 3 | import javax.servlet.*; 4 | import javax.servlet.annotation.WebFilter; 5 | import javax.servlet.http.HttpServletRequest; 6 | import javax.servlet.http.HttpServletResponse; 7 | import java.io.IOException; 8 | 9 | @WebFilter("/*") 10 | public class AllFilter implements Filter { 11 | 12 | @Override 13 | public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException { 14 | //设置全局servlet的编码 15 | HttpServletRequest request = (HttpServletRequest) req; 16 | HttpServletResponse response = (HttpServletResponse) resp; 17 | request.setCharacterEncoding("utf-8"); 18 | response.setContentType("text/html;charset=utf-8"); 19 | chain.doFilter(req, resp); 20 | } 21 | 22 | @Override 23 | public void init(FilterConfig filterConfig) throws ServletException { 24 | 25 | } 26 | 27 | 28 | @Override 29 | public void destroy() { 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/web/servlet/BuyServlet.java: -------------------------------------------------------------------------------- 1 | package com.hwua.web.servlet; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.hwua.entity.*; 5 | import com.hwua.service.*; 6 | import com.hwua.service.I.*; 7 | 8 | import javax.servlet.ServletException; 9 | import javax.servlet.annotation.WebServlet; 10 | import javax.servlet.http.HttpServlet; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | import javax.servlet.http.HttpSession; 14 | import java.io.IOException; 15 | import java.math.BigDecimal; 16 | import java.sql.SQLException; 17 | import java.sql.Timestamp; 18 | import java.util.Date; 19 | import java.util.List; 20 | 21 | @WebServlet("/doBuy") 22 | public class BuyServlet extends HttpServlet { 23 | private static ProductCategoryService pcs; 24 | private static ObjectMapper mapper ; 25 | private static ProductService ps; 26 | private static ShopCartService shopCarSvs; 27 | private static OrderService orderSvs; 28 | private static OrderDetailService odSvs; 29 | private static UserService userSvc; 30 | 31 | 32 | @Override 33 | public void init() throws ServletException { 34 | orderSvs = new OrderServiceImpl(); 35 | odSvs = new OrderDetailServiceImpl(); 36 | shopCarSvs = new ShopCartServiceImpl(); 37 | pcs = new ProductCategoryServiceImpl(); 38 | mapper = new ObjectMapper(); 39 | ps = new ProductServiceImpl(); 40 | userSvc = new UserServiceImpl(); 41 | } 42 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 43 | String param = request.getParameter("param"); 44 | Order order = new Order(); 45 | OrderDetail orderDetail = new OrderDetail(); 46 | //获取当前用户信息 47 | HttpSession session = request.getSession(false); 48 | User user = (User)session.getAttribute("user"); 49 | //订单总价 50 | BigDecimal totalPrice = new BigDecimal(0); 51 | //获取当前时间字符串 52 | Timestamp times = new Timestamp(new Date().getTime()); 53 | if (param.equals("buy")){//购物车结算 54 | 55 | //如果没有登陆,跳转到登陆页面 56 | if (user==null){ 57 | response.sendRedirect(request.getContextPath()+"/login.jsp"); 58 | }else { 59 | //获取用户id 60 | long uid = user.getId(); 61 | try { 62 | 63 | //获取该用户的购物车 64 | List shopCarts = shopCarSvs.showCart(uid); 65 | for (ShopCart shopCart : shopCarts) { 66 | //累加购物项获得总价 67 | totalPrice = totalPrice.add(shopCart.getSubtotal()); 68 | } 69 | 70 | order.setUid(uid);//用户id 71 | order.setUname(user.getUname());//用户姓名 72 | order.setUaddress(user.getAddress());//用户地址 73 | order.setCreate_time(times);//时间 74 | order.setMoney(totalPrice);//金额 75 | //添加订单 76 | orderSvs.insertOrder(order); 77 | 78 | //获取本次订单的id 79 | List orders = orderSvs.queryOrderByUid(uid); 80 | long orderId = orders.get(0).getId(); 81 | orderDetail.setOid(orderId);//设置订单id 82 | //每个购物项对应一个订单明细 83 | for (ShopCart shopCart : shopCarts) { 84 | orderDetail.setPid(shopCart.getPid());//设置商品id 85 | orderDetail.setQuantity(shopCart.getPnum());//设置商品数量 86 | orderDetail.setMoney(shopCart.getSubtotal());//设置小计金额 87 | //添加订单明细 88 | odSvs.insertOrderDetail(orderDetail); 89 | //删除对应的库存 = 原库存 - 购买的数量 90 | Long pnum = shopCart.getPro().getStock() - shopCart.getPnum(); 91 | //调用方法更改库存 92 | ps.delProStock(shopCart.getPro().getId(),pnum); 93 | } 94 | 95 | //清空购物车 96 | shopCarSvs.clearShopCart(uid); 97 | 98 | //把订单明细和订单放入到作用域,并跳转到订单页面 99 | session.setAttribute("orderList",orders); 100 | response.sendRedirect(request.getContextPath()+"/shopping-result.jsp"); 101 | } catch (SQLException e) { 102 | e.printStackTrace(); 103 | } 104 | } 105 | }else if (param.equals("buyOne")){//立即购买操作 106 | String pid = request.getParameter("pid");//商品id 107 | Long pnum = Long.parseLong(request.getParameter("pnum"));//商品数量 108 | 109 | //如果没有登陆,跳转到登陆页面 110 | if (user==null){ 111 | response.sendRedirect(request.getContextPath()+"/login.jsp"); 112 | }else { 113 | //获取用户id 114 | long uid = user.getId(); 115 | try { 116 | //查询商品单价 117 | Product product = ps.queryProductById(Integer.parseInt(pid)); 118 | totalPrice = product.getPrice().multiply(new BigDecimal(pnum));//获取小计 119 | //添加订单 120 | order.setUid(uid);//用户id 121 | order.setUname(user.getUname());//用户姓名 122 | order.setUaddress(user.getAddress());//用户地址 123 | order.setCreate_time(times);//时间 124 | order.setMoney(totalPrice);//金额 125 | //添加订单 126 | orderSvs.insertOrder(order); 127 | //获取本次订单的id 128 | List orders = orderSvs.queryOrderByUid(uid); 129 | long orderId = orders.get(0).getId(); 130 | orderDetail.setOid(orderId);//设置订单id 131 | orderDetail.setPid(Long.parseLong(pid));//设置商品id 132 | orderDetail.setQuantity(pnum);//设置商品数量 133 | orderDetail.setMoney(totalPrice);//设置小计金额 134 | //添加订单明细 135 | odSvs.insertOrderDetail(orderDetail); 136 | //删除对应库存 137 | Long num =product.getStock() - pnum; 138 | ps.delProStock(Long.parseLong(pid),num); 139 | //把订单明细和订单放入到作用域,并跳转到订单页面 140 | session.setAttribute("orderList",orders); 141 | response.sendRedirect(request.getContextPath()+"/shopping-result.jsp"); 142 | } catch (SQLException e) { 143 | e.printStackTrace(); 144 | } 145 | } 146 | }else if (param.equals("show")){ 147 | //如果没有登陆,跳转到登陆页面 148 | if (user==null){ 149 | response.sendRedirect(request.getContextPath()+"/login.jsp"); 150 | }else { 151 | //获取用户id 152 | long uid = user.getId(); 153 | try { 154 | List orders = orderSvs.queryOrderByUid(uid); 155 | //把订单明细和订单放入到作用域,并跳转到订单页面 156 | session.setAttribute("orderList",orders); 157 | response.sendRedirect(request.getContextPath()+"/orders_view.jsp"); 158 | } catch (SQLException e) { 159 | e.printStackTrace(); 160 | } 161 | } 162 | } 163 | } 164 | 165 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 166 | doPost(request, response); 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/web/servlet/CodeServlet.java: -------------------------------------------------------------------------------- 1 | package com.hwua.web.servlet; 2 | 3 | import javax.imageio.ImageIO; 4 | import javax.servlet.ServletException; 5 | import javax.servlet.annotation.WebServlet; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import java.awt.*; 10 | import java.awt.image.BufferedImage; 11 | import java.io.IOException; 12 | import java.util.Random; 13 | 14 | @WebServlet("/code") 15 | public class CodeServlet extends HttpServlet { 16 | public static final int WIDTH = 120; // 生成的图片的宽度 17 | public static final int HEIGHT = 35; // 生成的图片的高度 18 | 19 | protected void doGet(HttpServletRequest request, HttpServletResponse response) 20 | throws ServletException, IOException { 21 | // 在内存中创建一张图片 22 | BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB); 23 | // 得到图片 24 | Graphics g = image.getGraphics(); 25 | 26 | // 1.设置图片的背景色 27 | setBackGround(g); 28 | 29 | // 2.设置图片的边框 30 | setBorder(g); 31 | 32 | // 3.在图片上画干扰线 33 | drawRandomLine(g); 34 | 35 | // 4.在图片上写随机数 36 | String random = drawRandomNum((Graphics2D) g); 37 | System.out.println(random); 38 | request.getSession().setAttribute("checkCode", random); // 将随机数存在session中 39 | /* 40 | * 5.图形写给浏览器 41 | */ 42 | response.setContentType("image/jpeg"); 43 | // 发响应头控制浏览器不要缓存图片 44 | response.setDateHeader("expries", -1); 45 | response.setHeader("Cache-Control", "no-cache"); 46 | response.setHeader("Pragma", "no-cache"); 47 | ImageIO.write(image, "jpg", response.getOutputStream()); 48 | 49 | } 50 | 51 | /* 52 | * 设置图片的背景色 53 | */ 54 | private void setBackGround(Graphics g) { 55 | // 设置颜色 56 | g.setColor(Color.WHITE); 57 | // 填充区域 58 | g.fillRect(0, 0, WIDTH, HEIGHT); 59 | } 60 | 61 | /* 62 | * 设置图片的边框 63 | */ 64 | private void setBorder(Graphics g) { 65 | // 设置边框颜色 66 | g.setColor(Color.BLUE); 67 | // 边框区域 68 | g.drawRect(1, 1, WIDTH-2, HEIGHT-2); 69 | } 70 | 71 | /* 72 | * 在图片上画干扰线 73 | */ 74 | private void drawRandomLine(Graphics g) { 75 | // 设置颜色 76 | g.setColor(Color.GREEN); 77 | // 设置线条个数并画线 78 | for(int i=0;i<5;i++) { 79 | // 生成干扰线随机的起始坐标 80 | int x1 = new Random().nextInt(WIDTH); // 生成0~WIDTH(不包括WIDTH)的随机数 81 | int y1 = new Random().nextInt(HEIGHT); 82 | 83 | // 生成干扰线随机的结束坐标 84 | int x2 = new Random().nextInt(WIDTH); 85 | int y2 = new Random().nextInt(HEIGHT); 86 | 87 | g.drawLine(x1, y1, x2, y2); 88 | } 89 | } 90 | 91 | /* 92 | * 在图片上写随机数 93 | */ 94 | private String drawRandomNum(Graphics2D g) { 95 | // 设置颜色 96 | g.setColor(Color.RED); 97 | // 设置字体 98 | g.setFont(new Font("宋体", Font.BOLD, 20)); 99 | // 常用的中国汉字(汉字区间:[\u4e00-\u9fa5]) 100 | String base = "\u7684\u4e00\u4e86\u662f\u6211\u4e0d\u5728\u4eba\u4eec\u6709\u6765\u4ed6\u8fd9\u4e0a\u7740\u4e2a\u5730\u5230\u5927\u91cc\u8bf4\u5c31\u53bb\u5b50\u5f97\u4e5f\u548c\u90a3\u8981\u4e0b\u770b\u5929\u65f6\u8fc7\u51fa\u5c0f\u4e48\u8d77\u4f60\u90fd\u628a\u597d\u8fd8\u591a\u6ca1\u4e3a\u53c8\u53ef\u5bb6\u5b66\u53ea\u4ee5\u4e3b\u4f1a\u6837\u5e74\u60f3\u751f\u540c\u8001\u4e2d\u5341\u4ece\u81ea\u9762\u524d\u5934\u9053\u5b83\u540e\u7136\u8d70\u5f88\u50cf\u89c1\u4e24\u7528\u5979\u56fd\u52a8\u8fdb\u6210\u56de\u4ec0\u8fb9\u4f5c\u5bf9\u5f00\u800c\u5df1\u4e9b\u73b0\u5c71\u6c11\u5019\u7ecf\u53d1\u5de5\u5411\u4e8b\u547d\u7ed9\u957f\u6c34\u51e0\u4e49\u4e09\u58f0\u4e8e\u9ad8\u624b\u77e5\u7406\u773c\u5fd7\u70b9\u5fc3\u6218\u4e8c\u95ee\u4f46\u8eab\u65b9\u5b9e\u5403\u505a\u53eb\u5f53\u4f4f\u542c\u9769\u6253\u5462\u771f\u5168\u624d\u56db\u5df2\u6240\u654c\u4e4b\u6700\u5149\u4ea7\u60c5\u8def\u5206\u603b\u6761\u767d\u8bdd\u4e1c\u5e2d\u6b21\u4eb2\u5982\u88ab\u82b1\u53e3\u653e\u513f\u5e38\u6c14\u4e94\u7b2c\u4f7f\u5199\u519b\u5427\u6587\u8fd0\u518d\u679c\u600e\u5b9a\u8bb8\u5feb\u660e\u884c\u56e0\u522b\u98de\u5916\u6811\u7269\u6d3b\u90e8\u95e8\u65e0\u5f80\u8239\u671b\u65b0\u5e26\u961f\u5148\u529b\u5b8c\u5374\u7ad9\u4ee3\u5458\u673a\u66f4\u4e5d\u60a8\u6bcf\u98ce\u7ea7\u8ddf\u7b11\u554a\u5b69\u4e07\u5c11\u76f4\u610f\u591c\u6bd4\u9636\u8fde\u8f66\u91cd\u4fbf\u6597\u9a6c\u54ea\u5316\u592a\u6307\u53d8\u793e\u4f3c\u58eb\u8005\u5e72\u77f3\u6ee1\u65e5\u51b3\u767e\u539f\u62ff\u7fa4\u7a76\u5404\u516d\u672c\u601d\u89e3\u7acb\u6cb3\u6751\u516b\u96be\u65e9\u8bba\u5417\u6839\u5171\u8ba9\u76f8\u7814\u4eca\u5176\u4e66\u5750\u63a5\u5e94\u5173\u4fe1\u89c9\u6b65\u53cd\u5904\u8bb0\u5c06\u5343\u627e\u4e89\u9886\u6216\u5e08\u7ed3\u5757\u8dd1\u8c01\u8349\u8d8a\u5b57\u52a0\u811a\u7d27\u7231\u7b49\u4e60\u9635\u6015\u6708\u9752\u534a\u706b\u6cd5\u9898\u5efa\u8d76\u4f4d\u5531\u6d77\u4e03\u5973\u4efb\u4ef6\u611f\u51c6\u5f20\u56e2\u5c4b\u79bb\u8272\u8138\u7247\u79d1\u5012\u775b\u5229\u4e16\u521a\u4e14\u7531\u9001\u5207\u661f\u5bfc\u665a\u8868\u591f\u6574\u8ba4\u54cd\u96ea\u6d41\u672a\u573a\u8be5\u5e76\u5e95\u6df1\u523b\u5e73\u4f1f\u5fd9\u63d0\u786e\u8fd1\u4eae\u8f7b\u8bb2\u519c\u53e4\u9ed1\u544a\u754c\u62c9\u540d\u5440\u571f\u6e05\u9633\u7167\u529e\u53f2\u6539\u5386\u8f6c\u753b\u9020\u5634\u6b64\u6cbb\u5317\u5fc5\u670d\u96e8\u7a7f\u5185\u8bc6\u9a8c\u4f20\u4e1a\u83dc\u722c\u7761\u5174\u5f62\u91cf\u54b1\u89c2\u82e6\u4f53\u4f17\u901a\u51b2\u5408\u7834\u53cb\u5ea6\u672f\u996d\u516c\u65c1\u623f\u6781\u5357\u67aa\u8bfb\u6c99\u5c81\u7ebf\u91ce\u575a\u7a7a\u6536\u7b97\u81f3\u653f\u57ce\u52b3\u843d\u94b1\u7279\u56f4\u5f1f\u80dc\u6559\u70ed\u5c55\u5305\u6b4c\u7c7b\u6e10\u5f3a\u6570\u4e61\u547c\u6027\u97f3\u7b54\u54e5\u9645\u65e7\u795e\u5ea7\u7ae0\u5e2e\u5566\u53d7\u7cfb\u4ee4\u8df3\u975e\u4f55\u725b\u53d6\u5165\u5cb8\u6562\u6389\u5ffd\u79cd\u88c5\u9876\u6025\u6797\u505c\u606f\u53e5\u533a\u8863\u822c\u62a5\u53f6\u538b\u6162\u53d4\u80cc\u7ec6"; 101 | 102 | StringBuffer sb = new StringBuffer(); 103 | int x = 5; 104 | // 控制字数 105 | for(int i=0;i<4;i++) { 106 | 107 | int degree = new Random().nextInt()%30; //生成-30-30范围的随机数 108 | 109 | String ch = base.charAt(new Random().nextInt(base.length()))+""; 110 | sb.append(ch); 111 | // 写入字之前,设置好旋转 112 | g.rotate(degree*Math.PI/180, x, 20); // 设置字体旋转角度 113 | g.drawString(ch, x, 20); 114 | // 这次旋转不能影响下一次的旋转,所以要将上一次的旋转清掉,转回去 115 | g.rotate(-degree*Math.PI/180, x, 20); 116 | x+=30; 117 | } 118 | return sb.toString(); 119 | } 120 | 121 | protected void doPost(HttpServletRequest request, HttpServletResponse response) 122 | throws ServletException, IOException { 123 | doGet(request, response); 124 | } 125 | 126 | } -------------------------------------------------------------------------------- /src/main/java/com/hwua/web/servlet/CommentServlet.java: -------------------------------------------------------------------------------- 1 | package com.hwua.web.servlet; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | 5 | import com.hwua.dao.CommentDaoImpl; 6 | import com.hwua.dao.I.CommentDao; 7 | 8 | import com.hwua.entity.Comment; 9 | import com.hwua.entity.Paging; 10 | 11 | 12 | 13 | import javax.servlet.ServletException; 14 | import javax.servlet.annotation.WebServlet; 15 | import javax.servlet.http.HttpServlet; 16 | import javax.servlet.http.HttpServletRequest; 17 | import javax.servlet.http.HttpServletResponse; 18 | import java.io.IOException; 19 | import java.sql.SQLException; 20 | import java.text.SimpleDateFormat; 21 | import java.util.Date; 22 | import java.util.List; 23 | 24 | @WebServlet("/com.do") 25 | public class CommentServlet extends HttpServlet { 26 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 27 | CommentDao commentDao = new CommentDaoImpl(); 28 | String param = request.getParameter("param"); 29 | 30 | if (param.equals("queryCom")){//获取所有留言 31 | List comList = null; 32 | Paging page = new Paging(); 33 | /*获取每页个数*/ 34 | Integer pagesize = Integer.parseInt(request.getParameter("pagesize")); 35 | /*获取当前页*/ 36 | Integer currentPage = Integer.parseInt(request.getParameter("currentPage")); 37 | try { 38 | /*获取每页内容*/ 39 | comList = commentDao.querypageComment((currentPage - 1) * pagesize, pagesize); 40 | /* comList = commentDao*/ 41 | } catch (SQLException e) { 42 | e.printStackTrace(); 43 | } 44 | /*获取商品数量*/ 45 | Long count = null; 46 | try { 47 | count = commentDao.queryCount(); 48 | } catch (SQLException e) { 49 | e.printStackTrace(); 50 | } 51 | /*为page赋值*/ 52 | page.setTotalNumber(count); 53 | page.setCurrentPage(currentPage); 54 | page.setPageSize(pagesize); 55 | page.setCList(comList); 56 | System.out.println(page.getCList()); 57 | String str = JSON.toJSONString(page); 58 | response.getWriter().write(str); 59 | }else if (param.equals("addCom")){ 60 | String guestName = request.getParameter("guestName"); 61 | String guestTitle = request.getParameter("guestTitle"); 62 | String guestContent = request.getParameter("guestContent"); 63 | Date date = new Date(); 64 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 65 | String format = sdf.format(date);/*将创建时间字符串化*/ 66 | Comment comment = new Comment(guestTitle, guestContent, format, format, guestName, null); 67 | System.out.println(comment); 68 | try { 69 | Integer row = commentDao.addComment(comment); 70 | } catch (SQLException e) { 71 | e.printStackTrace(); 72 | } 73 | response.sendRedirect(request.getContextPath()+"/guestbook.jsp"); 74 | } 75 | 76 | } 77 | 78 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 79 | doPost(request, response); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/web/servlet/NewsServlet.java: -------------------------------------------------------------------------------- 1 | package com.hwua.web.servlet; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.hwua.entity.News; 5 | import com.hwua.service.I.NewService; 6 | import com.hwua.service.NewServiceImpl; 7 | 8 | 9 | 10 | import javax.servlet.ServletException; 11 | import javax.servlet.annotation.WebServlet; 12 | import javax.servlet.http.HttpServlet; 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.servlet.http.HttpServletResponse; 15 | import java.io.IOException; 16 | import java.io.PrintWriter; 17 | import java.sql.SQLException; 18 | import java.util.List; 19 | 20 | @WebServlet("/news") 21 | public class NewsServlet extends HttpServlet { 22 | private static NewService newSvc = new NewServiceImpl(); 23 | 24 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 25 | String param = request.getParameter("param"); 26 | PrintWriter pw = response.getWriter(); 27 | if (param.equals("queryNews")){ 28 | //通过查询获得新闻结果集 29 | List list = null; 30 | try { 31 | list = newSvc.queryNews(); 32 | } catch (SQLException e) { 33 | e.printStackTrace(); 34 | } 35 | //把结果集变成JSON传到页面 36 | String newList = JSON.toJSONString(list); 37 | pw.write(newList); 38 | }else if (param.equals("queryNewById")){//通过id查询新闻 39 | //获取id 40 | String id = request.getParameter("id"); 41 | 42 | News news = new News(); 43 | try { 44 | news = newSvc.queryNewById(Integer.parseInt(id)); 45 | } catch (SQLException e) { 46 | e.printStackTrace(); 47 | } 48 | 49 | if (news!=null) { 50 | 51 | //把结果变成JSON传到页面 52 | String newsJson = JSON.toJSONString(news); 53 | pw.write(newsJson); 54 | } 55 | } 56 | } 57 | 58 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 59 | doPost(request, response); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/web/servlet/ProCategoryServlet.java: -------------------------------------------------------------------------------- 1 | package com.hwua.web.servlet; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.hwua.entity.Product; 5 | import com.hwua.service.I.ProductCategoryService; 6 | import com.hwua.service.I.ProductService; 7 | import com.hwua.service.ProductCategoryServiceImpl; 8 | import com.hwua.service.ProductServiceImpl; 9 | 10 | import javax.servlet.ServletException; 11 | import javax.servlet.annotation.WebServlet; 12 | import javax.servlet.http.HttpServlet; 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.servlet.http.HttpServletResponse; 15 | import javax.servlet.http.HttpSession; 16 | import java.io.IOException; 17 | import java.sql.SQLException; 18 | import java.util.HashMap; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | @WebServlet("/proCategory") 23 | public class ProCategoryServlet extends HttpServlet { 24 | private static ProductCategoryService pcs; 25 | private static ObjectMapper mapper ; 26 | private static ProductService ps; 27 | 28 | 29 | @Override 30 | public void init() throws ServletException { 31 | pcs = new ProductCategoryServiceImpl(); 32 | mapper = new ObjectMapper(); 33 | ps = new ProductServiceImpl(); 34 | super.init(); 35 | } 36 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 37 | Map map = new HashMap<>(); 38 | String param = request.getParameter("param"); 39 | //查询二级类目的商品 40 | if (param.equals("querySonId")){ 41 | //父类名 42 | String parName = ""; 43 | //子类名 44 | String sonName = ""; 45 | //父子类id 46 | Long parId = 0l; 47 | Long sonId = 0l; 48 | //获取二级类目ID 49 | String str = request.getParameter("id"); 50 | long id = Long.parseLong(str); 51 | try { 52 | //获取父类id 53 | List parentId = pcs.queryParentById(); 54 | List list = null; 55 | //如果传过来的是一级分类ID就打印一级分类集合 56 | if (parentId.contains(id)){ 57 | list = ps.queryProByParentId(id); 58 | //查询分类名 59 | parName = pcs.queryProName(id); 60 | //设置父类id 61 | parId = id; 62 | }else {//否则打印二级分类 63 | //得到对应ID的结果集 64 | list = ps.queryProBySonId(id); 65 | //通过子类id查询父类的id 66 | sonId = id; 67 | parId = pcs.queryParentId(id); 68 | //查询分类名 69 | parName = pcs.queryProName(parId); 70 | sonName = pcs.queryProName(id); 71 | } 72 | map.put("sonList",list); 73 | //把父类名和子类名传入集合 74 | map.put("parentName",parName); 75 | map.put("sonName",sonName); 76 | map.put("parId",parId); 77 | map.put("sonId",sonId); 78 | } catch (SQLException e) { 79 | e.printStackTrace(); 80 | } 81 | 82 | }else if (param.equals("queryProList")){//进行模糊查询 83 | String qname = request.getParameter("qname"); 84 | System.out.println(qname); 85 | //父类名 86 | String parName = ""; 87 | //子类名 88 | String sonName = ""; 89 | //父子类id 90 | Long parId = 0L; 91 | Long sonId = 0L; 92 | try { 93 | //得到模糊查询结果集 94 | List list = ps.queryLikeByName(qname); 95 | if (list!=null) { 96 | //得到集合中第一个父子类id 97 | Product product = list.get(0); 98 | parId = product.getMajor_id(); 99 | sonId = product.getMinor_id(); 100 | //查询分类名 101 | parName = pcs.queryProName(parId); 102 | sonName = pcs.queryProName(sonId); 103 | } 104 | map.put("sonList",list); 105 | //把父类名和子类名传入集合 106 | map.put("parentName",parName); 107 | map.put("sonName",sonName); 108 | map.put("parId",parId); 109 | map.put("sonId",sonId); 110 | 111 | } catch (SQLException e) { 112 | e.printStackTrace(); 113 | } 114 | 115 | } 116 | mapper.writeValue(response.getWriter(),map); 117 | } 118 | 119 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 120 | doPost(request, response); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/main/java/com/hwua/web/servlet/ShopCarServlet.java: -------------------------------------------------------------------------------- 1 | package com.hwua.web.servlet; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.hwua.entity.Product; 5 | import com.hwua.entity.ShopCart; 6 | import com.hwua.entity.User; 7 | import com.hwua.service.I.ProductCategoryService; 8 | import com.hwua.service.I.ProductService; 9 | import com.hwua.service.I.ShopCartService; 10 | import com.hwua.service.ProductCategoryServiceImpl; 11 | import com.hwua.service.ProductServiceImpl; 12 | import com.hwua.service.ShopCartServiceImpl; 13 | 14 | import javax.servlet.ServletException; 15 | import javax.servlet.annotation.WebServlet; 16 | import javax.servlet.http.HttpServlet; 17 | import javax.servlet.http.HttpServletRequest; 18 | import javax.servlet.http.HttpServletResponse; 19 | import javax.servlet.http.HttpSession; 20 | import java.io.IOException; 21 | import java.sql.SQLException; 22 | import java.util.HashMap; 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | @WebServlet("/shopCar") 27 | public class ShopCarServlet extends HttpServlet { 28 | private static ProductCategoryService pcs; 29 | private static ObjectMapper mapper ; 30 | private static ProductService ps; 31 | private static ShopCartService cartService; 32 | 33 | 34 | @Override 35 | public void init() throws ServletException { 36 | pcs = new ProductCategoryServiceImpl(); 37 | mapper = new ObjectMapper(); 38 | ps = new ProductServiceImpl(); 39 | cartService = new ShopCartServiceImpl(); 40 | super.init(); 41 | } 42 | 43 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 44 | ShopCart shopCart = new ShopCart(); 45 | Map map = new HashMap<>(); 46 | HttpSession session = request.getSession(false); 47 | User user = (User)session.getAttribute("user"); 48 | 49 | String param = request.getParameter("param"); 50 | if (param.equals("showCar")){//添加购物项 51 | String pid = request.getParameter("id");//商品id 52 | Integer pnum = Integer.parseInt(request.getParameter("num"));//商品数量 53 | //判断用户是否登陆 54 | Long uid = 0L; 55 | //如果登陆了替换为当前用户id 56 | if (user!=null){ 57 | uid = user.getId(); 58 | } 59 | //封装成对象 60 | shopCart.setPid(Integer.parseInt(pid)); 61 | shopCart.setPnum(pnum); 62 | shopCart.setUid(uid); 63 | try { 64 | //添加商品到购物车 65 | cartService.addProduct(shopCart); 66 | //获取购物车结果集 67 | List shopCarts = cartService.showCart(uid); 68 | //设置到作用域并重定向到购物车页面 69 | session.setAttribute("shopCar",shopCarts); 70 | response.sendRedirect(request.getContextPath()+"/shopping.jsp"); 71 | } catch (SQLException e) { 72 | e.printStackTrace(); 73 | } 74 | }else if (param.equals("update")){//执行 商品数量修改 75 | Long id = Long.parseLong(request.getParameter("id")); 76 | Integer pnum =Integer.parseInt(request.getParameter("pnum"));//获取当前商品数量 77 | String type = request.getParameter("type");//判断修改类型 78 | if (type.equals("-")) {//减操作 79 | pnum -= 1; 80 | }else if (type.equals("+")){//加操作 81 | pnum += 1; 82 | } 83 | try { 84 | //通过id获取商品信息 85 | ShopCart updateCart = cartService.queryShopCart(id); 86 | Product product = ps.queryProductById(updateCart.getPid()); 87 | //修改的数量不能<=0 88 | if (pnum<=0){ 89 | map.put("updatesuccess",false); 90 | map.put("error","操作有误!商品最低数量为1"); 91 | map.put("updatePro",product); 92 | //把购物项数量改为1 93 | cartService.updateNum(1, id); 94 | }else if (pnum >product.getStock()){//修改的数量不能大于库存 95 | map.put("updatesuccess",false); 96 | map.put("error","操作有误!商品最大库存为"+product.getStock()); 97 | map.put("updatePro",product); 98 | //把购物项数量改为最大库存 99 | cartService.updateNum((int)product.getStock(), id); 100 | }else { 101 | //修改商品数量 102 | cartService.updateNum(pnum, id); 103 | //获得更改过数量的购物项 104 | updateCart = cartService.queryShopCart(id); 105 | map.put("updatesuccess",true); 106 | map.put("updateCart", updateCart); 107 | } 108 | } catch (SQLException e) { 109 | e.printStackTrace(); 110 | } 111 | }else if (param.equals("delPro")){//删除购物项 112 | System.out.println("111"); 113 | String id = request.getParameter("id"); 114 | Long uid = 0L; 115 | //如果登陆了替换为当前用户id 116 | if (user!=null){ 117 | uid = user.getId(); 118 | } 119 | try { 120 | //根据ID删除对应购物项 121 | cartService.delProduct(Long.parseLong(id)); 122 | //获取购物车结果集 123 | List shopCarts = cartService.showCart(uid); 124 | System.out.println(shopCarts); 125 | //设置到作用域并重定向到购物车页面 126 | session.setAttribute("shopCar",shopCarts); 127 | } catch (SQLException e) { 128 | e.printStackTrace(); 129 | } 130 | 131 | response.sendRedirect(request.getContextPath()+"/shopping.jsp"); 132 | }else if (param.equals("show")){ 133 | //判断用户是否登陆 134 | Long uid = 0L; 135 | //如果登陆了替换为当前用户id 136 | if (user!=null){ 137 | uid = user.getId(); 138 | } 139 | //查询购物项 140 | try { 141 | List shopCarts = cartService.showCart(uid); 142 | //设置到作用域并重定向到购物车页面 143 | session.setAttribute("shopCar",shopCarts); 144 | response.sendRedirect(request.getContextPath()+"/shopping.jsp"); 145 | } catch (SQLException e) { 146 | e.printStackTrace(); 147 | } 148 | } 149 | 150 | 151 | //把结果集转换为json发给页面 152 | mapper.writeValue(response.getWriter(),map); 153 | } 154 | 155 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 156 | doPost(request, response); 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /src/main/resources/druid.properties: -------------------------------------------------------------------------------- 1 | driverClassName=com.mysql.cj.jdbc.Driver 2 | url=jdbc:mysql://127.0.0.1:3306/graduation_283_amz?useSSL=false&serverTimezone=Asia/Shanghai 3 | username=root 4 | password=123456 5 | initialSize=5 6 | maxActive=10 7 | maxWait=3000 8 | maxIdle=8 9 | minIdle=3 -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | Archetype Created Web Application 7 | 8 | -------------------------------------------------------------------------------- /src/main/webapp/back.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="utf-8" isELIgnored="false" %> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 3 | <% 4 | String path = request.getContextPath(); 5 | String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 6 | %> 7 | 8 | 9 | 10 | 11 | 12 | My JSP 'back.jsp' starting page 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | 26 |

 密码已找回,请记录:

27 |

返回登录页面

28 | 29 | 30 | -------------------------------------------------------------------------------- /src/main/webapp/chat-room.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false"%> 2 | <% 3 | String path = request.getContextPath(); 4 | String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 5 | %> 6 | 7 | 8 | 9 | 10 | XXX - 聊天室 11 | 12 | 18 | 19 | 20 |
21 |
22 |

在线用户列表

23 | 26 |
27 |
28 |
29 |

aaa

30 |

aaa

31 |
32 |
33 |
接收人:所有
34 |
35 | 36 |
37 |
38 |
39 | 40 | 41 | -------------------------------------------------------------------------------- /src/main/webapp/code.jsp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaGraduationProject/DepartmentStoreManagementSystem/058324e22ac42e42ad35ce4589601a2b766e4503/src/main/webapp/code.jsp -------------------------------------------------------------------------------- /src/main/webapp/css/adv.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaGraduationProject/DepartmentStoreManagementSystem/058324e22ac42e42ad35ce4589601a2b766e4503/src/main/webapp/css/adv.css -------------------------------------------------------------------------------- /src/main/webapp/css/guestbook.css: -------------------------------------------------------------------------------- 1 | #reply-box form table td span { display:none; vertical-align:middle; margin-left:10px; padding-left:22px; padding-right:10px; } 2 | #reply-box form table td span.error { display:inline-block; font-size: 10px; border:1px solid blue; background: #c5d0ff url(../images/bg.png) -232px -65px no-repeat;} 3 | #reply-box form table td span.ok { display:inline-block; font-size: 10px; border:1px solid green;} -------------------------------------------------------------------------------- /src/main/webapp/css/index.css: -------------------------------------------------------------------------------- 1 | * { 2 | margin: 0; 3 | padding: 0; 4 | list-style: none; 5 | } 6 | 7 | body { 8 | font: 12px / 22px Verdana, Geneva, sans-serif; 9 | background: #FFFFFF; 10 | color: #333; 11 | } 12 | 13 | /*top��ʼ*/ 14 | .login_menu { 15 | height: 30px; 16 | width: 100%; 17 | background: rgba(0, 0, 0, 0.07); 18 | } 19 | 20 | #error{ 21 | padding: 10px auto; 22 | font-size: 20px; 23 | color: red; 24 | } 25 | 26 | .login_container { 27 | width: 960px; 28 | margin: 0 auto; 29 | height: 30px; 30 | } 31 | 32 | .m_left { 33 | float: left; 34 | margin-left: 30px; 35 | position: relative; 36 | top: 5px; 37 | } 38 | 39 | .m_left li { 40 | float: left; 41 | } 42 | 43 | .login_container a { 44 | text-decoration: none; 45 | color: #666666; 46 | } 47 | 48 | .login_container a:hover { 49 | color: black; 50 | } 51 | 52 | .m_right { 53 | float: right; 54 | position: relative; 55 | top: 5px; 56 | } 57 | 58 | .m_right li { 59 | float: left; 60 | margin-left: 15px; 61 | } 62 | 63 | .m_right img { 64 | vertical-align: middle; 65 | margin-right: 5px; 66 | } 67 | 68 | .login_container .c_red { 69 | color: red; 70 | } 71 | 72 | .logo_search { 73 | width: 960px; 74 | margin: 0 auto; 75 | height: 110px; 76 | } 77 | 78 | .logo { 79 | float: left; 80 | margin-top: 30px; 81 | } 82 | 83 | .search { 84 | float: right; 85 | position: relative; 86 | top: 40px; 87 | left: -100px; 88 | } 89 | 90 | #qname { 91 | border: #f00 3px solid; 92 | width: 440px; 93 | height: 30px; 94 | float: left; 95 | padding: 0 10px; 96 | } 97 | 98 | .query_button { 99 | width: 140px; 100 | height: 36px; 101 | background: #ff0000; 102 | border: 0; 103 | color: white; 104 | font-size: 20px; 105 | font-weight: bold; 106 | } 107 | 108 | .nav_bar { 109 | background: #ff4c11; 110 | height: 30px; 111 | } 112 | 113 | .nav_bar_container { 114 | width: 960px; 115 | margin: 0 auto; 116 | } 117 | 118 | .nav_bar_container ul li { 119 | float: left; 120 | color: #cccccc; 121 | margin-right: 5px; 122 | height: 28px; 123 | line-height: 28px; 124 | } 125 | 126 | .nav_bar_container ul li > a { 127 | text-decoration: none; 128 | color: white; 129 | font-size: 12px; 130 | font-weight: bold; 131 | } 132 | 133 | /*top����*/ 134 | 135 | /*middleģ�鿪ʼ*/ 136 | 137 | #middle { 138 | width: 960px; 139 | margin: 5px auto; 140 | overflow:hidden; 141 | 142 | } 143 | 144 | .p_left { 145 | float: left; 146 | width: 181px; 147 | } 148 | 149 | .p_category { 150 | border: 1px solid #c3c3c3; 151 | } 152 | 153 | .p_category h2 { 154 | background: #cc0000; 155 | font-size: 14px; 156 | color: white; 157 | padding: 2px 8px; 158 | } 159 | 160 | .p_category dt { 161 | color: #404040; 162 | font-weight: bold; 163 | background: #fafafa; 164 | padding: 2px 10px; 165 | } 166 | 167 | .p_category dt > a { 168 | text-decoration: none; 169 | font-size: 12px; 170 | } 171 | 172 | .p_category dd { 173 | margin-left: 10px; 174 | background: url(../images/bg.png) -232px -82px no-repeat; 175 | padding-left: 25px; 176 | } 177 | 178 | .p_category dd > a { 179 | color: #666; 180 | text-decoration: none; 181 | } 182 | 183 | .p_category dd > a:hover { 184 | text-decoration: underline; 185 | } 186 | 187 | /*-----------------------------*/ 188 | .p_center { 189 | float: left; 190 | margin: 0px 10px; 191 | } 192 | 193 | .pre_look { 194 | border: 1px solid #c3c3c3; 195 | margin-top: 10px; 196 | overflow:hidden; 197 | } 198 | 199 | .pre_look h3 { 200 | background: #cc0000; 201 | color: white; 202 | padding-left: 10px; 203 | height: 30px; 204 | line-height: 30px; 205 | 206 | } 207 | 208 | .pre_look dl { 209 | margin: 5px; 210 | } 211 | 212 | .pre_look dl dt { 213 | float: left; 214 | width: 60px; 215 | height: 60px; 216 | text-align: center; 217 | } 218 | 219 | .pre_look dl dt img { 220 | border: 1px solid #ccc; 221 | } 222 | 223 | .pre_look dl dd { 224 | height: 60px; 225 | margin-left: 66px; 226 | } 227 | 228 | .pre_look dl dd a { 229 | color: #666; 230 | text-decoration: none 231 | } 232 | 233 | .p_list { 234 | width: 300px; 235 | border-bottom: 2px solid #cccccc; 236 | margin: 0px auto; 237 | position: relative; 238 | top: 20px; 239 | 240 | } 241 | 242 | .p_info { 243 | display: inline-block; 244 | position: absolute; 245 | font-size: 16px; 246 | color: black; 247 | font-weight: bold; 248 | background: #ffffff; 249 | top: -10px; 250 | left: 100px; 251 | } 252 | 253 | .p_info img { 254 | vertical-align: middle; 255 | margin-right: 10px; 256 | } 257 | 258 | ul.product2 { 259 | margin-top: 30px; 260 | width: 522px; 261 | /*border: 1px solid red;*/ 262 | } 263 | 264 | ul.product2 li { 265 | width: 110px; 266 | line-height: 15px; 267 | height: 150px; 268 | float: left; 269 | margin: 5px 9px; 270 | border: 1px dotted #cccccc; 271 | background: lavenderblush; 272 | 273 | } 274 | 275 | ul.product2 li dl dt { 276 | text-align: center; 277 | } 278 | 279 | ul.product2 li dl dt img { 280 | width: 100px; 281 | height: 100px; 282 | 283 | } 284 | 285 | ul.product2 li dl dd.title { 286 | height: 30px; 287 | overflow: hidden; 288 | text-align:center; 289 | 290 | } 291 | 292 | ul.product2 li dl dd.title a { 293 | color: #666; 294 | padding-left: 10px; 295 | text-decoration:none; 296 | 297 | } 298 | 299 | ul.product2 li dl dd.price { 300 | color: #c30; 301 | font-weight: bold; 302 | text-align:center; 303 | } 304 | 305 | .pager { 306 | margin-top: 15px; 307 | clear: both; 308 | 309 | } 310 | 311 | .pager a { 312 | text-decoration: none; 313 | color: darkblue; 314 | } 315 | 316 | .pager ul { 317 | float: right; 318 | } 319 | 320 | .pager ul li { 321 | float: left; 322 | border: 1px solid #eee; 323 | line-height: 18px; 324 | padding: 0 3px; 325 | margin: 0 1px; 326 | display: inline; 327 | } 328 | 329 | .pager ul li.current { 330 | font-weight: bold; 331 | color: #630; 332 | } 333 | 334 | /*middleģ�����*/ 335 | 336 | /*rightģ�鿪ʼ*/ 337 | #p_right { 338 | margin-left: 2px; 339 | width: 230px; 340 | float: left; 341 | } 342 | 343 | .newsList { 344 | border: 1px solid #cccccc; 345 | } 346 | 347 | .newsList h2 { 348 | height: 30px; 349 | background: white; 350 | line-height: 30px; 351 | border-bottom: 1px solid #cccccc; 352 | padding-left: 25px; 353 | background: url("../images/icon_news.png") no-repeat 2px 8px; 354 | } 355 | 356 | .newsList li { 357 | background: url("../images/icon_sj.png") no-repeat 5px 10px; 358 | height: 25px; 359 | line-height: 25px; 360 | padding-left: 15px; 361 | } 362 | 363 | .newsList li > a { 364 | color: rgba(14, 14, 14, 0.58); 365 | text-decoration: none; 366 | } 367 | 368 | .newsList li > a:hover { 369 | text-decoration: underline; 370 | } 371 | 372 | .hot_sale { 373 | margin-top: 10px; 374 | border: 1px solid #cccccc; 375 | } 376 | 377 | .hot_sale h2 { 378 | background: url("../images/icon_Recommend.png") no-repeat 2px 6px; 379 | padding-left: 28px; 380 | height: 30px; 381 | line-height: 30px; 382 | border-bottom: 1px solid #cccccc; 383 | } 384 | 385 | .hot_sale li { 386 | 387 | height: 80px; 388 | padding: 7px; 389 | 390 | } 391 | 392 | .hot_sale li dt img { 393 | width: 80px; 394 | height: 80px; 395 | border: 1px solid #cccccc; 396 | float: left; 397 | margin-right: 15px; 398 | 399 | } 400 | 401 | .hot_sale li .p_name { 402 | height: 40px; 403 | padding-top: 10px; 404 | } 405 | 406 | .hot_sale li .p_name a { 407 | text-decoration: none; 408 | color: #4c4d4b; 409 | } 410 | 411 | .hot_sale li .p_name a:hover { 412 | text-decoration: underline; 413 | color: #4c4d4b; 414 | } 415 | 416 | .hot_sale li .price{ 417 | font-size: 14px; 418 | font-weight: bold; 419 | color: red; 420 | } 421 | 422 | /*rightģ�����*/ 423 | 424 | /*�ײ�ģ�鿪ʼ*/ 425 | #foot{ 426 | width: 100%; 427 | margin: 0 auto; 428 | clear: both; 429 | font-size: 14px; 430 | text-align: center; 431 | background: rgba(0, 0, 0, 0.07); 432 | } 433 | 434 | /*�ײ�ģ�����*/ 435 | 436 | -------------------------------------------------------------------------------- /src/main/webapp/css/querydiv.css: -------------------------------------------------------------------------------- 1 | /*$(function(){ 2 | $(".bodys p").not(":first").hide(); 3 | $(".searchbox ul li").mouseover(function(){ 4 | var index = $(this).index(); 5 | if(index==0){ 6 | $(this).find("a").addClass("style1"); 7 | $("li").eq(1).find("a").removeClass("style2"); 8 | $("li").eq(2).find("a").removeClass("style3"); 9 | } 10 | if(index==1){ 11 | $(this).find("a").addClass("style2"); 12 | $("li").eq(0).find("a").removeClass("style1"); 13 | $("li").eq(2).find("a").removeClass("style3"); 14 | } 15 | if(index==2){ 16 | $(this).find("a").addClass("style3"); 17 | $("li").eq(0).find("a").removeClass("style1"); 18 | $("li").eq(1).find("a").removeClass("style2"); 19 | } 20 | var index=$(this).index(); 21 | $(".bodys p").eq(index).show().siblings().hide(); 22 | }); 23 | }); 24 | 25 | 8 | 9 | 11 | 24 |
25 |

新闻动态

26 | 29 |
30 | -------------------------------------------------------------------------------- /src/main/webapp/index_pre_look.jsp: -------------------------------------------------------------------------------- 1 | 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false"%> 4 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 5 | 6 | 34 | 35 |
36 | <%--

最近浏览

37 |
38 |
39 | 40 |
41 |
42 | 43 |
44 |
--%> 45 |
-------------------------------------------------------------------------------- /src/main/webapp/index_product_sort.jsp: -------------------------------------------------------------------------------- 1 | 33 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false"%> 34 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 35 | 36 | 37 |
38 |

商品分类

39 |
40 | <%--
41 | 42 |
43 |
44 | 45 |
--%> 46 |
47 |
48 | 49 | -------------------------------------------------------------------------------- /src/main/webapp/index_top.jsp: -------------------------------------------------------------------------------- 1 | 2 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false"%> 3 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 4 | <%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 5 | <% 6 | double num = Math.random(); 7 | %> 8 | 19 | 65 | -------------------------------------------------------------------------------- /src/main/webapp/login.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false" %> 2 | <% 3 | String path = request.getContextPath(); 4 | String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 5 | %> 6 | 7 | 8 | 9 | 10 | XXX - 登录 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 81 | 82 | 83 | <%@ include file="index_top.jsp" %> 84 |
85 |
86 | 87 | 88 |
89 |

欢迎回到XXX

90 |
91 | 92 |
93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 107 | 108 | 109 | 110 | 111 | 112 |
用户名:
登录密码:忘记密码
验证码: 105 | <%--换一张--%> 106 |
113 |
114 |
115 |
116 |
117 |
118 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /src/main/webapp/method.jsp: -------------------------------------------------------------------------------- 1 | 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | -------------------------------------------------------------------------------- /src/main/webapp/news_view.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false" %> 2 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 | <% 4 | String path = request.getContextPath(); 5 | String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 6 | %> 7 | 8 | 9 | 10 | 11 | XXX - 新闻显示 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | <%@ include file="method.jsp" %> 21 | 41 | 42 | 43 | <%@ include file="index_top.jsp" %> 44 |
45 | 您现在的位置:XXX > 阅读新闻 46 |
47 |
48 |
49 | <%@ include file="index_news.jsp" %> 50 |
51 |
52 | <%--

标题:

53 |
54 |

创建时间:

55 | 内容: 56 |
--%> 57 |
58 |
59 |
60 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /src/main/webapp/orders_view.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false" %> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 3 | 4 | 5 | 6 | 7 | XXX - 订单页 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 23 | 28 | 29 | 30 | 31 | <%@ include file="index_top.jsp"%> 32 | 33 |
34 | 您现在的位置:XXX > 最新订单 35 |
36 |
37 |
38 |
39 | 40 | 41 | 42 | 43 | 44 | 45 | 48 | 49 | 50 | 51 | 53 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
订单时间:${order.create_time}订单号:${order.id}订单总额:${order.money} 46 | 47 |
${odList.product.name}单价:${odList.money} 54 | ${odList.quantity}正在发货
62 |
63 |
64 |
65 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /src/main/webapp/product-list.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false"%> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 3 | <%--<% 4 | String path = request.getContextPath(); 5 | String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() 6 | + path + "/"; 7 | %>--%> 8 | 9 | 10 | 11 | 12 | XXX - 产品列表 13 | 14 | 15 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | <%@ include file="method.jsp" %> 29 | 73 | 74 | 75 | <%@ include file="index_top.jsp"%> 76 |
77 | 您现在的位置:<%--XXX > > –%>--%> 78 |
79 |
80 |
81 | <%--导入商品分类--%> 82 | <%@ include file="index_product_sort.jsp"%> 83 |
84 |
85 | <%--导入最近浏览--%> 86 | <%@include file="index_pre_look.jsp"%> 87 | 88 |
89 |
90 |
91 |
92 |

全部商品

93 |
94 |
    95 | 96 | <%--
  • 97 |
    98 |
    99 | 100 |
    101 |
    102 | 商品名称 103 |
    104 |
    ¥12.34
    105 |
    106 |
  • 107 | 108 |
  • 109 |
    110 |
    111 | 112 |
    113 |
    114 | 商品名称 115 |
    116 |
    ¥12.34
    117 |
    118 |
  • --%> 119 | 120 | 121 |
122 |
123 |
124 | <%--
125 | 首页    126 | 上一页   127 | 下一页   128 | /   129 | 最后一页 130 |
--%> 131 | <%----%> 141 |
142 |
143 |
144 |
145 |
146 | 148 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /src/main/webapp/queryproduct-list.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false"%> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 3 | <%--<% 4 | String path = request.getContextPath(); 5 | String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() 6 | + path + "/"; 7 | %>--%> 8 | 9 | 10 | 11 | 12 | XXX - 产品列表 13 | 14 | 15 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | <%@ include file="method.jsp" %> 29 | 72 | 73 | 74 | <%@ include file="index_top.jsp"%> 75 |
76 | 您现在的位置:<%--XXX > > –%>--%> 77 |
78 |
79 |
80 | <%--导入商品分类--%> 81 | <%@ include file="index_product_sort.jsp"%> 82 |
83 |
84 | <%--导入最近浏览--%> 85 | <%@include file="index_pre_look.jsp"%> 86 | 87 |
88 |
89 |
90 |
91 |

全部商品

92 |
93 |
    94 | 95 | <%--
  • 96 |
    97 |
    98 | 99 |
    100 |
    101 | 商品名称 102 |
    103 |
    ¥12.34
    104 |
    105 |
  • 106 | 107 |
  • 108 |
    109 |
    110 | 111 |
    112 |
    113 | 商品名称 114 |
    115 |
    ¥12.34
    116 |
    117 |
  • --%> 118 | 119 | 120 |
121 |
122 |
123 | <%--
124 | 首页    125 | 上一页   126 | 下一页   127 | /   128 | 最后一页 129 |
--%> 130 | <%----%> 140 |
141 |
142 |
143 |
144 |
145 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /src/main/webapp/reg-result.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false" %> 2 | <% 3 | String path = request.getContextPath(); 4 | String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; 5 | %> 6 | 7 | 8 | 9 | 10 | XXX - 注册结果 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | <%@ include file="index_top.jsp" %> 21 |
22 |
23 | 24 | 25 |
26 |

欢迎注册XXX

27 |
    28 |
  • 填写注册信息
  • 29 |
  • 注册成功
  • 30 |
31 |
32 |

恭喜:注册成功!

33 |

正在进入登陆页面...

34 | 37 |
38 |
39 |
40 |
41 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/main/webapp/retrieve_password.jsp: -------------------------------------------------------------------------------- 1 | 2 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false"%> 3 | <% 4 | String path = request.getContextPath(); 5 | String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 6 | %> 7 | 8 | 9 | 10 | 11 | 亚马逊 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 54 | 55 | 56 | <%@ include file="index_top.jsp" %> 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 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /src/main/webapp/scripts/adv.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaGraduationProject/DepartmentStoreManagementSystem/058324e22ac42e42ad35ce4589601a2b766e4503/src/main/webapp/scripts/adv.js -------------------------------------------------------------------------------- /src/main/webapp/scripts/comment.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | 5 | 6 | function commentCheck(){ 7 | 8 | if($("[name=guestName]").val()==""){ 9 | alert("请输入昵称!") 10 | return false; 11 | } 12 | 13 | if($("[name=guestTitle]").val()==""){ 14 | alert("请输入标题!") 15 | return false; 16 | } 17 | 18 | if($("[name=guestContent]").val()==""){ 19 | alert("请输入留言内容!") 20 | return false; 21 | } 22 | 23 | return true; 24 | } 25 | -------------------------------------------------------------------------------- /src/main/webapp/scripts/function-manage.js: -------------------------------------------------------------------------------- 1 | // JavaScript Document 2 | function Delete(id) 3 | { 4 | if(confirm("确定要删除吗?")) { 5 | open("ProductClassServlet?action=remove&hpcId=" + id,"_self"); 6 | } 7 | } 8 | 9 | -------------------------------------------------------------------------------- /src/main/webapp/scripts/index.js: -------------------------------------------------------------------------------- 1 | 2 | //上一页方法 3 | function lastPage() { 4 | 5 | var totalPage = $("#totalPage").val() 6 | var source = $("#source").val() 7 | var hpcId = $("#hpcId").val() 8 | var pageNo = parseInt($("#currentPage").val()) 9 | var name = $("#queryName").val() 10 | 11 | if (name == null) { 12 | name = 0; 13 | } 14 | 15 | if (pageNo == 1) { 16 | alert("已经是第一页了!") 17 | } else { 18 | pageNo = pageNo - 1 19 | window.location.href = "ref?src=" + source + "&page=" + pageNo 20 | + "&hpcId=" + hpcId + "&qname=" + name 21 | } 22 | } 23 | 24 | // 下一页方法 25 | function nextPage() { 26 | 27 | var totalPage = $("#totalPage").val() 28 | var source = $("#source").val() 29 | var hpcId = $("#hpcId").val() 30 | var pageNo = parseInt($("#currentPage").val()) 31 | var name = $("#queryName").val() 32 | 33 | if (name == null) { 34 | name = 0; 35 | } 36 | 37 | if (pageNo == parseInt(totalPage)) { 38 | alert("已经是最后一页了!") 39 | } else { 40 | pageNo = pageNo + 1 41 | window.location.href = "ref?src=" + source + "&page=" + pageNo 42 | + "&hpcId=" + hpcId + "&qname=" + name 43 | } 44 | 45 | } 46 | 47 | function queryProducts() { 48 | var qname = $("#qname").val() 49 | if (qname == null) { 50 | alert("请输入想要搜索的商品名!") 51 | } else { 52 | window.location.href = "query?qname=" + qname 53 | 54 | } 55 | 56 | } 57 | 58 | -------------------------------------------------------------------------------- /src/main/webapp/scripts/product_view.js: -------------------------------------------------------------------------------- 1 | function addToCart(pid) { 2 | 3 | var stock=$("#stock").html() 4 | var count=$("#count").val() 5 | 6 | if(parseInt(count)>parseInt(stock)){ 7 | alert("您选择的数量超过库存!") 8 | }else{ 9 | $.ajax({ 10 | url : "addToCart",// 请求的servlet地址 11 | type : "GET",// 请求方式 12 | data : "" + pid+"_"+count,// 发送到服务器的数据 13 | dataType : "text",// 设置返回数据类型 14 | success : function(total) { 15 | $("#cartCount").html(total); 16 | alert("成功添加到购物车!") 17 | },// 响应成功后执行的回调方法data响应文本 18 | complete : function(XMLHttpRequest, statusText) { 19 | 20 | },// 响应完成后执行的回调方法 21 | error : function(XMLHttpRequest, statusText) { 22 | alert("添加到购物车失败!") 23 | }// 响应失败后执行的回调方法 24 | }) 25 | } 26 | 27 | } 28 | 29 | function goingToBuy(pid) { 30 | window.location.href="goingToBuy?"+pid+"_"+$("#count").val(); 31 | 32 | } 33 | 34 | //-按钮事件 35 | function minus(){ 36 | 37 | if($("#count").val()==1){ 38 | $("#count").val(1) 39 | }else if($("#count").val()>=2){ 40 | var old=$("#count").val() 41 | $("#count").val(parseInt(old)-1) 42 | } 43 | } 44 | 45 | //+按钮事件 46 | function add(){ 47 | var stock=$("#stock").html() 48 | var old=$("#count").val() 49 | if(parseInt(old)parseInt(stock)){ 63 | alert("您选择的数量超过库存!") 64 | } 65 | } 66 | 67 | 68 | 69 | function remaind() { 70 | alert("请先登录亚马逊!") 71 | window.location.href="login.jsp" 72 | } 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /src/main/webapp/scripts/register.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | function emailtest() { 4 | alert("测试") 5 | } 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/main/webapp/scripts/shopping.js: -------------------------------------------------------------------------------- 1 | 2 | function deleteCart(cid) { 3 | 4 | $.ajax({ 5 | url : "deleteCart",// 请求的servlet地址 6 | type : "GET",// 请求方式 7 | data : "" + cid,// 发送到服务器的数据 8 | dataType : "text",// 设置返回数据类型 9 | success : function() { 10 | 11 | },// 响应成功后执行的回调方法data响应文本 12 | complete : function(XMLHttpRequest, statusText) { 13 | 14 | },// 响应完成后执行的回调方法 15 | error : function(XMLHttpRequest, statusText) { 16 | alert("操作失败!") 17 | }// 响应失败后执行的回调方法 18 | }) 19 | } 20 | 21 | 22 | 23 | function alterCount(cid) { 24 | 25 | 26 | // window.location.href="alterQuantity?"+cid+"_"+$("#"+cid).val() 27 | $.ajax({ 28 | url : "alterQuantity",// 请求的servlet地址 29 | type : "GET",// 请求方式 30 | data : ""+cid+"_"+$("#"+cid).val(),// 发送到服务器的数据 31 | dataType : "text",// 设置返回数据类型 32 | success : function(total) { 33 | $("#cartCount").html(total); 34 | },// 响应成功后执行的回调方法data响应文本 35 | complete : function(XMLHttpRequest, statusText) { 36 | 37 | },// 响应完成后执行的回调方法 38 | error : function(XMLHttpRequest, statusText) { 39 | alert("操作失败!") 40 | }// 响应失败后执行的回调方法 41 | }) 42 | } 43 | 44 | 45 | //-按钮事件 46 | function reduce(id){ 47 | 48 | if($("#"+id).val()==1){ 49 | $("#"+id).val(1) 50 | }else if($("#"+id).val()>=2){ 51 | var old=$("#"+id).val() 52 | $("#"+id).val(parseInt(old)-1) 53 | } 54 | alterCount(id) 55 | } 56 | 57 | //+按钮事件 58 | function increase(id){ 59 | 60 | var stock=$("#hpStock"+id).val()//获得库存 61 | var old=$("#"+id).val()//获得原来的数量 62 | if(parseInt(old)parseInt(stock)){ 77 | alert("您选择的数量超过库存!") 78 | }else{ 79 | alterCount(id) 80 | } 81 | } 82 | 83 | 84 | 85 | 86 | function buttonTest(id) { 87 | alert("测试id="+id) 88 | } 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /src/main/webapp/shopping-result.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false"%> 2 | <% 3 | String path = request.getContextPath(); 4 | String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 5 | %> 6 | 7 | 8 | 9 | 10 | 亚马逊 - 购物车 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | <%@ include file="index_top.jsp" %> 21 |
22 | 您现在的位置:亚马逊 > 购物车 23 |
24 |
25 |
26 |
27 | 28 | 29 |
30 |
31 |

恭喜:购买成功!

32 |

正在查看最新订单...

33 | 36 |
37 |
38 |
39 |
40 |
41 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/test/java/com/hwua/test/NewsTest.java: -------------------------------------------------------------------------------- 1 | package com.hwua.test; 2 | 3 | import java.util.List; 4 | 5 | import org.junit.Test; 6 | 7 | import com.hwua.entity.News; 8 | import com.hwua.service.NewServiceImpl; 9 | import com.hwua.service.I.NewService; 10 | 11 | public class NewsTest { 12 | @Test 13 | public void testQueryNews() throws Exception{ 14 | NewService newsService = new NewServiceImpl(); 15 | List newsList = newsService.queryNews(); 16 | for(News news : newsList) { 17 | System.out.println(news); 18 | } 19 | 20 | } 21 | } 22 | --------------------------------------------------------------------------------