Java 实战范例之校园二手市场系统的实现

一、项目简述( +IW文档)

功能:本系统分用户前台和管理员后台。 本系统用例模型有三种,分别是游客、注册用户和系统管 理员。下面分别对这三个角色的功能进行描述: 1) 诞 游客是未注册的用户,他们可以浏览物物品,可以搜索物 品,如需购买物品,必须先注册成为网站用户。游客主要 功触吓: a.浏览物品 b.搜索物品 c.注册成为网站用户 2) 注册用户 注册用户是经过网站合法认证的用户,登录网站后可以浏 览物品、搜索物品、发布物品、关注物品、购买物品和查 看个人中心。 3) 系统管理员 系统管理员主要负责系统的后台管理工作,主要功能如 下: 用户管理,商品管理等等。

二、项目运行

环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe ( IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。

用户信息管理控制器:

@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
public class OrderController {
	private final GoodService goodService;
	private final OrderService orderService;

	@Autowired
	public OrderController(GoodService goodService, OrderService orderService) {
		this.goodService = goodService;
		this.orderService = orderService;
	}

	@RequestMapping(value = "/user/orderInfo", method = RequestMethod.GET)
	public String getOrderInfo(ModelMap model,
			@RequestParam(value = "orderId", required = false) Integer orderId,
			HttpSession session) {
		User sessionUser = (User) session.getAttribute("user");
		if (sessionUser == null) {
			return "redirect:/";
		}
		Order orderInfo = orderService.getOrderById(orderId);
		List<Order> orders = orderService.getOtherOrderByCustomerId(
				sessionUser.getId(), orderId);
		model.addAttribute("orderInfo", orderInfo);
		model.addAttribute("orders", orders);
		return "user/orderInfo";
	}

	@RequestMapping(value = "/user/sellerInfo", method = RequestMethod.GET)
	public String getSellerInfo(ModelMap model,
			@RequestParam(value = "orderId", required = false) Integer orderId,
			HttpSession session) {
		User sessionUser = (User) session.getAttribute("user");
		if (sessionUser == null) {
			return "redirect:/";
		}
		Order orderInfo = orderService.getOrderById(orderId);
		List<Order> orders = orderService.getOtherOrderBySellerId(
				sessionUser.getId(), orderId);
		model.addAttribute("orderInfo", orderInfo);
		model.addAttribute("orders", orders);
		System.out.println("sellerInfo.size:" + orders.size());
		return "user/sellerInfo";
	}

	@RequestMapping(value = "/user/order/delete/{orderId}", method = RequestMethod.GET)
	public ResponseEntity deleteOrderById(@PathVariable Integer orderId) {
		Boolean success;
		success = orderService.deleteOrderById(orderId) > 0;
		return ResponseEntity.ok(success);
	}

	@RequestMapping(value = "/user/sellerOrder/delete/{orderId}&{goodId}", method = RequestMethod.GET)
	public ResponseEntity deleteSellerOrderById(@PathVariable Integer orderId,
			@PathVariable Integer goodId) {
		Boolean success;
		success = goodService.updateGoodStatusId(1, goodId) > 0;
		if (success) {
			success = orderService.deleteOrderById(orderId) > 0;
		}
		return ResponseEntity.ok(success);
	}

	@RequestMapping(value = "/user/order/update/status/{orderId}&{statusId}", method = RequestMethod.GET)
	public ResponseEntity updateOrderStatus(@PathVariable Integer orderId,
			@PathVariable Integer statusId) {
		Boolean success = orderService.updateStatus(statusId, orderId) > 0;
		if (success) {
			Order order = orderService.getOrderById(orderId);
			return ResponseEntity.ok(order);
		}
		return ResponseEntity.ok(success);
	}

	@RequestMapping(value = "/user/order/create", method = RequestMethod.POST)
	public ResponseEntity createOrder(@RequestBody Order order) {
		Boolean success = orderService.insertOrder(order) > 0;
		if (success) {
			success = goodService.updateGoodStatusId(0, order.getGoodId()) > 0;
			if (success) {
				return ResponseEntity.ok(order.getId());
			} else {
				orderService.deleteOrderById(order.getId());
				return ResponseEntity.ok(success);
			}
		}
		return ResponseEntity.ok(success);
	}

	@RequestMapping(value = "/user/order/allOrder", method = RequestMethod.GET)
	public ResponseEntity getAllOrders() {
		List<Order> orderList = orderService.getOrderList();
		return ResponseEntity.ok(orderList);
	}
}

后台用户管理控制器:

@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);
    }

}

