├── README.md └── book ├── book.iml ├── src ├── dao │ ├── BookDao.java │ ├── OrderDao.java │ ├── OrderItemDao.java │ ├── UserDao.java │ └── impl │ │ ├── BaseDao.java │ │ ├── BookDaoImpl.java │ │ ├── OrderDaoImpl.java │ │ ├── OrderItemImpl.java │ │ └── UserDaoImpl.java ├── filter │ ├── ManagerFilter.java │ └── TransactionFilter.java ├── jdbc.properties ├── pojo │ ├── Book.java │ ├── Cart.java │ ├── CartItem.java │ ├── Order.java │ ├── OrderItem.java │ ├── Page.java │ └── User.java ├── service │ ├── BookService.java │ ├── OrderService.java │ ├── UserService.java │ └── impl │ │ ├── BookServiceImpl.java │ │ ├── OrderServiceImpl.java │ │ └── UserServiceImpl.java ├── test │ ├── BookDaoTest.java │ ├── BookServiceTest.java │ ├── JdbcUtilsTest.java │ ├── UserDaoTest.java │ └── UserServiceImplTest.java ├── utils │ ├── JdbcUtils.java │ └── WebUtils.java └── web │ ├── BaseServlet.java │ ├── BookServlet.java │ ├── CartServlet.java │ ├── ClientBookServlet.java │ ├── OrderServlet.java │ └── UserServlet.java └── web ├── WEB-INF ├── lib │ ├── commons-beanutils-1.8.0.jar │ ├── commons-dbutils-1.3.jar │ ├── commons-logging-1.1.1.jar │ ├── druid-1.1.9.jar │ ├── hamcrest-core-1.3.jar │ ├── junit-4.12.jar │ ├── kaptcha-2.3.2.jar │ ├── mysql-connector-java-5.1.7-bin.jar │ ├── taglibs-standard-impl-1.2.1.jar │ └── taglibs-standard-spec-1.2.1.jar └── web.xml ├── index.jsp ├── pages ├── cart │ ├── cart.jsp │ └── checkout.jsp ├── client │ └── client_index.jsp ├── common │ ├── foot.jsp │ ├── head.jsp │ ├── login_success_menu.jsp │ ├── manager_menu.jsp │ └── page_nav.jsp ├── error │ └── error500.jsp ├── manager │ ├── book_edit.jsp │ ├── book_manager.jsp │ ├── manager.jsp │ └── order_manager.jsp ├── order │ └── order.jsp └── user │ ├── login.jsp │ ├── login_success.jsp │ ├── regist.jsp │ └── regist_success.jsp └── static ├── css └── style.css ├── img ├── code.bmp ├── default.jpg ├── logo.gif └── pwd-icons-new.png └── script └── jquery-1.7.2.js /README.md: -------------------------------------------------------------------------------- 1 | # Library 2 | 基于JavaWeb的简单图书馆管理系统 3 | -------------------------------------------------------------------------------- /book/book.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /book/src/dao/BookDao.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import pojo.Book; 4 | 5 | import java.awt.*; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @ClassName BookDao 11 | * @Description TODO 12 | * @Author SawyerRen 13 | * @Date 2020/3/26 17:02 14 | */ 15 | public interface BookDao { 16 | 17 | public int addBook(Book book); 18 | 19 | public int deleteById(Integer id); 20 | 21 | public int updateBook(Book book); 22 | 23 | public Book queryBookById(Integer id); 24 | 25 | public List queryBooks(); 26 | 27 | Integer queryForPageTotalCount(); 28 | 29 | List queryForPageItems(int begin, int pageSize); 30 | 31 | Integer queryForPageTotalCountByPrice(int min,int max); 32 | 33 | List queryForPageItemsByPrice(int begin, int pageSize, int min, int max); 34 | } 35 | -------------------------------------------------------------------------------- /book/src/dao/OrderDao.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import pojo.Order; 4 | 5 | public interface OrderDao { 6 | int saveOrder(Order order); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /book/src/dao/OrderItemDao.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import pojo.OrderItem; 4 | 5 | public interface OrderItemDao { 6 | int saveOrderItem(OrderItem orderItem); 7 | } 8 | -------------------------------------------------------------------------------- /book/src/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import pojo.User; 4 | 5 | /** 6 | * @ClassName UserDao 7 | * @Description TODO 8 | * @Author SawyerRen 9 | * @Date 2020/3/22 15:18 10 | */ 11 | public interface UserDao { 12 | 13 | /** 14 | * 根据用户名查询用户信息 15 | * 16 | * @param username 用户名 17 | * @return 18 | */ 19 | public User queryUserByUsername(String username); 20 | 21 | /** 22 | * 根据用户名和密码查询 23 | * 24 | * @param username 25 | * @param password 26 | * @return 27 | */ 28 | public User queryUserByUsernameAndPassword(String username, String password); 29 | 30 | /** 31 | * 保存用户信息 32 | * 33 | * @param user 34 | * @return 35 | */ 36 | public int saveUser(User user); 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /book/src/dao/impl/BaseDao.java: -------------------------------------------------------------------------------- 1 | package dao.impl; 2 | 3 | import org.apache.commons.dbutils.QueryRunner; 4 | import org.apache.commons.dbutils.handlers.BeanHandler; 5 | import org.apache.commons.dbutils.handlers.BeanListHandler; 6 | import org.apache.commons.dbutils.handlers.ScalarHandler; 7 | import utils.JdbcUtils; 8 | 9 | import java.sql.Connection; 10 | import java.sql.SQLException; 11 | import java.util.List; 12 | 13 | /** 14 | * @ClassName BaseDao 15 | * @Description TODO 16 | * @Author SawyerRen 17 | * @Date 2020/3/22 15:02 18 | */ 19 | public abstract class BaseDao { 20 | 21 | private QueryRunner queryRunner = new QueryRunner(); 22 | 23 | public int update(String sql, Object... args) { 24 | Connection conn = JdbcUtils.getConnection(); 25 | try { 26 | return queryRunner.update(conn, sql, args); 27 | } catch (SQLException e) { 28 | e.printStackTrace(); 29 | throw new RuntimeException(e); 30 | } 31 | } 32 | 33 | public T queryForOne(Class type, String sql, Object... args) { 34 | Connection conn = JdbcUtils.getConnection(); 35 | try { 36 | return queryRunner.query(conn, sql, new BeanHandler(type), args); 37 | } catch (SQLException e) { 38 | e.printStackTrace(); 39 | throw new RuntimeException(e); 40 | } 41 | } 42 | 43 | public List queryForList(Class type, String sql, Object... args) { 44 | Connection conn = JdbcUtils.getConnection(); 45 | try { 46 | return queryRunner.query(conn, sql, new BeanListHandler(type), args); 47 | } catch (SQLException e) { 48 | e.printStackTrace(); 49 | throw new RuntimeException(e); 50 | } 51 | } 52 | 53 | public Object queryForSingleValue(String sql, Object... args) { 54 | Connection conn = JdbcUtils.getConnection(); 55 | try { 56 | return queryRunner.query(conn, sql, new ScalarHandler(), args); 57 | } catch (Exception e) { 58 | e.printStackTrace(); 59 | throw new RuntimeException(e); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /book/src/dao/impl/BookDaoImpl.java: -------------------------------------------------------------------------------- 1 | package dao.impl; 2 | 3 | import dao.BookDao; 4 | import pojo.Book; 5 | 6 | import java.util.List; 7 | 8 | 9 | /** 10 | * @ClassName BookDaoImpl 11 | * @Description TODO 12 | * @Author SawyerRen 13 | * @Date 2020/3/26 17:05 14 | */ 15 | public class BookDaoImpl extends BaseDao implements BookDao { 16 | 17 | @Override 18 | public int addBook(Book book) { 19 | String sql = "INSERT INTO t_book(`name` , `author` , `price` , `sales` , `stock` , `img_path`) " + 20 | "value(?,?,?,?,?,?)"; 21 | return update(sql, book.getName(), book.getAuthor(), book.getPrice(), 22 | book.getSales(), book.getStock(), book.getImgPath()); 23 | } 24 | 25 | @Override 26 | public int deleteById(Integer id) { 27 | String sql = "delete from t_book where id=?"; 28 | return update(sql, id); 29 | } 30 | 31 | @Override 32 | public int updateBook(Book book) { 33 | String sql = "update t_book set `name`=? , `author`=? , `price`=? , `sales`=? , `stock`=? , `img_path`=? where id = ?"; 34 | return update(sql, book.getName(), book.getAuthor(), book.getPrice(), 35 | book.getSales(), book.getStock(), book.getImgPath(), book.getId()); 36 | } 37 | 38 | @Override 39 | public Book queryBookById(Integer id) { 40 | String sql = "select id,name,author,price,sales,stock,img_path from t_book where id=?"; 41 | return queryForOne(Book.class, sql, id); 42 | } 43 | 44 | @Override 45 | public List queryBooks() { 46 | String sql = "select id,name,author,price,sales,stock,img_path from t_book"; 47 | return queryForList(Book.class, sql); 48 | } 49 | 50 | @Override 51 | public Integer queryForPageTotalCount() { 52 | String sql = "select count(*) from t_book"; 53 | Number count = (Number) queryForSingleValue(sql); 54 | return count.intValue(); 55 | } 56 | 57 | @Override 58 | public List queryForPageItems(int begin, int pageSize) { 59 | String sql = "select id,name,author,price,sales,stock,img_path from t_book limit ?,?"; 60 | return queryForList(Book.class, sql, begin, pageSize); 61 | } 62 | 63 | @Override 64 | public Integer queryForPageTotalCountByPrice(int min, int max) { 65 | String sql = "select count(*) from t_book where price between ? and ?"; 66 | Number count = (Number) queryForSingleValue(sql, min, max); 67 | return count.intValue(); 68 | 69 | } 70 | 71 | @Override 72 | public List queryForPageItemsByPrice(int begin, int pageSize, int min, int max) { 73 | String sql = "select id,name,author,price,sales,stock,img_path " + 74 | "from t_book where price between ? and ? order by price limit ?,? "; 75 | return queryForList(Book.class, sql, min, max, begin, pageSize); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /book/src/dao/impl/OrderDaoImpl.java: -------------------------------------------------------------------------------- 1 | package dao.impl; 2 | 3 | import dao.OrderDao; 4 | import pojo.Order; 5 | 6 | /** 7 | * @ClassName OrderDaoImpl 8 | * @Description TODO 9 | * @Author SawyerRen 10 | * @Date 2020/3/28 15:44 11 | */ 12 | public class OrderDaoImpl extends BaseDao implements OrderDao { 13 | @Override 14 | public int saveOrder(Order order) { 15 | String sql = "insert into t_order(`order_id`,`create_time`,`price`,`status`,`user_id`)" + 16 | "values(?,?,?,?,?)"; 17 | return update(sql, order.getOrderId(), order.getCreateTime(), order.getPrice(), order.getStatus(), order.getUserId()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /book/src/dao/impl/OrderItemImpl.java: -------------------------------------------------------------------------------- 1 | package dao.impl; 2 | 3 | import dao.OrderItemDao; 4 | import pojo.OrderItem; 5 | 6 | /** 7 | * @ClassName OrderItemImpl 8 | * @Description TODO 9 | * @Author SawyerRen 10 | * @Date 2020/3/28 15:46 11 | */ 12 | public class OrderItemImpl extends BaseDao implements OrderItemDao { 13 | @Override 14 | public int saveOrderItem(OrderItem orderItem) { 15 | String sql = "insert into t_order_item(`name`,`count`,`price`,`total_price`,`order_id`)" + 16 | "values(?,?,?,?,?)"; 17 | return update(sql, orderItem.getName(), orderItem.getCount(), orderItem.getPrice(), orderItem.getTotalPrice(), orderItem.getOrderId()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /book/src/dao/impl/UserDaoImpl.java: -------------------------------------------------------------------------------- 1 | package dao.impl; 2 | 3 | import dao.UserDao; 4 | import pojo.User; 5 | 6 | /** 7 | * @ClassName UserDaoImpl 8 | * @Description TODO 9 | * @Author SawyerRen 10 | * @Date 2020/3/22 15:23 11 | */ 12 | public class UserDaoImpl extends BaseDao implements UserDao { 13 | @Override 14 | public User queryUserByUsername(String username) { 15 | String sql = "select `id`,`username`,`password`,`email` from t_user where username = ?"; 16 | return queryForOne(User.class, sql, username); 17 | } 18 | 19 | @Override 20 | public User queryUserByUsernameAndPassword(String username, String password) { 21 | String sql = "select `id`,`username`,`password`,`email` from t_user where username = ? and password = ?"; 22 | return queryForOne(User.class, sql, username, password); 23 | 24 | } 25 | 26 | @Override 27 | public int saveUser(User user) { 28 | String sql = "INSERT INTO t_user(`username`,`password`,`email`) VALUES(?,?,?)"; 29 | return update(sql, user.getUsername(), user.getPassword(), user.getEmail()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /book/src/filter/ManagerFilter.java: -------------------------------------------------------------------------------- 1 | package filter; 2 | 3 | import javax.servlet.*; 4 | import javax.servlet.http.HttpServletRequest; 5 | import java.io.IOException; 6 | 7 | public class ManagerFilter implements Filter { 8 | public void destroy() { 9 | } 10 | 11 | public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException { 12 | HttpServletRequest httpServletRequest = (HttpServletRequest) req; 13 | Object user = httpServletRequest.getSession().getAttribute("user"); 14 | if (user == null) { 15 | httpServletRequest.getRequestDispatcher("/pages/user/login.jsp").forward(req, resp); 16 | } else { 17 | chain.doFilter(req, resp); 18 | } 19 | } 20 | 21 | public void init(FilterConfig config) throws ServletException { 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /book/src/filter/TransactionFilter.java: -------------------------------------------------------------------------------- 1 | package filter; 2 | 3 | import utils.JdbcUtils; 4 | 5 | import javax.servlet.*; 6 | import java.io.IOException; 7 | 8 | /** 9 | * @ClassName TransactionFilter 10 | * @Description TODO 11 | * @Author SawyerRen 12 | * @Date 2020/3/28 21:10 13 | */ 14 | public class TransactionFilter implements Filter { 15 | @Override 16 | public void init(FilterConfig filterConfig) throws ServletException { 17 | 18 | } 19 | 20 | @Override 21 | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { 22 | try { 23 | filterChain.doFilter(servletRequest,servletResponse); 24 | JdbcUtils.commitAndClose(); 25 | } catch (Exception e) { 26 | JdbcUtils.rollbackAndClose(); 27 | e.printStackTrace(); 28 | throw new RuntimeException(e); 29 | } 30 | } 31 | 32 | @Override 33 | public void destroy() { 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /book/src/jdbc.properties: -------------------------------------------------------------------------------- 1 | username=root 2 | password=123456 3 | url=jdbc:mysql://localhost:3306/book 4 | driverClassName=com.mysql.jdbc.Driver 5 | initialSize=5 6 | maxActive=10 -------------------------------------------------------------------------------- /book/src/pojo/Book.java: -------------------------------------------------------------------------------- 1 | package pojo; 2 | 3 | public class Book { 4 | private Integer id; 5 | private String name; 6 | private String author; 7 | private double price; 8 | private Integer sales; 9 | private Integer stock; 10 | private String imgPath = "static/img/default.jpg"; 11 | 12 | public Book() { 13 | } 14 | 15 | public Book(Integer id, String name, String author, double price, Integer sales, Integer stock, String imgPath) { 16 | this.id = id; 17 | this.name = name; 18 | this.author = author; 19 | this.price = price; 20 | this.sales = sales; 21 | this.stock = stock; 22 | if (imgPath != null && !"".equals(imgPath)) { 23 | this.imgPath = imgPath; 24 | } 25 | } 26 | 27 | public Integer getId() { 28 | return id; 29 | } 30 | 31 | public void setId(Integer id) { 32 | this.id = id; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | 43 | public String getAuthor() { 44 | return author; 45 | } 46 | 47 | public void setAuthor(String author) { 48 | this.author = author; 49 | } 50 | 51 | public double getPrice() { 52 | return price; 53 | } 54 | 55 | public void setPrice(double price) { 56 | this.price = price; 57 | } 58 | 59 | public Integer getSales() { 60 | return sales; 61 | } 62 | 63 | public void setSales(Integer sales) { 64 | this.sales = sales; 65 | } 66 | 67 | public Integer getStock() { 68 | return stock; 69 | } 70 | 71 | public void setStock(Integer stock) { 72 | this.stock = stock; 73 | } 74 | 75 | public String getImgPath() { 76 | return imgPath; 77 | } 78 | 79 | public void setImgPath(String imgPath) { 80 | if (imgPath != null && !"".equals(imgPath)) { 81 | this.imgPath = imgPath; 82 | } 83 | } 84 | 85 | @Override 86 | public String toString() { 87 | return "book{" + 88 | "id=" + id + 89 | ", name='" + name + '\'' + 90 | ", author='" + author + '\'' + 91 | ", price=" + price + 92 | ", sales=" + sales + 93 | ", stock=" + stock + 94 | ", imgPath='" + imgPath + '\'' + 95 | '}'; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /book/src/pojo/Cart.java: -------------------------------------------------------------------------------- 1 | package pojo; 2 | 3 | 4 | import java.util.ArrayList; 5 | import java.util.LinkedHashMap; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | public class Cart { 10 | private Map items = new LinkedHashMap<>(); 11 | 12 | public void addItem(CartItem cartItem) { 13 | CartItem item = items.get(cartItem.getId()); 14 | if (item == null) { 15 | items.put(cartItem.getId(), cartItem); 16 | } else { 17 | item.setCount(item.getCount() + 1); 18 | item.setTotalPrice(item.getPrice() * item.getCount()); 19 | } 20 | } 21 | 22 | public void deleteItem(Integer id) { 23 | items.remove(id); 24 | } 25 | 26 | public void clear() { 27 | items.clear(); 28 | ; 29 | } 30 | 31 | public void updateCount(Integer id, Integer count) { 32 | CartItem item = items.get(id); 33 | if (item != null) { 34 | item.setCount(count); 35 | item.setTotalPrice(item.getPrice() * item.getCount()); 36 | } 37 | } 38 | 39 | public Integer getTotalCount() { 40 | Integer totalCount = 0; 41 | for (Map.Entry entry : items.entrySet()) { 42 | CartItem item = entry.getValue(); 43 | totalCount += item.getCount(); 44 | } 45 | return totalCount; 46 | } 47 | 48 | public double getTotalPrice() { 49 | double totalPrice = 0; 50 | for (Map.Entry entry : items.entrySet()) { 51 | CartItem item = entry.getValue(); 52 | totalPrice += item.getPrice(); 53 | } 54 | return totalPrice; 55 | 56 | } 57 | 58 | public Map getItems() { 59 | return items; 60 | } 61 | 62 | public void setItems(Map items) { 63 | this.items = items; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return "Cart{" + 69 | "totalCount=" + getTotalCount() + 70 | ", totalPrice=" + getTotalPrice() + 71 | ", items=" + items + 72 | '}'; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /book/src/pojo/CartItem.java: -------------------------------------------------------------------------------- 1 | package pojo; 2 | 3 | public class CartItem { 4 | private Integer id; 5 | private String name; 6 | private Integer count; 7 | private double price; 8 | private double totalPrice; 9 | 10 | public CartItem() { 11 | } 12 | 13 | public CartItem(Integer id, String name, Integer count, double price, double totalPrice) { 14 | this.id = id; 15 | this.name = name; 16 | this.count = count; 17 | this.price = price; 18 | this.totalPrice = totalPrice; 19 | } 20 | 21 | public Integer getId() { 22 | return id; 23 | } 24 | 25 | public void setId(Integer id) { 26 | this.id = id; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | 37 | public Integer getCount() { 38 | return count; 39 | } 40 | 41 | public void setCount(Integer count) { 42 | this.count = count; 43 | } 44 | 45 | public double getPrice() { 46 | return price; 47 | } 48 | 49 | public void setPrice(double price) { 50 | this.price = price; 51 | } 52 | 53 | public double getTotalPrice() { 54 | return totalPrice; 55 | } 56 | 57 | public void setTotalPrice(double totalPrice) { 58 | this.totalPrice = totalPrice; 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return "CartItem{" + 64 | "id=" + id + 65 | ", name='" + name + '\'' + 66 | ", count=" + count + 67 | ", price=" + price + 68 | ", totalPrice=" + totalPrice + 69 | '}'; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /book/src/pojo/Order.java: -------------------------------------------------------------------------------- 1 | package pojo; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * @ClassName Order 7 | * @Description TODO 8 | * @Author SawyerRen 9 | * @Date 2020/3/28 15:37 10 | */ 11 | public class Order { 12 | private String orderId; 13 | private Date createTime; 14 | private double price; 15 | private Integer status = 0; 16 | private Integer userId; 17 | 18 | public Order() { 19 | } 20 | 21 | public Order(String orderId, Date createTime, double price, Integer status, Integer userId) { 22 | this.orderId = orderId; 23 | this.createTime = createTime; 24 | this.price = price; 25 | this.status = status; 26 | this.userId = userId; 27 | } 28 | 29 | public String getOrderId() { 30 | return orderId; 31 | } 32 | 33 | public void setOrderId(String orderId) { 34 | this.orderId = orderId; 35 | } 36 | 37 | public Date getCreateTime() { 38 | return createTime; 39 | } 40 | 41 | public void setCreateTime(Date createTime) { 42 | this.createTime = createTime; 43 | } 44 | 45 | public double getPrice() { 46 | return price; 47 | } 48 | 49 | public void setPrice(double price) { 50 | this.price = price; 51 | } 52 | 53 | public Integer getStatus() { 54 | return status; 55 | } 56 | 57 | public void setStatus(Integer status) { 58 | this.status = status; 59 | } 60 | 61 | public Integer getUserId() { 62 | return userId; 63 | } 64 | 65 | public void setUserId(Integer userId) { 66 | this.userId = userId; 67 | } 68 | 69 | @Override 70 | public String toString() { 71 | return "Order{" + 72 | "orderId='" + orderId + '\'' + 73 | ", createTime=" + createTime + 74 | ", price=" + price + 75 | ", status=" + status + 76 | ", userId=" + userId + 77 | '}'; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /book/src/pojo/OrderItem.java: -------------------------------------------------------------------------------- 1 | package pojo; 2 | 3 | /** 4 | * @ClassName OrderItem 5 | * @Description TODO 6 | * @Author SawyerRen 7 | * @Date 2020/3/28 15:39 8 | */ 9 | public class OrderItem { 10 | private Integer id; 11 | private String name; 12 | private Integer count; 13 | private double price; 14 | private double totalPrice; 15 | private String orderId; 16 | 17 | public OrderItem() { 18 | } 19 | 20 | public OrderItem(Integer id, String name, Integer count, double price, double totalPrice, String orderId) { 21 | this.id = id; 22 | this.name = name; 23 | this.count = count; 24 | this.price = price; 25 | this.totalPrice = totalPrice; 26 | this.orderId = orderId; 27 | } 28 | 29 | public Integer getId() { 30 | return id; 31 | } 32 | 33 | public void setId(Integer id) { 34 | this.id = id; 35 | } 36 | 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | public Integer getCount() { 46 | return count; 47 | } 48 | 49 | public void setCount(Integer count) { 50 | this.count = count; 51 | } 52 | 53 | public double getPrice() { 54 | return price; 55 | } 56 | 57 | public void setPrice(double price) { 58 | this.price = price; 59 | } 60 | 61 | public double getTotalPrice() { 62 | return totalPrice; 63 | } 64 | 65 | public void setTotalPrice(double totalPrice) { 66 | this.totalPrice = totalPrice; 67 | } 68 | 69 | public String getOrderId() { 70 | return orderId; 71 | } 72 | 73 | public void setOrderId(String orderId) { 74 | this.orderId = orderId; 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return "OrderItem{" + 80 | "id=" + id + 81 | ", name='" + name + '\'' + 82 | ", count=" + count + 83 | ", price=" + price + 84 | ", totalPrice=" + totalPrice + 85 | ", orderId='" + orderId + '\'' + 86 | '}'; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /book/src/pojo/Page.java: -------------------------------------------------------------------------------- 1 | package pojo; 2 | 3 | import java.util.List; 4 | 5 | public class Page { 6 | public static final Integer PAGE_SIZE = 4;//页面大小 7 | 8 | private Integer pageNo;//页数 9 | private Integer pageTotal;//总页数 10 | private Integer pageSize = PAGE_SIZE; 11 | private Integer pageTotalCount;//总图书数 12 | private List items; 13 | private String url; 14 | 15 | public String getUrl() { 16 | return url; 17 | } 18 | 19 | public void setUrl(String url) { 20 | this.url = url; 21 | } 22 | 23 | public Integer getPageNo() { 24 | return pageNo; 25 | } 26 | 27 | public void setPageNo(Integer pageNo) { 28 | this.pageNo = pageNo; 29 | } 30 | 31 | public Integer getPageSize() { 32 | return pageSize; 33 | } 34 | 35 | public void setPageSize(Integer pageSize) { 36 | this.pageSize = pageSize; 37 | } 38 | 39 | public Integer getPageTotal() { 40 | return pageTotal; 41 | } 42 | 43 | public void setPageTotal(Integer pageTotal) { 44 | this.pageTotal = pageTotal; 45 | } 46 | 47 | public Integer getPageTotalCount() { 48 | return pageTotalCount; 49 | } 50 | 51 | public void setPageTotalCount(Integer pageTotalCount) { 52 | this.pageTotalCount = pageTotalCount; 53 | } 54 | 55 | public List getItems() { 56 | return items; 57 | } 58 | 59 | public void setItems(List items) { 60 | this.items = items; 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | return "Page{" + 66 | "pageNo=" + pageNo + 67 | ", pageTotal=" + pageTotal + 68 | ", pageSize=" + pageSize + 69 | ", pageTotalCount=" + pageTotalCount + 70 | ", items=" + items + 71 | ", url='" + url + '\'' + 72 | '}'; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /book/src/pojo/User.java: -------------------------------------------------------------------------------- 1 | package pojo; 2 | 3 | /** 4 | * @ClassName User 5 | * @Description TODO 6 | * @Author SawyerRen 7 | * @Date 2020/3/22 14:37 8 | */ 9 | public class User { 10 | private Integer id; 11 | private String username; 12 | private String password; 13 | private String email; 14 | 15 | public Integer getId() { 16 | return id; 17 | } 18 | 19 | public void setId(Integer id) { 20 | this.id = id; 21 | } 22 | 23 | public String getUsername() { 24 | return username; 25 | } 26 | 27 | public void setUsername(String username) { 28 | this.username = username; 29 | } 30 | 31 | public String getPassword() { 32 | return password; 33 | } 34 | 35 | public void setPassword(String password) { 36 | this.password = password; 37 | } 38 | 39 | public String getEmail() { 40 | return email; 41 | } 42 | 43 | public void setEmail(String email) { 44 | this.email = email; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "User{" + 50 | "id=" + id + 51 | ", username='" + username + '\'' + 52 | ", password='" + password + '\'' + 53 | ", email='" + email + '\'' + 54 | '}'; 55 | } 56 | 57 | public User() { 58 | } 59 | 60 | public User(Integer id, String username, String password, String email) { 61 | this.id = id; 62 | this.username = username; 63 | this.password = password; 64 | this.email = email; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /book/src/service/BookService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import pojo.Book; 4 | import pojo.Page; 5 | 6 | import java.util.List; 7 | 8 | public interface BookService { 9 | 10 | void addBook(Book book); 11 | 12 | void deleteBookById(Integer id); 13 | 14 | void updateBook(Book book); 15 | 16 | Book queryBookById(Integer id); 17 | 18 | List queryBooks(); 19 | 20 | Page page(int pageNo, int pageSize); 21 | 22 | Page pageByPrice(int pageNo, int pageSize, int min, int max); 23 | } 24 | -------------------------------------------------------------------------------- /book/src/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import pojo.Cart; 4 | 5 | /** 6 | * @ClassName OrderService 7 | * @Description TODO 8 | * @Author SawyerRen 9 | * @Date 2020/3/28 15:54 10 | */ 11 | public interface OrderService { 12 | String createOrder(Cart cart,Integer userId); 13 | } 14 | -------------------------------------------------------------------------------- /book/src/service/UserService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import pojo.User; 4 | 5 | public interface UserService { 6 | /** 7 | * 注册用户 8 | * @param user 9 | */ 10 | public void registerUser(User user); 11 | 12 | public User login(User user); 13 | 14 | public boolean existUsername(String username); 15 | } 16 | -------------------------------------------------------------------------------- /book/src/service/impl/BookServiceImpl.java: -------------------------------------------------------------------------------- 1 | package service.impl; 2 | 3 | import dao.BookDao; 4 | import dao.impl.BookDaoImpl; 5 | import pojo.Book; 6 | import pojo.Page; 7 | import service.BookService; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @ClassName BookServiceImpl 13 | * @Description TODO 14 | * @Author SawyerRen 15 | * @Date 2020/3/26 17:27 16 | */ 17 | public class BookServiceImpl implements BookService { 18 | private BookDao bookDao = new BookDaoImpl(); 19 | 20 | @Override 21 | public void addBook(Book book) { 22 | bookDao.addBook(book); 23 | } 24 | 25 | @Override 26 | public void deleteBookById(Integer id) { 27 | bookDao.deleteById(id); 28 | } 29 | 30 | @Override 31 | public void updateBook(Book book) { 32 | bookDao.updateBook(book); 33 | } 34 | 35 | @Override 36 | public Book queryBookById(Integer id) { 37 | return bookDao.queryBookById(id); 38 | } 39 | 40 | @Override 41 | public List queryBooks() { 42 | return bookDao.queryBooks(); 43 | } 44 | 45 | @Override 46 | public Page page(int pageNo, int pageSize) { 47 | Page page = new Page<>(); 48 | page.setPageNo(pageNo); 49 | page.setPageSize(pageSize); 50 | Integer pageTotalCount = bookDao.queryForPageTotalCount(); 51 | page.setPageTotalCount(pageTotalCount); 52 | Integer pageTotal = pageTotalCount / pageSize; 53 | if (pageTotalCount % pageSize > 0) { 54 | pageTotal++; 55 | } 56 | page.setPageTotal(pageTotal); 57 | int begin = (page.getPageNo() - 1) * pageSize; 58 | List items = bookDao.queryForPageItems(begin, pageSize); 59 | page.setItems(items); 60 | return page; 61 | } 62 | 63 | @Override 64 | public Page pageByPrice(int pageNo, int pageSize, int min, int max) { 65 | Page page = new Page<>(); 66 | page.setPageNo(pageNo); 67 | page.setPageSize(pageSize); 68 | Integer pageTotalCount = bookDao.queryForPageTotalCountByPrice(min,max); 69 | page.setPageTotalCount(pageTotalCount); 70 | Integer pageTotal = pageTotalCount / pageSize; 71 | if (pageTotalCount % pageSize > 0) { 72 | pageTotal++; 73 | } 74 | page.setPageTotal(pageTotal); 75 | int begin = (page.getPageNo() - 1) * pageSize; 76 | List items = bookDao.queryForPageItemsByPrice(begin, pageSize, min, max); 77 | page.setItems(items); 78 | return page; 79 | 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /book/src/service/impl/OrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package service.impl; 2 | 3 | import dao.OrderDao; 4 | import dao.OrderItemDao; 5 | import dao.impl.OrderDaoImpl; 6 | import dao.impl.OrderItemImpl; 7 | import pojo.Cart; 8 | import pojo.CartItem; 9 | import pojo.Order; 10 | import pojo.OrderItem; 11 | import service.OrderService; 12 | 13 | import java.util.Date; 14 | import java.util.Map; 15 | 16 | /** 17 | * @ClassName OrderServiceImpl 18 | * @Description TODO 19 | * @Author SawyerRen 20 | * @Date 2020/3/28 15:55 21 | */ 22 | public class OrderServiceImpl implements OrderService { 23 | private OrderDao orderDao = new OrderDaoImpl(); 24 | private OrderItemDao orderItemDao = new OrderItemImpl(); 25 | 26 | @Override 27 | public String createOrder(Cart cart, Integer userId) { 28 | String orderId = System.currentTimeMillis() + "" + userId; 29 | Order order = new Order(orderId, new Date(), cart.getTotalPrice(), 0, userId); 30 | orderDao.saveOrder(order); 31 | for (Map.Entry entry : cart.getItems().entrySet()) { 32 | CartItem cartItem = entry.getValue(); 33 | OrderItem orderItem = new OrderItem(null, cartItem.getName(), cartItem.getCount(), cartItem.getPrice(), cartItem.getTotalPrice(), orderId); 34 | orderItemDao.saveOrderItem(orderItem); 35 | } 36 | cart.clear(); 37 | return orderId; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /book/src/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package service.impl; 2 | 3 | import dao.UserDao; 4 | import dao.impl.UserDaoImpl; 5 | import pojo.User; 6 | import service.UserService; 7 | 8 | /** 9 | * @ClassName UserServiceImpl 10 | * @Description TODO 11 | * @Author SawyerRen 12 | * @Date 2020/3/22 16:06 13 | */ 14 | public class UserServiceImpl implements UserService { 15 | private UserDao userDao = new UserDaoImpl(); 16 | 17 | @Override 18 | public void registerUser(User user) { 19 | userDao.saveUser(user); 20 | } 21 | 22 | @Override 23 | public User login(User user) { 24 | return userDao.queryUserByUsernameAndPassword(user.getUsername(), user.getPassword()); 25 | } 26 | 27 | @Override 28 | public boolean existUsername(String username) { 29 | return userDao.queryUserByUsername(username) != null; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /book/src/test/BookDaoTest.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import dao.BookDao; 4 | import dao.impl.BookDaoImpl; 5 | import org.junit.Test; 6 | import pojo.Book; 7 | 8 | import java.util.List; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | public class BookDaoTest { 13 | private BookDao bookDao = new BookDaoImpl(); 14 | 15 | @Test 16 | public void addBook() { 17 | bookDao.addBook(new Book(null, "123", "1231", 999, 1000, 0, null)); 18 | } 19 | 20 | @Test 21 | public void deleteById() { 22 | bookDao.deleteById(42); 23 | } 24 | 25 | @Test 26 | public void updateBook() { 27 | bookDao.updateBook(new Book(42, "321", "1231", 999, 1000, 0, null)); 28 | } 29 | 30 | @Test 31 | public void queryBookById() { 32 | System.out.println(bookDao.queryBookById(42)); 33 | } 34 | 35 | @Test 36 | public void queryBooks() { 37 | for (Book book : bookDao.queryBooks()) { 38 | System.out.println(book); 39 | } 40 | } 41 | 42 | @Test 43 | public void queryForPageTotalCount() { 44 | System.out.println(bookDao.queryForPageTotalCount()); 45 | } 46 | 47 | @Test 48 | public void queryForPageItems() { 49 | List books = bookDao.queryForPageItems(0, 4); 50 | for (Book book : books) { 51 | System.out.println(book); 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /book/src/test/BookServiceTest.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import org.junit.Test; 4 | import pojo.Book; 5 | import service.BookService; 6 | import service.impl.BookServiceImpl; 7 | 8 | import static org.junit.Assert.*; 9 | 10 | public class BookServiceTest { 11 | BookService bookService = new BookServiceImpl(); 12 | 13 | @Test 14 | public void addBook() { 15 | bookService.addBook(new Book(null, "1234", "1234", 999, 10, 0, null)); 16 | } 17 | 18 | @Test 19 | public void deleteBookById() { 20 | bookService.deleteBookById(44); 21 | } 22 | 23 | @Test 24 | public void updateBook() { 25 | bookService.updateBook(new Book(44, "lalalaa", "lala", 1000, 20, 20, null)); 26 | } 27 | 28 | @Test 29 | public void queryBookById() { 30 | System.out.println(bookService.queryBookById(44)); 31 | } 32 | 33 | @Test 34 | public void queryBooks() { 35 | for (Book queryBook : bookService.queryBooks()) { 36 | System.out.println(queryBook); 37 | } 38 | } 39 | 40 | @Test 41 | public void page() { 42 | System.out.println(bookService.page(1,4)); 43 | } 44 | } -------------------------------------------------------------------------------- /book/src/test/JdbcUtilsTest.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import org.junit.Test; 4 | import utils.JdbcUtils; 5 | 6 | /** 7 | * @ClassName JdbcUtilsTest 8 | * @Description TODO 9 | * @Author SawyerRen 10 | * @Date 2020/3/22 14:53 11 | */ 12 | public class JdbcUtilsTest { 13 | @Test 14 | public void testJdbcUtils(){ 15 | System.out.println(JdbcUtils.getConnection()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /book/src/test/UserDaoTest.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import dao.UserDao; 4 | import dao.impl.UserDaoImpl; 5 | import org.junit.Test; 6 | import pojo.User; 7 | 8 | import static org.junit.Assert.*; 9 | 10 | public class UserDaoTest { 11 | 12 | @Test 13 | public void queryUserByUsername() { 14 | UserDaoImpl userDao = new UserDaoImpl(); 15 | System.out.println(userDao.queryUserByUsername("admin")); 16 | } 17 | 18 | @Test 19 | public void queryUserByUsernameAndPassword() { 20 | UserDaoImpl userDao = new UserDaoImpl(); 21 | System.out.println(userDao.queryUserByUsernameAndPassword("admin","admin")); 22 | 23 | } 24 | 25 | @Test 26 | public void saveUser() { 27 | UserDaoImpl userDao = new UserDaoImpl(); 28 | System.out.println(userDao.saveUser(new User(null,"admin","123456","123@qq.com"))); 29 | } 30 | } -------------------------------------------------------------------------------- /book/src/test/UserServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import org.junit.Test; 4 | import pojo.User; 5 | import service.UserService; 6 | import service.impl.UserServiceImpl; 7 | 8 | import static org.junit.Assert.*; 9 | 10 | public class UserServiceImplTest { 11 | 12 | UserService userService = new UserServiceImpl(); 13 | 14 | @Test 15 | public void registerUser() { 16 | userService.registerUser(new User(null, "rsy", "123", "1234@qqq.com")); 17 | } 18 | 19 | @Test 20 | public void login() { 21 | System.out.println(userService.login(new User(null, "rsy", "123", ""))); 22 | } 23 | 24 | @Test 25 | public void existUsername() { 26 | if (userService.existUsername("rsy")) { 27 | System.out.println("已存在"); 28 | } else { 29 | System.out.println("不存在"); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /book/src/utils/JdbcUtils.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import com.alibaba.druid.pool.DruidDataSource; 4 | import com.alibaba.druid.pool.DruidDataSourceFactory; 5 | 6 | import java.io.InputStream; 7 | import java.sql.Connection; 8 | import java.sql.SQLException; 9 | import java.util.Properties; 10 | 11 | /** 12 | * @ClassName JdbcUtils 13 | * @Description TODO 14 | * @Author SawyerRen 15 | * @Date 2020/3/22 14:39 16 | */ 17 | public class JdbcUtils { 18 | private static DruidDataSource dataSource; 19 | private static ThreadLocal conns = new ThreadLocal<>(); 20 | 21 | static { 22 | try { 23 | Properties properties = new Properties(); 24 | InputStream inputStream = JdbcUtils.class.getClassLoader().getResourceAsStream("jdbc.properties"); 25 | properties.load(inputStream); 26 | //创建数据库连接池 27 | dataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties); 28 | } catch (Exception e) { 29 | e.printStackTrace(); 30 | } 31 | } 32 | 33 | public static Connection getConnection() { 34 | Connection conn = conns.get(); 35 | if (conn == null) { 36 | try { 37 | conn = dataSource.getConnection(); 38 | conns.set(conn); 39 | conn.setAutoCommit(false); 40 | } catch (SQLException e) { 41 | e.printStackTrace(); 42 | } 43 | } 44 | return conn; 45 | } 46 | 47 | public static void commitAndClose() { 48 | Connection connection = conns.get(); 49 | if (connection != null) { 50 | try { 51 | connection.commit(); 52 | 53 | } catch (SQLException e) { 54 | e.printStackTrace(); 55 | } finally { 56 | try { 57 | connection.close(); 58 | } catch (SQLException e) { 59 | e.printStackTrace(); 60 | } 61 | } 62 | } 63 | conns.remove(); 64 | } 65 | 66 | public static void rollbackAndClose() { 67 | Connection connection = conns.get(); 68 | if (connection != null) { 69 | try { 70 | connection.rollback(); 71 | } catch (SQLException e) { 72 | e.printStackTrace(); 73 | } finally { 74 | try { 75 | connection.close(); 76 | } catch (SQLException e) { 77 | e.printStackTrace(); 78 | } 79 | } 80 | } 81 | conns.remove(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /book/src/utils/WebUtils.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import org.apache.commons.beanutils.BeanUtils; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | import java.lang.reflect.InvocationTargetException; 7 | import java.util.Map; 8 | 9 | /** 10 | * @ClassName WebUtils 11 | * @Description TODO 12 | * @Author SawyerRen 13 | * @Date 2020/3/26 16:14 14 | */ 15 | public class WebUtils { 16 | public static T copyParamToBean(Map map, T bean) { 17 | try { 18 | BeanUtils.populate(bean, map); 19 | } catch (Exception e) { 20 | e.printStackTrace(); 21 | } 22 | return bean; 23 | } 24 | 25 | public static int parseInt(String s, int defaultValue){ 26 | try { 27 | return Integer.parseInt(s); 28 | } catch (Exception e) { 29 | e.printStackTrace(); 30 | } 31 | return defaultValue; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /book/src/web/BaseServlet.java: -------------------------------------------------------------------------------- 1 | package web; 2 | 3 | import javax.servlet.ServletException; 4 | import javax.servlet.http.HttpServlet; 5 | import javax.servlet.http.HttpServletRequest; 6 | import javax.servlet.http.HttpServletResponse; 7 | import java.io.IOException; 8 | import java.lang.reflect.Method; 9 | 10 | /** 11 | * @ClassName BaseServlet 12 | * @Description TODO 13 | * @Author SawyerRen 14 | * @Date 2020/3/26 12:07 15 | */ 16 | public abstract class BaseServlet extends HttpServlet { 17 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 18 | String action = request.getParameter("action"); 19 | try { 20 | Method method = this.getClass().getDeclaredMethod(action, HttpServletRequest.class, HttpServletResponse.class); 21 | method.invoke(this, request, response); 22 | } catch (Exception e) { 23 | e.printStackTrace(); 24 | throw new RuntimeException(e); 25 | } 26 | } 27 | 28 | @Override 29 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 30 | doPost(req, resp); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /book/src/web/BookServlet.java: -------------------------------------------------------------------------------- 1 | package web; 2 | 3 | import pojo.Book; 4 | import pojo.Page; 5 | import service.BookService; 6 | import service.impl.BookServiceImpl; 7 | import utils.WebUtils; 8 | 9 | import javax.servlet.ServletException; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | import java.io.IOException; 13 | import java.util.List; 14 | 15 | 16 | public class BookServlet extends BaseServlet { 17 | private BookService bookService = new BookServiceImpl(); 18 | 19 | protected void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 20 | Book book = WebUtils.copyParamToBean(request.getParameterMap(), new Book()); 21 | bookService.addBook(book); 22 | // request.getRequestDispatcher("/manager/bookServlet?action=list").forward(request, response); 23 | response.sendRedirect(request.getContextPath() + "/manager/bookServlet?action=page&pageNo="+request.getParameter("pageNo")); 24 | } 25 | 26 | protected void delete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 27 | Integer id = Integer.valueOf(request.getParameter("id")); 28 | bookService.deleteBookById(id); 29 | response.sendRedirect(request.getContextPath() + "/manager/bookServlet?action=page"); 30 | } 31 | 32 | protected void update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 33 | Book book = WebUtils.copyParamToBean(request.getParameterMap(), new Book()); 34 | bookService.updateBook(book); 35 | response.sendRedirect(request.getContextPath() + "/manager/bookServlet?action=page"); 36 | } 37 | 38 | protected void getBook(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 39 | Integer id = Integer.valueOf(request.getParameter("id")); 40 | Book book = bookService.queryBookById(id); 41 | request.setAttribute("book", book); 42 | request.getRequestDispatcher("/pages/manager/book_edit.jsp").forward(request, response); 43 | } 44 | 45 | protected void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 46 | List books = bookService.queryBooks(); 47 | request.setAttribute("books", books); 48 | request.getRequestDispatcher("/pages/manager/book_manager.jsp").forward(request, response); 49 | } 50 | 51 | protected void page(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 52 | int pageNo = WebUtils.parseInt(request.getParameter("pageNo"), 1); 53 | int pageSize = WebUtils.parseInt(request.getParameter("pageSize"), Page.PAGE_SIZE); 54 | Page page = bookService.page(pageNo, pageSize); 55 | page.setUrl("manager/bookServlet?action=page"); 56 | request.setAttribute("page", page); 57 | request.getRequestDispatcher("/pages/manager/book_manager.jsp").forward(request, response); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /book/src/web/CartServlet.java: -------------------------------------------------------------------------------- 1 | package web; 2 | 3 | import pojo.Book; 4 | import pojo.Cart; 5 | import pojo.CartItem; 6 | import service.BookService; 7 | import service.impl.BookServiceImpl; 8 | import utils.WebUtils; 9 | 10 | import javax.servlet.ServletException; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | import java.io.IOException; 14 | 15 | public class CartServlet extends BaseServlet { 16 | BookService bookService = new BookServiceImpl(); 17 | 18 | protected void addItem(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 19 | int id = WebUtils.parseInt(req.getParameter("id"), 0); 20 | Book book = bookService.queryBookById(id); 21 | CartItem cartItem = new CartItem(book.getId(), book.getName(), 1, book.getPrice(), book.getPrice()); 22 | Cart cart = (Cart) req.getSession().getAttribute("cart"); 23 | if (cart == null) { 24 | cart = new Cart(); 25 | req.getSession().setAttribute("cart", cart); 26 | } 27 | cart.addItem(cartItem); 28 | req.getSession().setAttribute("lastName", cartItem.getName()); 29 | resp.sendRedirect(req.getHeader("Referer")); 30 | } 31 | 32 | protected void deleteItem(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 33 | int id = WebUtils.parseInt(req.getParameter("id"), 0); 34 | Cart cart = (Cart) req.getSession().getAttribute("cart"); 35 | if (cart != null) { 36 | cart.deleteItem(id); 37 | resp.sendRedirect(req.getHeader("Referer")); 38 | } 39 | } 40 | 41 | protected void clear(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 42 | Cart cart = (Cart) req.getSession().getAttribute("cart"); 43 | if (cart != null) { 44 | cart.clear(); 45 | resp.sendRedirect(req.getHeader("Referer")); 46 | } 47 | } 48 | 49 | protected void updateCount(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 50 | int id = WebUtils.parseInt(req.getParameter("id"), 0); 51 | int count = WebUtils.parseInt(req.getParameter("count"), 1); 52 | Cart cart = (Cart) req.getSession().getAttribute("cart"); 53 | if (cart != null) { 54 | cart.updateCount(id, count); 55 | resp.sendRedirect(req.getHeader("Referer")); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /book/src/web/ClientBookServlet.java: -------------------------------------------------------------------------------- 1 | package web; 2 | 3 | import pojo.Book; 4 | import pojo.Page; 5 | import service.BookService; 6 | import service.impl.BookServiceImpl; 7 | import utils.WebUtils; 8 | 9 | import javax.servlet.ServletException; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | import java.io.IOException; 13 | 14 | /** 15 | * @ClassName ClientBookServlet 16 | * @Description TODO 17 | * @Author SawyerRen 18 | * @Date 2020/3/27 12:32 19 | */ 20 | public class ClientBookServlet extends BookServlet { 21 | private BookService bookService = new BookServiceImpl(); 22 | 23 | protected void page(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 24 | int pageNo = WebUtils.parseInt(request.getParameter("pageNo"), 1); 25 | int pageSize = WebUtils.parseInt(request.getParameter("pageSize"), Page.PAGE_SIZE); 26 | Page page = bookService.page(pageNo, pageSize); 27 | page.setUrl("client/bookServlet?action=page"); 28 | request.setAttribute("page", page); 29 | request.getRequestDispatcher("/pages/client/client_index.jsp").forward(request, response); 30 | } 31 | 32 | protected void pageByPrice(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 33 | int pageNo = WebUtils.parseInt(request.getParameter("pageNo"), 1); 34 | int pageSize = WebUtils.parseInt(request.getParameter("pageSize"), Page.PAGE_SIZE); 35 | int min = WebUtils.parseInt(request.getParameter("min"), 0); 36 | int max = WebUtils.parseInt(request.getParameter("max"), Integer.MAX_VALUE); 37 | Page page = bookService.pageByPrice(pageNo, pageSize, min, max); 38 | StringBuilder builder = new StringBuilder("client/bookServlet?action=pageByPrice"); 39 | if (request.getParameter("min") != null) { 40 | builder.append("&min=").append(request.getParameter("min")); 41 | } 42 | if (request.getParameter("max") != null) { 43 | builder.append("&max=").append(request.getParameter("max")); 44 | } 45 | page.setUrl(builder.toString()); 46 | request.setAttribute("page", page); 47 | request.getRequestDispatcher("/pages/client/client_index.jsp").forward(request, response); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /book/src/web/OrderServlet.java: -------------------------------------------------------------------------------- 1 | package web; 2 | 3 | import pojo.Cart; 4 | import pojo.User; 5 | import service.OrderService; 6 | import service.impl.OrderServiceImpl; 7 | import utils.JdbcUtils; 8 | 9 | import javax.servlet.ServletException; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | import java.io.IOException; 13 | 14 | /** 15 | * @ClassName OrderServlet 16 | * @Description TODO 17 | * @Author SawyerRen 18 | * @Date 2020/3/28 16:09 19 | */ 20 | public class OrderServlet extends BaseServlet { 21 | private OrderService orderService = new OrderServiceImpl(); 22 | 23 | protected void createOrder(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 24 | Cart cart = (Cart) req.getSession().getAttribute("cart"); 25 | User loginUser = (User) req.getSession().getAttribute("user"); 26 | Integer id = loginUser.getId(); 27 | String orderId = orderService.createOrder(cart, id); 28 | 29 | req.setAttribute("orderId", orderId); 30 | req.getRequestDispatcher("/pages/cart/checkout.jsp").forward(req, resp); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /book/src/web/UserServlet.java: -------------------------------------------------------------------------------- 1 | package web; 2 | 3 | import pojo.User; 4 | import service.UserService; 5 | import service.impl.UserServiceImpl; 6 | import utils.WebUtils; 7 | 8 | import javax.servlet.ServletException; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | import java.io.IOException; 13 | import java.lang.reflect.Method; 14 | 15 | import static com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY; 16 | 17 | public class UserServlet extends BaseServlet { 18 | private UserService userService = new UserServiceImpl(); 19 | 20 | protected void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 21 | String username = request.getParameter("username"); 22 | String password = request.getParameter("password"); 23 | User loginUser = userService.login(new User(null, username, password, null)); 24 | if (loginUser == null) { 25 | request.setAttribute("msg", "用户名或密码错误"); 26 | request.setAttribute("username", username); 27 | request.getRequestDispatcher("/pages/user/login.jsp").forward(request, response); 28 | } else { 29 | request.getSession().setAttribute("user", loginUser); 30 | request.getRequestDispatcher("/pages/user/login_success.jsp").forward(request, response); 31 | } 32 | } 33 | 34 | protected void logout(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 35 | request.getSession().invalidate(); 36 | response.sendRedirect(request.getContextPath()); 37 | } 38 | 39 | protected void register(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 40 | String token = (String) request.getSession().getAttribute(KAPTCHA_SESSION_KEY); 41 | request.getSession().removeAttribute(KAPTCHA_SESSION_KEY); 42 | //获取请求的参数 43 | String username = request.getParameter("username"); 44 | String password = request.getParameter("password"); 45 | String email = request.getParameter("email"); 46 | String code = request.getParameter("code"); 47 | 48 | User user = WebUtils.copyParamToBean(request.getParameterMap(), new User()); 49 | //检查验证码是否正确 50 | if (token != null && token.equalsIgnoreCase(code)) { 51 | //检查用户名是否可用 52 | if (userService.existUsername(username)) { 53 | System.out.println("用户名已存在"); 54 | request.setAttribute("msg", "用户名已存在"); 55 | request.setAttribute("username", username); 56 | request.setAttribute("email", email); 57 | 58 | request.getRequestDispatcher("/pages/user/regist.jsp").forward(request, response); 59 | } else { 60 | userService.registerUser(new User(null, username, password, email)); 61 | 62 | request.getRequestDispatcher("/pages/user/regist_success.jsp").forward(request, response); 63 | } 64 | } else { 65 | //跳回注册页面 66 | request.setAttribute("msg", "验证码错误"); 67 | request.setAttribute("username", username); 68 | request.setAttribute("email", email); 69 | System.out.println("验证码错误"); 70 | request.getRequestDispatcher("/pages/user/regist.jsp").forward(request, response); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /book/web/WEB-INF/lib/commons-beanutils-1.8.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SawyerRen/Library/c9fc20afe794061b4931733f842ef2ca8c1bc57b/book/web/WEB-INF/lib/commons-beanutils-1.8.0.jar -------------------------------------------------------------------------------- /book/web/WEB-INF/lib/commons-dbutils-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SawyerRen/Library/c9fc20afe794061b4931733f842ef2ca8c1bc57b/book/web/WEB-INF/lib/commons-dbutils-1.3.jar -------------------------------------------------------------------------------- /book/web/WEB-INF/lib/commons-logging-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SawyerRen/Library/c9fc20afe794061b4931733f842ef2ca8c1bc57b/book/web/WEB-INF/lib/commons-logging-1.1.1.jar -------------------------------------------------------------------------------- /book/web/WEB-INF/lib/druid-1.1.9.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SawyerRen/Library/c9fc20afe794061b4931733f842ef2ca8c1bc57b/book/web/WEB-INF/lib/druid-1.1.9.jar -------------------------------------------------------------------------------- /book/web/WEB-INF/lib/hamcrest-core-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SawyerRen/Library/c9fc20afe794061b4931733f842ef2ca8c1bc57b/book/web/WEB-INF/lib/hamcrest-core-1.3.jar -------------------------------------------------------------------------------- /book/web/WEB-INF/lib/junit-4.12.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SawyerRen/Library/c9fc20afe794061b4931733f842ef2ca8c1bc57b/book/web/WEB-INF/lib/junit-4.12.jar -------------------------------------------------------------------------------- /book/web/WEB-INF/lib/kaptcha-2.3.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SawyerRen/Library/c9fc20afe794061b4931733f842ef2ca8c1bc57b/book/web/WEB-INF/lib/kaptcha-2.3.2.jar -------------------------------------------------------------------------------- /book/web/WEB-INF/lib/mysql-connector-java-5.1.7-bin.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SawyerRen/Library/c9fc20afe794061b4931733f842ef2ca8c1bc57b/book/web/WEB-INF/lib/mysql-connector-java-5.1.7-bin.jar -------------------------------------------------------------------------------- /book/web/WEB-INF/lib/taglibs-standard-impl-1.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SawyerRen/Library/c9fc20afe794061b4931733f842ef2ca8c1bc57b/book/web/WEB-INF/lib/taglibs-standard-impl-1.2.1.jar -------------------------------------------------------------------------------- /book/web/WEB-INF/lib/taglibs-standard-spec-1.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SawyerRen/Library/c9fc20afe794061b4931733f842ef2ca8c1bc57b/book/web/WEB-INF/lib/taglibs-standard-spec-1.2.1.jar -------------------------------------------------------------------------------- /book/web/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | ManagerFilter 8 | filter.ManagerFilter 9 | 10 | 11 | ManagerFilter 12 | /pages/manager/* 13 | /manager/bookServlet 14 | 15 | 16 | TransactionFilter 17 | filter.TransactionFilter 18 | 19 | 20 | TransactionFilter 21 | /* 22 | 23 | 24 | 25 | UserServlet 26 | web.UserServlet 27 | 28 | 29 | 30 | UserServlet 31 | /userServlet 32 | 33 | 34 | 35 | BookServlet 36 | web.BookServlet 37 | 38 | 39 | 40 | BookServlet 41 | /manager/bookServlet 42 | 43 | 44 | ClientBookServlet 45 | web.ClientBookServlet 46 | 47 | 48 | 49 | ClientBookServlet 50 | /client/bookServlet 51 | 52 | 53 | 54 | KaptchaServlet 55 | com.google.code.kaptcha.servlet.KaptchaServlet 56 | 57 | 58 | 59 | KaptchaServlet 60 | /kaptcha.jpg 61 | 62 | 63 | CartServlet 64 | web.CartServlet 65 | 66 | 67 | 68 | CartServlet 69 | /cartServlet 70 | 71 | 72 | 73 | OrderServlet 74 | web.OrderServlet 75 | 76 | 77 | 78 | OrderServlet 79 | /orderServlet 80 | 81 | 82 | 83 | 500 84 | /pages/error/error500.jsp 85 | 86 | 87 | -------------------------------------------------------------------------------- /book/web/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | -------------------------------------------------------------------------------- /book/web/pages/cart/cart.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 8 | 购物车 9 | <%@include file="/pages/common/head.jsp" %> 10 | 31 | 32 | 33 | 34 | 39 | 40 |
41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 66 | 67 | 68 | 71 | 72 | 73 | 74 |
商品名称数量单价金额操作
购物车为空
${entry.value.name} 64 | 65 | ${entry.value.price}${entry.value.totalPrice}删除 70 |
75 | 76 |
77 | 购物车中共有${sessionScope.cart.totalCount}件商品 78 | 总金额${sessionScope.cart.totalPrice} 79 | 清空购物车 80 | 去结账 81 |
82 |
83 |
84 | 85 | <%@include file="/pages/common/foot.jsp" %> 86 | > 87 | 88 | -------------------------------------------------------------------------------- /book/web/pages/cart/checkout.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 5 | 6 | 7 | 结算页面 8 | <%@include file="/pages/common/head.jsp"%> 9 | 15 | 16 | 17 | 18 | 23 | 24 |
25 | 26 |

