事情來得太忽然,一個朋友說是要我幫忙作一個JavaWeb的課程設計,在過一天就要去答辯了…
這我哪受的了時間這麼短尚未~~~,正準備委婉的拒絕的時候他說寫完以後給我那個啥…
好吧,我就是這麼庸俗php
那好吧,泡杯雀巢(特濃)開工。java
這是我快作完的時候他給他瞧瞧的項目結構,居然看不懂,那就只能改了。
git
這是把一些接口繼承幹掉以後的目錄結構。github
上面就是最後的目錄結構,應該很容易理解吧。web
這裏描述的是這個項目的關鍵地方,懂了這裏,整個項目就不在話下。sql
最主要的就是那三個servlet,也就是controller類.數據庫
這裏是 UserServlet.java。tomcat
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { this.doPost(req, resp); } protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String action = req.getParameter("action"); switch (action) { case "adLogin": { // 判斷管理員密碼是否正確 login(req, resp, 1); } break; case "login": { // 判斷用戶密碼是否正確 login(req, resp, 0); } break; case "loginOut": { // 退出登陸 loginOut(req, resp, 0); } break; case "showAllUsers": { // 顯示全部用戶 showAllUsers(req, resp); } break; case "delUser": { // 刪除用戶 delUser(req, resp); } break; case "updateUser": { // 更新 updateUser(req, resp); } break; case "insertUser": { // 插入用戶 insertUser(req, resp); } } }
幾乎全部有關用戶的請求都通過這裏,根據傳過來的action指令不一樣,調用不一樣的方法來而後相應的結果或者是頁面。服務器
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doPost(req, resp); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String action = req.getParameter("action"); if (action.equals("showAllIndents")){showAllIndents(req, resp);} else if (action.equals("showAllUserIndents")){showAllUserIndents(req, resp);} else if (action.equals("delIndent")){delIndent(req, resp);} else if (action.equals("payout")){payout(req, resp);} switch (action) { // 顯示全部訂單 case "showAllIndents": { showAllIndents(req, resp); } break; // 顯示全部用戶訂單 case "showAllUserIndents": { showAllUserIndents(req, resp); } break; // 刪除訂單 case "delIndent": { delIndent(req, resp); } break; // 支付,等價於生成訂單 case "payout": { payout(req, resp); } break; } }
在處理訂單和商品的的請求時也是用了一樣的道理。接下類的代碼就不BB了,能夠在GitHub
上取,裏面寫了我自認爲蠻多的代碼。jsp
朋友說要作最簡單的,那我就作最簡單的哦。
這是首頁
這裏是商品中心也就是用戶中心
簡單嗎
-- phpMyAdmin SQL Dump -- version 4.4.15.10 -- https://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: 2019-06-19 15:15:18 -- 服務器版本: 5.7.19-log -- PHP Version: 5.4.45 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Database: `jsp_shop` -- -- -------------------------------------------------------- -- -- 表的結構 `ad_users` -- CREATE TABLE IF NOT EXISTS `ad_users` ( `id` int(11) NOT NULL, `username` varchar(50) NOT NULL, `password` varchar(50) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- 轉存表中的數據 `ad_users` -- INSERT INTO `ad_users` (`id`, `username`, `password`) VALUES (1, 'admin', 'admin'); -- -------------------------------------------------------- -- -- 表的結構 `goods` -- CREATE TABLE IF NOT EXISTS `goods` ( `id` int(11) NOT NULL, `goodsClassId` int(11) NOT NULL, `goodname` varchar(20) NOT NULL, `price` float NOT NULL, `amount` int(11) NOT NULL, `leave_amount` int(11) NOT NULL, `img` varchar(200) DEFAULT NULL ) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8; -- -- 轉存表中的數據 `goods` -- INSERT INTO `goods` (`id`, `goodsClassId`, `goodname`, `price`, `amount`, `leave_amount`, `img`) VALUES (4, 1, 'zzz', 43, 0, 54, 'https://img12.360buyimg.com/n7/jfs/t1/63005/7/2162/346204/5d073a88E037d277f/ad359511de220251.jpg'), (6, 1, '阿迪達斯', 499, 100, 13, 'https://img10.360buyimg.com/n7/jfs/t1/19909/3/6832/54742/5c62746fE4ca54219/dd9fd5234e80ca56.jpg'), (8, 2, '男士levis外套', 300, 100, 16, 'https://img13.360buyimg.com/n8/jfs/t1/82625/13/358/355493/5ce8ada3E190147ae/28d18a09922d5084.jpg'), (13, 5, '男士休閒包', 299, 100, 18, 'https://img13.360buyimg.com/n7/jfs/t1/62078/7/1965/323619/5d04b1c2E0270ed58/3bdfde61f9b6abe4.jpg'); -- -------------------------------------------------------- -- -- 表的結構 `goodsclass` -- CREATE TABLE IF NOT EXISTS `goodsclass` ( `id` int(11) NOT NULL, `classname` varchar(30) NOT NULL ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8; -- -- 轉存表中的數據 `goodsclass` -- INSERT INTO `goodsclass` (`id`, `classname`) VALUES (1, '男鞋'), (2, '男士外套'), (5, '男士挎包'); -- -------------------------------------------------------- -- -- 表的結構 `indent` -- CREATE TABLE IF NOT EXISTS `indent` ( `id` int(11) NOT NULL, `indentNo` varchar(20) NOT NULL, `userId` int(11) NOT NULL, `totalPrice` float DEFAULT NULL ) ENGINE=InnoDB AUTO_INCREMENT=76 DEFAULT CHARSET=utf8; -- -- 轉存表中的數據 `indent` -- INSERT INTO `indent` (`id`, `indentNo`, `userId`, `totalPrice`) VALUES (72, 'HYD-34-71', 34, NULL), (73, 'HYD-34-72', 34, 123), (74, 'HYD-34-73', 34, 123), (75, 'HYD-34-74', 34, 123); -- -------------------------------------------------------- -- -- 表的結構 `indentlist` -- CREATE TABLE IF NOT EXISTS `indentlist` ( `id` int(11) NOT NULL, `indentId` int(11) NOT NULL, `goodId` int(11) NOT NULL, `amount` int(11) NOT NULL ) ENGINE=InnoDB AUTO_INCREMENT=74 DEFAULT CHARSET=utf8; -- -- 轉存表中的數據 `indentlist` -- INSERT INTO `indentlist` (`id`, `indentId`, `goodId`, `amount`) VALUES (70, 72, 4, 1), (71, 73, 6, 3), (72, 74, 4, 1), (73, 75, 4, 1); -- -------------------------------------------------------- -- -- 表的結構 `users` -- CREATE TABLE IF NOT EXISTS `users` ( `id` int(11) NOT NULL, `username` varchar(20) NOT NULL, `password` varchar(20) NOT NULL ) ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=utf8; -- -- 轉存表中的數據 `users` -- INSERT INTO `users` (`id`, `username`, `password`) VALUES (34, '123', '123'), (36, '321', '321'), (38, '543543', '54353475'), (39, '9789', '9879'); -- -- Indexes for dumped tables -- -- -- Indexes for table `goods` -- ALTER TABLE `goods` ADD PRIMARY KEY (`id`); -- -- Indexes for table `goodsclass` -- ALTER TABLE `goodsclass` ADD PRIMARY KEY (`id`); -- -- Indexes for table `indent` -- ALTER TABLE `indent` ADD PRIMARY KEY (`id`); -- -- Indexes for table `indentlist` -- ALTER TABLE `indentlist` ADD PRIMARY KEY (`id`); -- -- Indexes for table `users` -- ALTER TABLE `users` ADD PRIMARY KEY (`id`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `goods` -- ALTER TABLE `goods` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=21; -- -- AUTO_INCREMENT for table `goodsclass` -- ALTER TABLE `goodsclass` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=6; -- -- AUTO_INCREMENT for table `indent` -- ALTER TABLE `indent` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=76; -- -- AUTO_INCREMENT for table `indentlist` -- ALTER TABLE `indentlist` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=74; -- -- AUTO_INCREMENT for table `users` -- ALTER TABLE `users` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=40; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;