Java实战项目之校园跑腿管理系统的实现

 更新时间:2022年01月18日 17:07:13   作者:qq_1334611189  
只有理论是不够的,只有在实战中才能获得能力的提升,本篇文章手把手带你用java+Springboot+vue+maven+elementui+mysql实现一个校园跑腿管理系统,大家可以在过程中查缺补漏,提升水平

前端使用的是vue+elementui,这款系统只适合学习巩固SpringBoot+VUE,后面还要在这上面加校园公告、校园零食等功能,后期代码我也会持续更新上去。系统分为管理员和学生、学生是管理员后台添加的两种角色。

运行环境:

后端 jdk1.8、maven3.5/3.6 mysql5.7 idea/eclipse

前端 idea vue-cli node.js 搭建vue环境 webpack3.6.0指定版本

管理员控制层:

@Controller
@RequestMapping(value = "admin")
public class AdminController {
 
    private final UserService userService;
    private final GoodService goodService;
    private final TypeService typeService;
    private final OrderService orderService;
 
    @Autowired
    public AdminController(UserService userService, GoodService goodService, TypeService typeService, OrderService orderService) {
        this.userService = userService;
        this.goodService = goodService;
        this.typeService = typeService;
        this.orderService = orderService;
    }
 
    @RequestMapping(value = "/adminLogin", method = RequestMethod.GET)
    public String getAdminLogin(){
        return "admin/adminLogin";
    }
 
    @RequestMapping(value = "/adminLogin", method = RequestMethod.POST)
    public String postAdminLogin(ModelMap model,
                                 @RequestParam(value = "email", required = false) String email,
                                 @RequestParam(value = "password", required = false) String password,
                                 HttpSession session) {
        User admin = userService.getUserByEmail(email);
        String message;
        if (admin != null){
            String mdsPass = DigestUtils.md5DigestAsHex((password + admin.getCode()).getBytes());
//            if (!mdsPass .equals(admin.getPassword())){
//                message = "用户密码错误!";
//            }
            if (!password .equals(admin.getPassword())){
                message = "用户密码错误!";
            } else if (admin.getRoleId() != 101){
                message = "用户没有权限访问!";
            } else {
                session.setAttribute("admin",admin);
                return "redirect:/admin/adminPage";
            }
        } else {
            message = "用户不存在!";
        }
        model.addAttribute("message", message);
        return "admin/adminLogin";
    }
 
    @RequestMapping(value = "/adminLogout", method = RequestMethod.GET)
    public String adminLogout(@RequestParam(required = false, defaultValue = "false" )String adminLogout, HttpSession session){
        if (adminLogout.equals("true")){
            session.removeAttribute("admin");
        }
//        adminLogout = "false";
        return "redirect:/";
    }
 
    @RequestMapping(value = "/adminPage", method = RequestMethod.GET)
    public String getAdminPage(ModelMap model,
                               HttpSession session){
        User admin = (User) session.getAttribute("admin");
        if (admin == null){
            return "redirect:/admin/adminLogin";
        }
        List<Good> goodList = goodService.getAllGoodList();
        for (Good good : goodList) {
            good.setGoodUser(userService.getUserById(good.getUserId()));
            good.setGoodSecondType(typeService.getSecondTypeById(good.getSecondTypeId()));
        }
        List<User> userList = userService.getAllUser();
        List<FirstType> firstTypeList = typeService.getAllFirstType();
        List<Order> orderList = orderService.getOrderList();
        model.addAttribute("goodList", goodList);
        model.addAttribute("userList", userList);
        model.addAttribute("firstTypeList", firstTypeList);
        model.addAttribute("orderList", orderList);
        return "admin/adminPage";
    }
    @RequestMapping(value = "/user/update/status/{statusId}&{userId}", method = RequestMethod.GET)
    public ResponseEntity updateUserStatus(@PathVariable Integer statusId,
                                            @PathVariable Integer userId){
        Boolean success = userService.updateUserStatus(statusId, userId);
        if (success){
            List<User> userList = userService.getAllUser();
            return ResponseEntity.ok(userList);
        }
        return ResponseEntity.ok(success);
    }
 
    @RequestMapping(value = "/user/delete/{userId}", method = RequestMethod.GET)
    public ResponseEntity deleteUser(@PathVariable Integer userId){
        Boolean success = userService.deleteUser(userId);
        if (success){
            List<User> userList = userService.getAllUser();
            return ResponseEntity.ok(userList);
        }
        return ResponseEntity.ok(success);
    }
 
}

