基于Springboot的宠物店管理系统(源代码+数据库)087
发布人:shili8
发布时间:2024-11-19 01:55
阅读次数:0
**基于Springboot的宠物店管理系统**
### 系统概述本系统是一个基于Springboot的宠物店管理系统,主要功能包括:
* 宠物信息管理(添加、删除、修改)
* 客户信息管理(添加、删除、修改)
* 订单管理(添加、删除、修改)
* 支付管理(添加、删除、修改)
### 系统设计####1.数据库设计本系统使用MySQL作为数据库,以下是数据库表结构:
sqlCREATE TABLE pet ( id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255) NOT NULL, age INT NOT NULL, type VARCHAR(255) NOT NULL); CREATE TABLE customer ( id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255) NOT NULL, phone VARCHAR(255) NOT NULL, address VARCHAR(255) NOT NULL); CREATE TABLE order_info ( id INT PRIMARY KEY AUTO_INCREMENT, pet_id INT NOT NULL, customer_id INT NOT NULL, order_date DATE NOT NULL, total DECIMAL(10,2) NOT NULL, status VARCHAR(255) NOT NULL, FOREIGN KEY (pet_id) REFERENCES pet(id), FOREIGN KEY (customer_id) REFERENCES customer(id) ); CREATE TABLE payment ( id INT PRIMARY KEY AUTO_INCREMENT, order_id INT NOT NULL, amount DECIMAL(10,2) NOT NULL, pay_date DATE NOT NULL, status VARCHAR(255) NOT NULL, FOREIGN KEY (order_id) REFERENCES order_info(id) );
####2.系统模块设计本系统分为以下几个模块:
* **PetController**:负责宠物信息的添加、删除、修改* **CustomerController**:负责客户信息的添加、删除、修改* **OrderController**:负责订单管理的添加、删除、修改* **PaymentController**:负责支付管理的添加、删除、修改### 系统实现####1.宠物信息管理**PetController.java**
java@RestController@RequestMapping("/pet") public class PetController { @Autowired private PetService petService; @GetMapping public ListgetAllPets() { return petService.getAllPets(); } @PostMapping public void addPet(@RequestBody Pet pet) { petService.addPet(pet); } @DeleteMapping("/{id}") public void deletePet(@PathVariable Long id) { petService.deletePet(id); } @PutMapping("/{id}") public void updatePet(@PathVariable Long id, @RequestBody Pet pet) { petService.updatePet(id, pet); } }
**PetService.java**
java@Servicepublic class PetService { @Autowired private PetRepository petRepository; public ListgetAllPets() { return petRepository.findAll(); } public void addPet(Pet pet) { petRepository.save(pet); } public void deletePet(Long id) { petRepository.deleteById(id); } public void updatePet(Long id, Pet pet) { Pet existingPet = petRepository.findById(id).orElse(null); if (existingPet != null) { existingPet.setName(pet.getName()); existingPet.setAge(pet.getAge()); existingPet.setType(pet.getType()); petRepository.save(existingPet); } } }
####2.客户信息管理**CustomerController.java**
java@RestController@RequestMapping("/customer") public class CustomerController { @Autowired private CustomerService customerService; @GetMapping public ListgetAllCustomers() { return customerService.getAllCustomers(); } @PostMapping public void addCustomer(@RequestBody Customer customer) { customerService.addCustomer(customer); } @DeleteMapping("/{id}") public void deleteCustomer(@PathVariable Long id) { customerService.deleteCustomer(id); } @PutMapping("/{id}") public void updateCustomer(@PathVariable Long id, @RequestBody Customer customer) { customerService.updateCustomer(id, customer); } }
**CustomerService.java**
java@Servicepublic class CustomerService { @Autowired private CustomerRepository customerRepository; public ListgetAllCustomers() { return customerRepository.findAll(); } public void addCustomer(Customer customer) { customerRepository.save(customer); } public void deleteCustomer(Long id) { customerRepository.deleteById(id); } public void updateCustomer(Long id, Customer customer) { Customer existingCustomer = customerRepository.findById(id).orElse(null); if (existingCustomer != null) { existingCustomer.setName(customer.getName()); existingCustomer.setPhone(customer.getPhone()); existingCustomer.setAddress(customer.getAddress()); customerRepository.save(existingCustomer); } } }
####3.订单管理**OrderController.java**
java@RestController@RequestMapping("/order") public class OrderController { @Autowired private OrderService orderService; @GetMapping public ListgetAllOrders() { return orderService.getAllOrders(); } @PostMapping public void addOrder(@RequestBody OrderInfo order) { orderService.addOrder(order); } @DeleteMapping("/{id}") public void deleteOrder(@PathVariable Long id) { orderService.deleteOrder(id); } @PutMapping("/{id}") public void updateOrder(@PathVariable Long id, @RequestBody OrderInfo order) { orderService.updateOrder(id, order); } }
**OrderService.java**
java@Servicepublic class OrderService { @Autowired private OrderRepository orderRepository; public ListgetAllOrders() { return orderRepository.findAll(); } public void addOrder(OrderInfo order) { orderRepository.save(order); } public void deleteOrder(Long id) { orderRepository.deleteById(id); } public void updateOrder(Long id, OrderInfo order) { OrderInfo existingOrder = orderRepository.findById(id).orElse(null); if (existingOrder != null) { existingOrder.setPetId(order.getPetId()); existingOrder.setCustomerId(order.getCustomerId()); existingOrder.setOrderDate(order.getOrderDate()); existingOrder.setTotal(order.getTotal()); existingOrder.setStatus(order.getStatus()); orderRepository.save(existingOrder); } } }
####4.支付管理**PaymentController.java**
java@RestController@RequestMapping("/payment") public class PaymentController { @Autowired private PaymentService paymentService; @GetMapping public ListgetAllPayments() { return paymentService.getAllPayments(); } @PostMapping public void addPayment(@RequestBody Payment payment) { paymentService.addPayment(payment); } @DeleteMapping("/{id}") public void deletePayment(@PathVariable Long id) { paymentService.deletePayment(id); } @PutMapping("/{id}") public void updatePayment(@PathVariable Long id, @RequestBody Payment payment) { paymentService.updatePayment(id, payment); } }
**PaymentService.java**
java@Servicepublic class PaymentService { @Autowired private PaymentRepository paymentRepository; public ListgetAllPayments() { return paymentRepository.findAll(); } public void addPayment(Payment payment) { paymentRepository.save(payment); } public void deletePayment(Long id) { paymentRepository.deleteById(id); } public void updatePayment(Long id, Payment payment) { Payment existingPayment = paymentRepository.findById(id).orElse(null); if (existingPayment != null) { existingPayment.setOrderId(payment.getOrderId()); existingPayment.setAmount(payment.getAmount()); existingPayment.setPayDate(payment.getPayDate()); existingPayment.setStatus(payment.getStatus()); paymentRepository.save(existingPayment); } } }
### 系统测试####1.宠物信息管理* **添加宠物**:使用Postman发送POST请求到`/pet`端点,传递JSON数据 `{ "name": "Tom", "age":2, "type": "dog" }`
* **删除宠物**:使用Postman发送DELETE请求到`/pet/{id}`端点,传递宠物ID* **修改宠物**:使用Postman发送PUT请求到`/pet/{id}`端点,传递JSON数据 `{ "name": "Tom", "age":3, "type": "dog" }`
####2.客户信息管理* **添加客户**:使用Postman发送POST请求到`/customer`端点,传递JSON数据 `{ "name": "John", "phone": "1234567890", "address": "New York" }`
* **删除客户**:使用Postman发送DELETE请求到`/customer/{id}`端点,传递客户ID* **修改客户**:使用Postman发送PUT请求到`/customer/{id}`端点,传递JSON数据 `{ "name": "John", "phone": "1234567891", "address": "New York" }`
####3.订单管理* **添加订单**:使用Postman发送POST请求到`/order