作者主页:夜未央5788
项目介绍
基于springboot的物流管理系统,这个项目的技术使用的都是比较新的,代码写的架构设计、编码风格很规范、注释清洗、代码简洁、适合于二次开发、学习。
管理员角色:注册、登录、我的物流,可以创建我要寄件,可以查看我要收件。个人管理,个人信息的查看和修改(头像、用户名、账号、密码、电话、邮箱等属性)、我收到的(展示收到的物流信息,如快递编号、寄件人、存放位置、订单时间、状态等)、我寄出的(可以自行修改订单的状态,未寄出、已寄出、已签收等)。后台管理:物流管理和用户管理。
普通用户:注册、登录、我的物流,可以创建我要寄件,可以查看我要收件。个人管理,个人信息的查看和修改(头像、用户名、账号、密码、电话、邮箱等属性)、我收到的(展示收到的物流信息,如快递编号、寄件人、存放位置、订单时间、状态等)、我寄出的(可以自行修改订单的状态,未寄出、已寄出、已签收等)。
使用人群:
正在做毕设的学生,或者需要项目实战练习的Java学习者
由于本程序规模不大,可供课程设计,毕业设计学习演示之
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 8.0/5.7版本;
6.是否Maven项目:是;
技术栈
1.后端:SpringBoot+Mysql+redis+Mybatis-plus
2.前端:Thymeleaf+jquery+layui
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,在浏览器中输入http://localhost:8080 访问
5. 管理员用户名密码:admin/admin,普通用户名密码:user/123456
运行截图
相关代码
管理端控制器
@Controller
public class adminController {
@Autowired
PostService postService;
@Autowired
CategoryService categoryService;
@Autowired
PositionService positionService;
@Autowired
OrdersService ordersService;
@Autowired
UserService userService;
//寄件管理
@GetMapping("/toAdminSend")
public String toAdminSend(@RequestParam(required = false, defaultValue = "1", value = "pageNum") int pageNum, HttpSession session, Model model, RedirectAttributes attributes) {
User userInfo = (User) session.getAttribute("user");
if (userInfo != null) {
PageHelper.startPage(pageNum, 6);
List<Post> postList = postService.findAllPost();
PageInfo<Post> pageInfo = new PageInfo<>(postList);
model.addAttribute("postList", postList);
model.addAttribute("pageInfo", pageInfo);
List<Category> categoryList = categoryService.list();
model.addAttribute("categoryList", categoryList);
return "adminSend";
} else {
attributes.addFlashAttribute("message", "权限不足,请先登录");
return "redirect:/toLogin";
}
}
@GetMapping("adminSendPost/{id}")
public String adminSendPost(@PathVariable Integer id) {
postService.updatePostStatusTo1(id, new Date());
return "redirect:/toAdminSend";
}
@PostMapping("/searchPost")
public String searchPost(Post post, @RequestParam(required = false, defaultValue = "1", value = "pageNum") int pageNum, Model model) {
PageHelper.startPage(pageNum, 6);
List<Post> postList = postService.findPostBySearch(post);
PageInfo<Post> pageInfo = new PageInfo<>(postList);
List<Category> categoryList = categoryService.list();
model.addAttribute("categoryList", categoryList);
model.addAttribute("postList", postList);
model.addAttribute("pageInfo", pageInfo);
return "adminSend";
}
//收件管理
@GetMapping("adminPickUpPost/{id}")
public String adminPickUpPost(@PathVariable Integer id, Model model) {
Post post = postService.findById(id);
model.addAttribute("post", post);
QueryWrapper<Position> status0 = new QueryWrapper<Position>().eq("status", 0);
List<Position> positionList = positionService.list(status0);
model.addAttribute("positionList", positionList);
return "adminPickUp";
}
// @GetMapping("/toAdminPickUp")
// public String toAdminPickUp(Model model, RedirectAttributes attributes, HttpSession session) {
// User userInfo = (User) session.getAttribute("user");
// if (userInfo != null) {
// QueryWrapper<Position> status0 = new QueryWrapper<Position>().eq("status", 0);
// List<Position> positionList = positionService.list(status0);
// model.addAttribute("positionList", positionList);
// return "adminPickUp";
// } else {
// attributes.addFlashAttribute("message", "权限不足,请先登录");
// return "redirect:/toLogin";
// }
// }
@PostMapping("/adminPickUpOrders")
public String adminPickUpOrders(@RequestParam String num, @RequestParam String name, @RequestParam String sendName, @RequestParam Integer id, @RequestParam Integer positionId,RedirectAttributes attributes) {
QueryWrapper<User> userName = new QueryWrapper<User>().eq("name", name);
try {
User user = userService.getOne(userName);
if (user==null) {
attributes.addFlashAttribute("message", "收件人有误,请注册后邮寄");
}
Orders orders = new Orders();
orders.setUserId(user.getId());
orders.setSendName(sendName);
orders.setPositionId(positionId);
orders.setCreateTime(new Date());
orders.setUpdateTime(new Date());
orders.setNum(num);
ordersService.save(orders);
}catch (NullPointerException e) {
e.printStackTrace();
}
//柜子状态变为1
Position position = positionService.getById(positionId);
position.setStatus(1);
positionService.updateById(position);
//post状态变为2
postService.updatePostStatusTo2(id, new Date());
return "redirect:/toAdminSend";
}
//用户管理
@GetMapping("/toAdminUser")
public String toAdminUser(@RequestParam(required = false, defaultValue = "1", value = "pageNum") int pageNum, HttpSession session, Model model, RedirectAttributes attributes) {
User userInfo = (User) session.getAttribute("user");
if (userInfo != null) {
PageHelper.startPage(pageNum, 6);
List<User> userList = userService.list();
PageInfo<User> pageInfo = new PageInfo<>(userList);
model.addAttribute("userList", userList);
model.addAttribute("pageInfo", pageInfo);
return "adminUser";
} else {
attributes.addFlashAttribute("message", "权限不足,请先登录");
return "redirect:/toLogin";
}
}
@GetMapping("/adminUserTo1/{id}")
public String adminUserTo1(@PathVariable Integer id, HttpSession session) {
User user = userService.getById(id);
user.setRole(1);
userService.updateById(user);
User userInfo = (User) session.getAttribute("user");
if (id == userInfo.getId()) {
session.setAttribute("user", user);
return "index";
}
return "redirect:/toAdminUser";
}
@GetMapping("/adminUserTo0/{id}")
public String adminUserTo0(@PathVariable Integer id) {
User user = userService.getById(id);
user.setRole(0);
userService.updateById(user);
return "redirect:/toAdminUser";
}
}
登录控制器
@Controller
public class LoginController {
@Autowired
UserService userService;
@GetMapping("/toLogin")
public String toLogin(){
return "login";
}
@PostMapping("/userLogin")
public String login(@RequestParam String username, @RequestParam String password,
HttpSession session, RedirectAttributes attributes) {
QueryWrapper<User> wrapper = new QueryWrapper<User>().eq("username", username).eq("password", password);
User user = userService.getOne(wrapper);
if (user != null){
session.setAttribute("user",user);
return "redirect:/index";
}else {
attributes.addFlashAttribute("message","用户名或密码错误");
return "redirect:/toLogin";
}
}
@GetMapping("/toRegister")
public String toRegister() {
return "register";
}
@PostMapping("/register")
public String register(User user) {
user.setCreateTime(new Date());
userService.save(user);
return "redirect:/toLogin";
}
@GetMapping("/findUsername")
@ResponseBody
public void findUsername(String username, HttpServletResponse response) throws IOException {
response.setContentType("application/json;charset=utf-8");
QueryWrapper<User> wrapper = new QueryWrapper<User>().eq("username", username);
User userInfo = userService.getOne(wrapper);
Map<String, Object> map = new HashMap<>();
if (userInfo != null) {
map.put("userExit", true);
map.put("msg", "用户名已存在");
} else {
map.put("userExit", false);
map.put("msg", "正确");
}
//将map转为json,并且传递给客户端
String s = JSON.toJSONString(map);
PrintWriter writer = response.getWriter();
writer.write(s);
writer.close();
}
@GetMapping("/findName")
@ResponseBody
public void findName(String name, HttpServletResponse response) throws IOException {
response.setContentType("application/json;charset=utf-8");
QueryWrapper<User> wrapper = new QueryWrapper<User>().eq("name", name);
User userInfo = userService.getOne(wrapper);
Map<String, Object> map = new HashMap<>();
if (userInfo != null) {
map.put("nameExit", true);
map.put("msg", "用户名已存在");
} else {
map.put("nameExit", false);
map.put("msg", "正确");
}
//将map转为json,并且传递给客户端
String s = JSON.toJSONString(map);
PrintWriter writer = response.getWriter();
writer.write(s);
writer.close();
}
@GetMapping("/logout")
public String logout(HttpSession session){
session.removeAttribute("user");
return "redirect:/toLogin";
}
}