用户控制层:

@Controller
@RequestMapping(value = "user")
public class UserController {
	private final GoodService goodService;
	private final OrderService orderService;
	private final ReviewService reviewService;
	private final UserService userService;
	private final CollectService collectService;
 
	@Autowired
	public UserController(GoodService goodService, OrderService orderService,
			ReviewService reviewService, UserService userService,
			CollectService collectService) {
		this.goodService = goodService;
		this.orderService = orderService;
		this.reviewService = reviewService;
		this.userService = userService;
		this.collectService = collectService;
	}
 
	@RequestMapping(value = "userProfile", method = RequestMethod.GET)
	public String getMyProfile(ModelMap model, HttpSession session) {
		User user = (User) session.getAttribute("user");
		if (user == null) {
			return "redirect:/";
		}
		List<Collect> collects = collectService
				.getCollectByUserId(user.getId());
		for (Collect collect : collects) {
			collect.setGood(goodService.getGoodById(collect.getGoodId()));
		}
		List<Good> goods = goodService.getGoodByUserId(user.getId());
		List<Order> orders = orderService.getOrderByCustomerId(user.getId());
		List<Review> reviews = reviewService.gerReviewByToUserId(user.getId());
		List<Reply> replies = reviewService.gerReplyByToUserId(user.getId());
		List<Order> sellGoods = orderService.getOrderBySellerId(user.getId());
		model.addAttribute("collects", collects);
		model.addAttribute("goods", goods);
		model.addAttribute("orders", orders);
		model.addAttribute("reviews", reviews);
		model.addAttribute("replies", replies);
		model.addAttribute("sellGoods", sellGoods);
		return "user/userProfile";
	}
 
	@RequestMapping(value = "/review", method = RequestMethod.GET)
	public String getReviewInfo(@RequestParam(required = false) Integer goodId,
			@RequestParam(required = false) Integer reviewId) {
		System.out.println("reviewId" + reviewId);
		if (reviewId != null) {
			System.out.println("reviewId" + reviewId);
			if (reviewService.updateReviewStatus(1, reviewId) == 1) {
				return "redirect:/goods/goodInfo?goodId=" + goodId;
			}
		}
		return "redirect:/user/userProfile";
	}
 
	@RequestMapping(value = "/reply", method = RequestMethod.GET)
	public String getReplyInfo(
			@RequestParam(required = false) Integer reviewId,
			@RequestParam(required = false) Integer replyId) {
		if (replyId != null) {
			if (reviewService.updateReplyStatus(1, replyId) == 1) {
				Integer goodId = reviewService.getGoodIdByReviewId(reviewId);
				return "redirect:/goods/goodInfo?goodId=" + goodId;
			}
		}
		return "redirect:/user/userProfile";
	}
 
	@RequestMapping(value = "/userEdit", method = RequestMethod.GET)
	public String getUserEdit(ModelMap model,
			@RequestParam(value = "userId", required = false) Integer userId,
			HttpSession session) {
		User sessionUser = (User) session.getAttribute("user");
		if (sessionUser == null) {
			return "redirect:/";
		}
		User user = userService.getUserById(userId);
		List<Order> sellGoods = orderService.getOrderBySellerId(user.getId());
		List<Review> reviews = reviewService.gerReviewByToUserId(user.getId());
		List<Reply> replies = reviewService.gerReplyByToUserId(user.getId());
		model.addAttribute("user", user);
		model.addAttribute("sellGoods", sellGoods);
		model.addAttribute("reviews", reviews);
		model.addAttribute("replies", replies);
		return "user/userEdit";
	}
 