你的订单已结算,订单号为2937474382928484747

27 | 28 | 29 |
30 | 31 | <%@include file="/pages/common/foot.jsp"%>> 32 | 33 | -------------------------------------------------------------------------------- /book/web/pages/client/client_index.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 书城首页 8 | <%@include file="/pages/common/head.jsp" %> 9 | 17 | 18 | 19 | 20 | 38 |
39 |
40 |
41 |
42 | 43 | 价格: 元 - 44 | 元 45 | 46 |
47 |
48 |
49 | 您的购物车中有${sessionScope.cart.totalCount}件商品 50 |
51 | 您刚刚将${sessionScope.lastName}加入到了购物车中 52 |
53 |
54 | 55 | 56 |
57 |
58 | 59 |
60 |
61 |
62 | 书名: 63 | ${book.name} 64 |
65 |
66 | 作者: 67 | ${book.author} 68 |
69 |
70 | 价格: 71 | ${book.price} 72 |
73 |
74 | 销量: 75 | ${book.sales} 76 |
77 |
78 | 库存: 79 | ${book.stock} 80 |
81 |
82 | 83 |
84 |
85 |
86 |
87 | 88 | 89 |
90 | 91 | <%@include file="/pages/common/page_nav.jsp"%> 92 |
93 | 94 | <%@include file="/pages/common/foot.jsp" %> 95 | > 96 | 97 | -------------------------------------------------------------------------------- /book/web/pages/common/foot.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: SawyerRen 4 | Date: 2020/3/26 5 | Time: 9:37 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 |
10 | 11 | 尚硅谷书城.Copyright ©2015 12 | 13 |
14 | -------------------------------------------------------------------------------- /book/web/pages/common/head.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: SawyerRen 4 | Date: 2020/3/26 5 | Time: 9:25 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /book/web/pages/common/login_success_menu.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: SawyerRen 4 | Date: 2020/3/26 5 | Time: 9:20 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 |
11 | 欢迎${sessionScope.user.username}光临尚硅谷书城 12 | 我的订单 13 | 注销   14 | 返回 15 |
16 | 17 | -------------------------------------------------------------------------------- /book/web/pages/common/manager_menu.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: SawyerRen 4 | Date: 2020/3/26 5 | Time: 9:42 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 |
11 | 图书管理 12 | 订单管理 13 | 返回商城 14 |
15 | -------------------------------------------------------------------------------- /book/web/pages/common/page_nav.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: SawyerRen 4 | Date: 2020/3/27 5 | Time: 13:48 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 80 | 81 | -------------------------------------------------------------------------------- /book/web/pages/error/error500.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 书城首页 8 | <%@include file="/pages/common/head.jsp" %> 9 | 10 | 11 | 抱歉,后台程序出现问题,正在抢修。
12 | 返回首页 13 | 14 | -------------------------------------------------------------------------------- /book/web/pages/manager/book_edit.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 5 | 6 | 7 | 编辑图书 8 | <%@include file="/pages/common/head.jsp"%> 9 | 23 | 24 | 25 | 31 | 32 |
33 |
34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 |
名称价格作者销量库存操作
55 |
56 | 57 | 58 |
59 | 60 | <%@include file="/pages/common/foot.jsp"%>> 61 | 62 | -------------------------------------------------------------------------------- /book/web/pages/manager/book_manager.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 8 | 图书管理 9 | <%@include file="/pages/common/head.jsp" %> 10 | 17 | 18 | 19 | 20 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 45 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
名称价格作者销量库存操作
${book.name}${book.price}${book.author}${book.sales}${book.stock}修改 44 | 删除 47 |
添加图书
60 | <%@include file="/pages/common/page_nav.jsp"%> 61 |
62 | 63 | <%@include file="/pages/common/foot.jsp" %> 64 | > 65 | 66 | -------------------------------------------------------------------------------- /book/web/pages/manager/manager.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 5 | 6 | 7 | 后台管理 8 | <%@include file="/pages/common/head.jsp"%> 9 | 15 | 16 | 17 | 18 | 23 | 24 |
25 |

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