到此这篇关于Java 实战范例之校园二手市场系统的实现的文章就介绍到这了,更多相关Java 二手市场系统内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • Java 实战项目基于遗传算法学校排课系统的实现流程

    一.项目简述 本系统功能包括: 排课管理,课程管理,讲师管理,班级管理,学生管理,教学资料,学习文档,在线测试,教材列表,教学设计,帮助中心等等功能. 二.项目运行 环境配置: Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持). 项目技术: Springboot + Maven + mybatis+ Vue 等等组成,B/S模式 + Maven管理

  • Java 实战项目之小说在线阅读系统的实现流程

    一.项目简述 功能包括(管理员和游客角色): 1:用户及主要操作功能 游客可以浏览网站的主页,但是需要注册为会员后部分小 说才能对网络小说进免费行阅读或阅读.用户可以收藏书 架,留言评论,上次阅读,阅读历史,章节选择等等功 能. 2:管理模块 网络小说管理模块包括不同网络小说类别的添加,删除以 及网络小说的上传,删除管理.可以包括武侠小书,都市 言情,穿越小书等各个类等等功能. 二.项目运行 环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ

  • Java 实战项目之精美物流管理系统的实现流程

    一.项目简述 本系统功能包括: 数据统计.收件录入.发件录入.到件录入.派件录入.问题件录入.退件录入.留仓录入.装车录入.发车录入.到车录入.卸车录入.运单录入.运单编辑.运单查询.数据导入.签收录入.签收查询.快件跟踪.自定义跟踪.问题件跟踪.预付款管理.财务报表明细.现金账单.月结账单.代收货款.业务员提成.订单分配.订单查询.物品名维护.入库.出库.库存.物料.角色管理.用户管理.系统设置.员工维护.客户维护.网点维护.报价维护.其他维护.收发记录.到件预报. 二.项目运行 环境配置:

  • Java 实战项目之教材管理系统的实现流程

    一.项目简述 功能包括: 管理员可以增删改查教材.教材商.入库教材.用户(用 户包括学生和教师)可以对教材商.教材进行.Excel的导入 导出操作.教师以领取入库的教材,可以退还教材.学生只能在对应的教师那里领取教材,并且可以退还教材. 查询自己已经领取的教材.并且对已领教材付款等等. 二.项目运行 环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持) 项目技术: JSP +Spr

  • Java 实战项目之学生信息管理系统的实现流程

    一.项目简述 功能包括: 用户的登录注册,学生信息管理,教师信息管理,班级信 息管理,采用mvcx项目架构,覆盖增删改查,包括学生, 教币班级的信息导出上传导入等等功能. 二.项目运行 环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持) 项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuer

  • Java 实战项目之精品养老院管理系统的实现流程

    一.项目简述 本系统功能包括:通知公告,老人管理,护工管理,问答管理等等功能. 二.项目运行 环境配置: Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持). 项目技术: Springboot + Maven + mybatis+ Vue 等等组成,B/S模式 + Maven管理等等. 系统控制器(登录.注销.修改.新增登)业务: /** * 系统控

  • Java 实战项目之家政服务平台系统的实现流程

    一.项目简述 功能包括: 家政服务网站系统,用户注册,登录,分为家政人员,普 通用户,以及最高管理员,包括家政分类查询,展示,线 上预约服务,家政申请,评论,留言沟通・,联系家政服 务,家政人员的认证,职业认证,以及后台的维护等等功能. 二.项目运行 环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持) 项目技术: JSP +Spring + SpringMVC + MyBatis

  • Java ʵս��Ŀ֮���ߵ��ϵͳ��ʵ������

    һ����Ŀ���� ���ܰ����� ǰ̨ʵ�֣��û�����˵�����Ʒ����ɸѡ���鿴�˵��� �顢��ӹ��ﳵ�����ﳵ���㡢��Աȯ�����˶�����ѯ�� �ȡ� ��̨ʵ�֣���ϵ�������Ʒ��������������ϵͳ����� �ϼ���Ա����ȡ� ϵͳ��Ϊ���߻����Ա���˿͡���ʦ������Ա�ȵȡ� ������Ŀ���� �������ã� Jdk1.8 + Tomcat8.5 + mysql + Eclispe (Inte

  • Java 实战项目之诚途旅游系统的实现流程

    采用ssm架构实现的旅游网站系统 包括网站展示和后台管理功能,网站主要是页面浏览以及评论.制定旅游方案.智能推荐功能 后台就是维护网站展示的内容,添加旅游景点.管理用户.查看用户的搜索记录功能 酒店信息控制层: /** * 控制器层 * */ @Controller @CrossOrigin @RequestMapping("/hotel") public class HotelController { @Autowired private HotelService hotelServ

  • Java 实战项目之毕业设计管理系统的实现流程

    一.项目简述 功能包括: 该系统不错分为学生,教师,管理员,教导主任四种角 色,包括学生管理,教师管理,学生选题,教师选题,主 任审核,管理员审核,开题报告,中期检查,论文提交, 文件管理等等非常不错. 二.项目运行 环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持) 项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + Ja

随机推荐