	@RequestMapping(value = "/userEdit", method = RequestMethod.POST)
	public String postUserEdit(ModelMap model, @Valid User user,
			HttpSession session,
			@RequestParam(value = "photo", required = false) MultipartFile photo)
			throws IOException {
		String status;
		Boolean insertSuccess;
		User sessionUser = (User) session.getAttribute("user");
		user.setId(sessionUser.getId());
		InfoCheck infoCheck = new InfoCheck();
		if (!infoCheck.isMobile(user.getMobile())) {
			status = "请输入正确的手机号!";
		} else if (!infoCheck.isEmail(user.getEmail())) {
			status = "请输入正确的邮箱!";
		} else if (userService.getUserByMobile(user.getMobile()).getId() != user
				.getId()) {
			System.out.println(userService.getUserByMobile(user.getMobile())
					.getId() + " " + user.getId());
			status = "此手机号码已使用!";
		} else if (userService.getUserByEmail(user.getEmail()).getId() != user
				.getId()) {
			status = "此邮箱已使用!";
		} else {
			if (!photo.isEmpty()) {
				RandomString randomString = new RandomString();
				FileCheck fileCheck = new FileCheck();
				String filePath = "/statics/image/photos/" + user.getId();
				String pathRoot = fileCheck.checkGoodFolderExist(filePath);
				String fileName = user.getId()
						+ randomString.getRandomString(10);
				String contentType = photo.getContentType();
				String imageName = contentType.substring(contentType
						.indexOf("/") + 1);
				String name = fileName + "." + imageName;
				photo.transferTo(new File(pathRoot + name));
				String photoUrl = filePath + "/" + name;
				user.setPhotoUrl(photoUrl);
			} else {
				String photoUrl = userService.getUserById(user.getId())
						.getPhotoUrl();
				user.setPhotoUrl(photoUrl);
			}
			insertSuccess = userService.updateUser(user);
			if (insertSuccess) {
				session.removeAttribute("user");
				session.setAttribute("user", user);
				return "redirect:/user/userProfile";
			} else {
				status = "修改失败!";
				model.addAttribute("user", user);
				model.addAttribute("status", status);
				return "user/userEdit";
			}
		}
		System.out.println(user.getMobile());
		System.out.println(status);
		model.addAttribute("user", user);
		model.addAttribute("status", status);
		return "user/userEdit";
	}
 
	@RequestMapping(value = "/password/edit", method = RequestMethod.POST)
	public ResponseEntity editPassword(@RequestBody Password password) {
		User user = userService.getUserById(password.getUserId());
		String oldPass = DigestUtils
				.md5DigestAsHex((password.getOldPassword() + user.getCode())
						.getBytes());
		if (oldPass.equals(user.getPassword())) {
			RandomString randomString = new RandomString();
			String code = (randomString.getRandomString(5));
			String md5Pass = DigestUtils.md5DigestAsHex((password
					.getNewPassword() + code).getBytes());
			Boolean success = userService.updatePassword(md5Pass, code,
					password.getUserId());
			if (success) {
				return ResponseEntity.ok(true);
			} else {
				return ResponseEntity.ok("密码修改失败!");
			}
		} else {
			return ResponseEntity.ok("原密码输入不正确!");
		}
	}
 
}

类型控制层:

@Controller
@RequestMapping("type")
public class TypeController {
	private final TypeService typeService;
	private final GoodService goodService;
 
	@Autowired
	public TypeController(TypeService typeService, GoodService goodService) {
		this.typeService = typeService;
		this.goodService = goodService;
	}
 
	@RequestMapping(value = "/secondType/{firstTypeId}", method = RequestMethod.GET)
	public ResponseEntity getSecondTypeId(@PathVariable Integer firstTypeId) {
		List<SecondType> secondTypes = typeService
				.getSecondTypeByFirstTypeId(firstTypeId);
		if (secondTypes == null) {
			return ResponseEntity.ok("isNull");
		}
		return ResponseEntity.ok(secondTypes);
	}
 
	@RequestMapping(value = "/secondType/delete/{secondTypeId}", method = RequestMethod.GET)
	public ResponseEntity deleteSecondType(@PathVariable Integer secondTypeId) {
		Boolean success = goodService.getGoodsAdminByType(secondTypeId)
				.isEmpty();
		System.out.println(goodService.getGoodsAdminByType(secondTypeId));
		if (success) {
			Integer thisFirstTypeId = typeService.getSecondTypeById(
					secondTypeId).getFirstTypeId();
			success = typeService.deleteSecondType(secondTypeId);
			if (success) {
				List<SecondType> secondTypeList = typeService
						.getSecondTypeByFirstTypeId(thisFirstTypeId);
				if (secondTypeList == null) {
					return ResponseEntity.ok("isNull");
				}
				return ResponseEntity.ok(secondTypeList);
			}
		}
		return ResponseEntity.ok(success);
	}
 