26 |
27 | 28 | <%@include file="/pages/common/foot.jsp"%>> 29 | 30 | -------------------------------------------------------------------------------- /book/web/pages/manager/order_manager.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 5 | 6 | 7 | 订单管理 8 | <%@include file="/pages/common/head.jsp" %> 9 | 10 | 11 | 12 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |
日期金额详情发货
2015.04.2390.00查看详情点击发货
2015.04.2020.00查看详情已发货
2014.01.23190.00查看详情等待收货
48 |
49 | 50 | <%@include file="/pages/common/foot.jsp" %> 51 | > 52 | 53 | -------------------------------------------------------------------------------- /book/web/pages/order/order.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 5 | 6 | 7 | 我的订单 8 | <%@include file="/pages/common/head.jsp"%> 9 | 15 | 16 | 17 | 18 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
日期金额状态详情
2015.04.2390.00未发货查看详情
2015.04.2020.00已发货查看详情
2014.01.23190.00已完成查看详情
54 | 55 | 56 |
57 | 58 | <%@include file="/pages/common/foot.jsp"%>> 59 | 60 | -------------------------------------------------------------------------------- /book/web/pages/user/login.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 5 | 6 | 7 | 尚硅谷会员登录页面 8 | <%@include file="/pages/common/head.jsp" %> 9 | 10 | 11 |
12 | 13 |
14 | 15 | 56 | <%@include file="/pages/common/foot.jsp" %> 57 | > 58 | 59 | -------------------------------------------------------------------------------- /book/web/pages/user/login_success.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 5 | 6 | 7 | 尚硅谷会员注册页面 8 | <%@include file="/pages/common/head.jsp"%> 9 | 19 | 20 | 21 | 25 | 26 |
27 | 28 |

