在哪里创建网站平台,网站建设后续的费用,万网 网站模板,客户关系管理名词解释目录
1 实验内容
2 实验要求
3 思路
4 核心代码
5 实验结果 1 实验内容
简单的线上图书交易系统的web层
2 实验要求
①采用SpringMVC框架#xff0c;采用REST风格
②要求具有如下功能#xff1a;商品分类、订单、购物车、库存
③独立完成#xff0c;编写实验报告 …目录
1 实验内容
2 实验要求
3 思路
4 核心代码
5 实验结果 1 实验内容
简单的线上图书交易系统的web层
2 实验要求
①采用SpringMVC框架采用REST风格
②要求具有如下功能商品分类、订单、购物车、库存
③独立完成编写实验报告
3 思路
①确保项目结构清晰按照MVC的结构进行组织
②在pom.xml中添加SpringMVC相关依赖以及其他可能需要的依赖比如数据库连接池、模板引擎等
③配置web.xml文件配置DispatcherServlet和Spring监听器
④在WEB-INF目录下创建相关文件配置相关内容
⑤在com.exp.controller包下创建控制器类使用RestController注解以REST风格暴露接口
⑥创建JSP文件用于显示前端页面。
4 核心代码
①BookController类
RestControllerRequestMapping(/books)public class BookController { Autowired private BookService bookService; GetMapping public ListBook getAllBooks() { return bookService.getAllBooks(); } GetMapping(/{id}) public Book getBookById(PathVariable Long id) { return bookService.getBookById(id); } PostMapping public void addBook(RequestBody Book book) { bookService.addBook(book); } PutMapping(/{id}) public void updateBook(PathVariable Long id, RequestBody Book book) { book.setId(id); bookService.updateBook(book); } DeleteMapping(/{id}) public void deleteBook(PathVariable Long id) { bookService.deleteBook(id); }}
②OrderController类
RestControllerRequestMapping(/orders)public class OrderController { Autowired private OrderService orderService; GetMapping public ListOrder getAllOrders() { return orderService.getAllOrders(); } GetMapping(/{id}) public Order getOrderById(PathVariable Long id) { return orderService.getOrderById(id); } PostMapping public void addOrder(RequestBody Order order) { orderService.addOrder(order); } PutMapping(/{id}) public void updateOrder(PathVariable Long id, RequestBody Order order) { order.setId(id); orderService.updateOrder(order); } DeleteMapping(/{id}) public void deleteOrder(PathVariable Long id) { orderService.deleteOrder(id); }}
③CartController类
RestControllerRequestMapping(/cart)public class CartController { Autowired private CartService cartService; GetMapping(/{userId}) public ListCartItem getCartItemsByUserId(PathVariable Long userId) { return cartService.getCartItemsByUserId(userId); } PostMapping public void addCartItem(RequestBody CartItem cartItem) { cartService.addCartItem(cartItem); } PutMapping(/{id}) public void updateCartItem(PathVariable Long id, RequestBody CartItem cartItem) { cartItem.setId(id); cartService.updateCartItem(cartItem); } DeleteMapping(/{id}) public void deleteCartItem(PathVariable Long id) { cartService.deleteCartItem(id); }}
④InventoryController类
RestControllerRequestMapping(/inventory)public class InventoryController { Autowired private InventoryService inventoryService; GetMapping(/{bookId}) public Inventory getInventoryByBookId(PathVariable Long bookId) { return inventoryService.getInventoryByBookId(bookId); } PostMapping public void addInventory(RequestBody Inventory inventory) { inventoryService.addInventory(inventory); } PutMapping(/{id}) public void updateInventory(PathVariable Long id, RequestBody Inventory inventory) { inventory.setId(id); inventoryService.updateInventory(inventory); } DeleteMapping(/{id}) public void deleteInventory(PathVariable Long id) { inventoryService.deleteInventory(id); }}
5 实验结果
①购物车界面 ②库存界面 ③订单界面 ④商品书籍界面