	@RequestMapping(value = "/firstType/delete/{firstTypeId}", method = RequestMethod.GET)
	public ResponseEntity deleteFirstType(@PathVariable Integer firstTypeId) {
		Boolean success = typeService.getSecondTypeByFirstTypeId(firstTypeId)
				.isEmpty();
		if (success) {
			success = typeService.deleteFirstType(firstTypeId);
			if (success) {
				List<FirstType> firstTypeList = typeService.getAllFirstType();
				if (firstTypeList == null) {
					return ResponseEntity.ok("isNull");
				}
				return ResponseEntity.ok(firstTypeList);
			}
		}
		return ResponseEntity.ok(success);
	}
 
	@RequestMapping(value = "/secondType/create", method = RequestMethod.POST)
	public ResponseEntity createSecondType(@RequestBody SecondType secondType) {
		Integer thisFirstTypeId = secondType.getFirstTypeId();
		Boolean success = typeService.createSecondType(secondType);
		if (success) {
			List<SecondType> secondTypeList = typeService
					.getSecondTypeByFirstTypeId(thisFirstTypeId);
			return ResponseEntity.ok(secondTypeList);
		}
		return ResponseEntity.ok(success);
	}
 
	@RequestMapping(value = "/firstType/create", method = RequestMethod.POST)
	public ResponseEntity createSecondType(@RequestBody FirstType firstType) {
		Boolean success = typeService.createFirstType(firstType);
		if (success) {
			List<FirstType> firstTypeList = typeService.getAllFirstType();
			return ResponseEntity.ok(firstTypeList);
		}
		return ResponseEntity.ok(success);
	}
}

到此这篇关于Java实战项目之校园跑腿管理系统的实现的文章就介绍到这了,更多相关Java 校园跑腿管理系统内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • java基本教程之多线程基本概念 java多线程教程

    java基本教程之多线程基本概念 java多线程教程

    多线程是Java中不可避免的一个重要主体。下面是对“JDK中新增JUC包”之前的Java多线程内容的讲解,JUC包是由Java大师Doug Lea完成并在JDK1.5版本添加到Java中的
    2014-01-01
  • Java虚拟机JVM性能优化(三):垃圾收集详解

    Java虚拟机JVM性能优化(三):垃圾收集详解

    这篇文章主要介绍了Java虚拟机JVM性能优化(三):垃圾收集详解,本文讲解了众多的JVM垃圾收集器知识点,需要的朋友可以参考下
    2014-09-09
  • Java如何使用jar命令打包

    Java如何使用jar命令打包

    把多个文件打包成一个压缩包——这个压缩包和WinZip的压缩格式是一样的,区别在于jar压缩的文件默认多一个META-INF的文件夹,该文件夹里包含一个MANIFEST.MF的文件,本文给大家介绍Java如何使用jar命令打包,感兴趣的朋友跟随小编一起看看吧
    2023-10-10
  • 详解Spring Cloud微服务架构下的WebSocket解决方案

    详解Spring Cloud微服务架构下的WebSocket解决方案

    这篇文章主要介绍了详解Spring Cloud微服务架构下的WebSocket解决方案,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-12-12
  • Springmvc国际化自动配置代码实现

    Springmvc国际化自动配置代码实现

    这篇文章主要介绍了Springmvc国际化自动配置代码实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-04-04
  • 将一个数组按照固定大小进行拆分成数组的方法

    将一个数组按照固定大小进行拆分成数组的方法

    下面小编就为大家带来一篇将一个数组按照固定大小进行拆分成数组的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-11-11
  • spring接口通过配置支持返回多种格式(xml,json,html,excel)

    spring接口通过配置支持返回多种格式(xml,json,html,excel)

    这篇文章主要给大家介绍了关于spring接口如何通过配置支持返回多种格式(xml,json,html,excel)的相关资料,文中通过示例代码介绍的非常详细,需要的朋友可以参考借鉴,下面随着小编来一起学习学习吧。
    2017-12-12
  • Java设计模式之工厂模式

    Java设计模式之工厂模式

    这篇文章主要为大家详细介绍了Java设计模式之工厂模式,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-03-03
  • 基于Properties类操作.properties配置文件方法总结

    基于Properties类操作.properties配置文件方法总结

    这篇文章主要介绍了Properties类操作.properties配置文件方法总结,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2021-09-09
  • Java数据结构之散列表(动力节点Java学院整理)

    Java数据结构之散列表(动力节点Java学院整理)

    散列表(Hash table,也叫哈希表),是根据关键字(key value)而直接进行访问的数据结构。这篇文章给大家介绍了java数据结构之散列表,包括基本概念和散列函数相关知识,需要的的朋友参考下吧
    2017-04-04

最新评论