欢迎回来 转到主页

29 | 30 |
31 | 32 | <%@include file="/pages/common/foot.jsp"%>> 33 | 34 | -------------------------------------------------------------------------------- /book/web/pages/user/regist.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 5 | 6 | 7 | 尚硅谷会员注册页面 8 | <%@include file="/pages/common/head.jsp"%> 9 | 50 | 57 | 58 | 59 |
60 | 61 |
62 | 63 | 119 | <%@include file="/pages/common/foot.jsp"%>> 120 | 121 | -------------------------------------------------------------------------------- /book/web/pages/user/regist_success.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 5 | 6 | 7 | 尚硅谷会员注册页面 8 | <%@include file="/pages/common/head.jsp"%> 9 | 19 | 20 | 21 | 26 | 27 |
28 | 29 |

注册成功! 转到主页

30 | 31 |
32 | 33 | <%@include file="/pages/common/foot.jsp"%>> 34 | 35 | -------------------------------------------------------------------------------- /book/web/static/css/style.css: -------------------------------------------------------------------------------- 1 | @CHARSET "UTF-8"; 2 | 3 | body { 4 | overflow: hidden; 5 | } 6 | 7 | * { 8 | margin: 0; 9 | font-family:"Microsoft Yahei"; 10 | color: #666; 11 | } 12 | 13 | div{ 14 | margin: auto; 15 | margin-bottom: 10px; 16 | margin-top: 10px; 17 | 18 | } 19 | 20 | #header { 21 | height: 82px; 22 | width: 1200px; 23 | } 24 | 25 | #main { 26 | height: 460px; 27 | width: 1200px; 28 | border: 1px black solid; 29 | overflow: auto; 30 | } 31 | 32 | #bottom { 33 | height: 30px; 34 | width: 1200px; 35 | text-align: center; 36 | } 37 | 38 | #book{ 39 | width: 100%; 40 | height: 90%; 41 | margin: auto; 42 | 43 | } 44 | 45 | .b_list{ 46 | height:300px; 47 | width:250px; 48 | margin: 20px; 49 | float: left; 50 | margin-top:0px; 51 | margin-bottom:0px; 52 | border: 1px #e3e3e3 solid; 53 | } 54 | 55 | #page_nav{ 56 | width: 100%; 57 | height: 10px; 58 | margin: auto; 59 | 60 | text-align: center; 61 | } 62 | 63 | #pn_input { 64 | width: 30px; 65 | text-align: center; 66 | } 67 | 68 | .img_div{ 69 | height: 150px; 70 | text-align: center; 71 | } 72 | 73 | .book_img { 74 | height:150px; 75 | width:150px; 76 | } 77 | 78 | .book_info { 79 | 80 | text-align: center; 81 | } 82 | 83 | .book_info div{ 84 | height: 10px; 85 | width: 300px; 86 | text-align: left; 87 | } 88 | 89 | .wel_word{ 90 | font-size: 60px; 91 | float: left; 92 | } 93 | 94 | .logo_img{ 95 | float: left; 96 | } 97 | 98 | #header div a { 99 | text-decoration: none; 100 | font-size: 20px; 101 | } 102 | 103 | #header div{ 104 | float: right; 105 | margin-top: 55px; 106 | } 107 | 108 | .book_cond{ 109 | margin-left: 500px; 110 | } 111 | 112 | .book_cond input{ 113 | width: 50px; 114 | text-align: center; 115 | } 116 | 117 | 118 | /*登录页面CSS样式 */ 119 | 120 | #login_header{ 121 | height: 82px; 122 | width: 1200px; 123 | } 124 | 125 | .login_banner{ 126 | height:475px; 127 | background-color: #39987c; 128 | } 129 | 130 | .login_form{ 131 | height:310px; 132 | width:406px; 133 | float: right; 134 | margin-right:50px; 135 | margin-top: 50px; 136 | background-color: #fff; 137 | } 138 | 139 | #content { 140 | height: 475px; 141 | width: 1200px; 142 | } 143 | 144 | .login_box{ 145 | margin: 20px; 146 | height: 260px; 147 | width: 366px; 148 | } 149 | 150 | h1 { 151 | font-size: 20px; 152 | } 153 | .msg_cont{ 154 | background: none repeat scroll 0 0 #fff6d2; 155 | border: 1px solid #ffe57d; 156 | color: #666; 157 | height: 18px; 158 | line-height: 18px; 159 | padding: 3px 10px 3px 40px; 160 | position: relative; 161 | border: none; 162 | } 163 | 164 | .msg_cont b { 165 | background: url("../img/pwd-icons-new.png") no-repeat scroll -104px -22px rgba(0, 0, 0, 0); 166 | display: block; 167 | height: 17px; 168 | left: 10px; 169 | margin-top: -8px; 170 | overflow: hidden; 171 | position: absolute; 172 | top: 50%; 173 | width: 16px; 174 | } 175 | 176 | .form .itxt { 177 | border: 0 none; 178 | float: none; 179 | font-family: "宋体"; 180 | font-size: 14px; 181 | height: 18px; 182 | line-height: 18px; 183 | overflow: hidden; 184 | padding: 10px 0 10px 10px; 185 | width: 220px; 186 | border: 1px #e3e3e3 solid; 187 | } 188 | 189 | #sub_btn{ 190 | background-color: #39987c; 191 | border: none; 192 | color: #fff; 193 | width: 360px; 194 | height: 40px; 195 | } 196 | 197 | #l_content { 198 | float: left; 199 | margin-top: 150px; 200 | margin-left: 300px; 201 | } 202 | 203 | #l_content span { 204 | font-size: 60px; 205 | color: white; 206 | } 207 | 208 | .tit h1 { 209 | float: left; 210 | margin-top: 5px; 211 | } 212 | 213 | .tit a { 214 | float: right; 215 | margin-left: 10px; 216 | margin-top: 10px; 217 | color: red; 218 | text-decoration: none; 219 | } 220 | 221 | .tit .errorMsg { 222 | float: right; 223 | margin-left: 10px; 224 | margin-top: 10px; 225 | color: red; 226 | } 227 | 228 | .tit { 229 | height: 30px; 230 | } 231 | /*购物车*/ 232 | #main table{ 233 | margin: auto; 234 | margin-top: 80px; 235 | border-collapse: collapse; 236 | } 237 | 238 | #main table td{ 239 | width: 120px; 240 | text-align:center; 241 | border-bottom: 1px #e3e3e3 solid; 242 | padding: 10px; 243 | } 244 | 245 | .cart_info{ 246 | width: 700px; 247 | text-align: right; 248 | } 249 | 250 | .cart_span { 251 | margin-left: 20px; 252 | } 253 | 254 | .cart_span span{ 255 | color: red; 256 | font-size: 20px; 257 | margin: 10px; 258 | } 259 | 260 | .cart_span a , td a{ 261 | font-size: 20px; 262 | color: blue; 263 | } 264 | 265 | #header div span { 266 | margin: 10px; 267 | } 268 | 269 | #header div .um_span{ 270 | color: red; 271 | font-size: 25px; 272 | margin: 10px; 273 | } 274 | 275 | #header div a { 276 | color: blue; 277 | } 278 | -------------------------------------------------------------------------------- /book/web/static/img/code.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SawyerRen/Library/c9fc20afe794061b4931733f842ef2ca8c1bc57b/book/web/static/img/code.bmp -------------------------------------------------------------------------------- /book/web/static/img/default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SawyerRen/Library/c9fc20afe794061b4931733f842ef2ca8c1bc57b/book/web/static/img/default.jpg -------------------------------------------------------------------------------- /book/web/static/img/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SawyerRen/Library/c9fc20afe794061b4931733f842ef2ca8c1bc57b/book/web/static/img/logo.gif -------------------------------------------------------------------------------- /book/web/static/img/pwd-icons-new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SawyerRen/Library/c9fc20afe794061b4931733f842ef2ca8c1bc57b/book/web/static/img/pwd-icons-new.png --------------------------------------------------------------------------------