springboot物流管理系统 代码实现部分
时间: 2023-10-12 16:19:50 浏览: 90
Spring Boot 物流管理系统的实现涉及到多个模块,包括用户管理、订单管理、仓库管理、物流管理等。下面我可以给你一个简单的代码实现部分。
1. 用户管理模块
用户管理模块包括用户的登陆、注册、修改密码等功能。以下是一个简单的实现代码:
```java
@Controller
public class UserController {
@Autowired
private UserService userService;
/**
* 跳转到登录页面
*
* @return
*/
@GetMapping(value = "/login")
public String login() {
return "login";
}
/**
* 用户登录
*
* @param username
* @param password
* @param session
* @return
*/
@PostMapping(value = "/login")
public String login(@RequestParam String username,
@RequestParam String password,
HttpSession session) {
User user = userService.login(username, password);
if (user != null) {
session.setAttribute("user", user);
return "redirect:/index";
} else {
return "login";
}
}
/**
* 跳转到注册页面
*
* @return
*/
@GetMapping(value = "/register")
public String register() {
return "register";
}
/**
* 用户注册
*
* @param user
* @return
*/
@PostMapping(value = "/register")
public String register(User user) {
if (userService.register(user)) {
return "login";
} else {
return "register";
}
}
/**
* 用户注销
*
* @param session
* @return
*/
@GetMapping(value = "/logout")
public String logout(HttpSession session) {
session.removeAttribute("user");
return "login";
}
/**
* 跳转到修改密码页面
*
* @return
*/
@GetMapping(value = "/changePassword")
public String changePassword() {
return "changePassword";
}
/**
* 修改密码
*
* @param oldPassword
* @param newPassword
* @param session
* @return
*/
@PostMapping(value = "/changePassword")
public String changePassword(@RequestParam String oldPassword,
@RequestParam String newPassword,
HttpSession session) {
User user = (User) session.getAttribute("user");
if (user != null && user.getPassword().equals(oldPassword)) {
user.setPassword(newPassword);
userService.updateUser(user);
session.removeAttribute("user");
return "login";
} else {
return "changePassword";
}
}
}
```
2. 订单管理模块
订单管理模块包括订单的添加、删除、查询、修改等功能。以下是一个简单的实现代码:
```java
@RestController
@RequestMapping("/order")
public class OrderController {
@Autowired
private OrderService orderService;
/**
* 添加订单
*
* @param order
* @return
*/
@PostMapping(value = "/add")
public Result addOrder(Order order) {
if (orderService.addOrder(order)) {
return Result.success();
} else {
return Result.failure("添加订单失败");
}
}
/**
* 删除订单
*
* @param orderId
* @return
*/
@GetMapping(value = "/delete")
public Result deleteOrder(@RequestParam Long orderId) {
if (orderService.deleteOrder(orderId)) {
return Result.success();
} else {
return Result.failure("删除订单失败");
}
}
/**
* 查询订单
*
* @param orderId
* @return
*/
@GetMapping(value = "/find")
public Result findOrder(@RequestParam Long orderId) {
Order order = orderService.findOrder(orderId);
if (order != null) {
return Result.success(order);
} else {
return Result.failure("查询订单失败");
}
}
/**
* 修改订单
*
* @param order
* @return
*/
@PostMapping(value = "/update")
public Result updateOrder(Order order) {
if (orderService.updateOrder(order)) {
return Result.success();
} else {
return Result.failure("修改订单失败");
}
}
}
```
3. 仓库管理模块
仓库管理模块包括仓库的添加、删除、查询、修改等功能。以下是一个简单的实现代码:
```java
@RestController
@RequestMapping("/warehouse")
public class WarehouseController {
@Autowired
private WarehouseService warehouseService;
/**
* 添加仓库
*
* @param warehouse
* @return
*/
@PostMapping(value = "/add")
public Result addWarehouse(Warehouse warehouse) {
if (warehouseService.addWarehouse(warehouse)) {
return Result.success();
} else {
return Result.failure("添加仓库失败");
}
}
/**
* 删除仓库
*
* @param warehouseId
* @return
*/
@GetMapping(value = "/delete")
public Result deleteWarehouse(@RequestParam Long warehouseId) {
if (warehouseService.deleteWarehouse(warehouseId)) {
return Result.success();
} else {
return Result.failure("删除仓库失败");
}
}
/**
* 查询仓库
*
* @param warehouseId
* @return
*/
@GetMapping(value = "/find")
public Result findWarehouse(@RequestParam Long warehouseId) {
Warehouse warehouse = warehouseService.findWarehouse(warehouseId);
if (warehouse != null) {
return Result.success(warehouse);
} else {
return Result.failure("查询仓库失败");
}
}
/**
* 修改仓库
*
* @param warehouse
* @return
*/
@PostMapping(value = "/update")
public Result updateWarehouse(Warehouse warehouse) {
if (warehouseService.updateWarehouse(warehouse)) {
return Result.success();
} else {
return Result.failure("修改仓库失败");
}
}
}
```
4. 物流管理模块
物流管理模块包括物流的添加、删除、查询、修改等功能。以下是一个简单的实现代码:
```java
@RestController
@RequestMapping("/logistics")
public class LogisticsController {
@Autowired
private LogisticsService logisticsService;
/**
* 添加物流
*
* @param logistics
* @return
*/
@PostMapping(value = "/add")
public Result addLogistics(Logistics logistics) {
if (logisticsService.addLogistics(logistics)) {
return Result.success();
} else {
return Result.failure("添加物流失败");
}
}
/**
* 删除物流
*
* @param logisticsId
* @return
*/
@GetMapping(value = "/delete")
public Result deleteLogistics(@RequestParam Long logisticsId) {
if (logisticsService.deleteLogistics(logisticsId)) {
return Result.success();
} else {
return Result.failure("删除物流失败");
}
}
/**
* 查询物流
*
* @param logisticsId
* @return
*/
@GetMapping(value = "/find")
public Result findLogistics(@RequestParam Long logisticsId) {
Logistics logistics = logisticsService.findLogistics(logisticsId);
if (logistics != null) {
return Result.success(logistics);
} else {
return Result.failure("查询物流失败");
}
}
/**
* 修改物流
*
* @param logistics
* @return
*/
@PostMapping(value = "/update")
public Result updateLogistics(Logistics logistics) {
if (logisticsService.updateLogistics(logistics)) {
return Result.success();
} else {
return Result.failure("修改物流失败");
}
}
}
```
以上就是一个简单的 Spring Boot 物流管理系统的代码实现部分。其中,UserController、OrderController、WarehouseController、LogisticsController 分别对应用户管理、订单管理、仓库管理、物流管理模块。
阅读全文