基于javaweb+jsp的网上商城系统(java+SSM+jsp+mysql+maven)

基于javaweb+jsp的网上商城系统(java+SSM+jsp+mysql+maven)

一、项目简述功能
javaweb 网上商城系统,前台+后台管理,用户注册,登录,上哦展示,分组展示,搜索,收货地址管理,购物车管理,添加,购买,个人信息修改。订单查询等等,后台商品管理,分类管理,库存管理,订单管理,用户管理,信息修改等等.
二、项目运行
环境配置: Jdk1.8 + Tomcats . 5 + mysql + Eclispe ( IntelliJ IDEA ,Eclispe , MyEclispe , sts 都支持)
项目技术: JSP + Spring + SpringMVC + MyBatis + html + cSS + Javascript + JQuery + Ajax + layui + maven 等等。

基于javaweb+jsp的网上商城系统(java+SSM+jsp+mysql+maven)_第1张图片
基于javaweb+jsp的网上商城系统(java+SSM+jsp+mysql+maven)_第2张图片
基于javaweb+jsp的网上商城系统(java+SSM+jsp+mysql+maven)_第3张图片

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

	 */
	@PostMapping("/register")
	public String register(Users user, Model model){
		if (user.getUsername().isEmpty()) {
			model.addAttribute("msg", "用户名不能为空!");
			return "/index/register.jsp";
		}else if (userService.isExist(user.getUsername())) {
			model.addAttribute("msg", "用户名已存在!");
			return "/index/register.jsp";
		}else {
			String password = user.getPassword();
			userService.add(user);
			user.setPassword(password);
			return "/index/index"; // 注册成功后转去登录
		}
	}
	
	/**
	 * 用户登录
	 * @return
	 */
                            //未付款订单
                            orderUnpaidArray[i] = orderGroup.getProductOrder_count();
                            break;
                        case 1:
                            //未发货订单
                            orderNotShippedArray[i] = orderGroup.getProductOrder_count();
                            break;
                        case 2:
                            //未确认订单
                            orderUnconfirmedArray[i] = orderGroup.getProductOrder_count();
                            break;
                        case 3:
                            //交易成功订单
                            orderSuccessArray[i] = orderGroup.getProductOrder_count();
                            break;
                    }
                    //累加当前日期的订单总数
                    orderCount += orderGroup.getProductOrder_count();
		}
		int orderid = orderService.save(shopcartList, user);
		if(orderid > 0) {
			// 清空购物车
			session.setAttribute("total", shopcartService.getTotal(user.getId()));
			// 跳转支付
			return "redirect:topay?orderid="+orderid;
		} 
		model.addAttribute("msg", "出了点问题");
		return shopcart(model, session);
	}
	
	/**
	 * 支付页面
	 * @return
	 */
	@RequestMapping("/topay")
	public String topay(int orderid, ServletRequest request, HttpSession session) {
		Users user = (Users) session.getAttribute("user");
		if (user == null) {
			request.setAttribute("msg", "请先登录!");
		return "/index/register.jsp";
	}
	
	/**
	 * 用户注册
	 * @return
	 */
	@PostMapping("/register")
	public String register(Users user, Model model){
		if (user.getUsername().isEmpty()) {
			model.addAttribute("msg", "用户名不能为空!");
			return "/index/register.jsp";
		}else if (userService.isExist(user.getUsername())) {
			model.addAttribute("msg", "用户名已存在!");
			return "/index/register.jsp";
		}else {
			String password = user.getPassword();
			userService.add(user);
		if (user == null) {
			request.setAttribute("msg", "请先登录!");
			return "/index/index";
		}
		// 模拟支付
		orderService.pay(order);
		request.setAttribute("typeList", typeService.getList());
		request.setAttribute("order", orderService.get(order.getId()));
		request.setAttribute("msg", "支付成功! 即将跳转到订单列表");
		return "/index/pay.jsp";
	}
	
	/**
	 * 查看订单
	 * @return
	 */
后台管理平台登录代码:
/**
 * 后台管理-主页
 */
@Controller
public class AdminHomeController extends BaseController {
    @Resource(name = "adminService")
    private AdminService adminService;
    @Resource(name = "productOrderService")
    private ProductOrderService productOrderService;
    @Resource(name = "productService")
    private ProductService productService;
    @Resource(name = "userService")
    private UserService userService;
    /**
     * 转到后台管理-主页
     * @param session session对象
     * @param map 前台传入的Map
     * @return 响应数据
     * @throws ParseException 转换异常
     */
    @RequestMapping(value = "admin", method = RequestMethod.GET)
    public String goToPage(HttpSession session, Map<String, Object> map) throws ParseException {
	 * 购买
	 * @return
	 */
	@RequestMapping("/buy")
	public @ResponseBody int buy(Shopcart shopcart, HttpSession session, Model model){
		Users user = (Users) session.getAttribute("user");
		if (user == null) {
			return -111;
		}
		shopcart.setUserId(user.getId());
		shopcart.setGood(goodService.get(shopcart.getGoodId()));
		// 验证库存
//		int stock = skuService.getStock(shopcart.getGoodId(), shopcart.getColorId(), shopcart.getSizeId());
//		if(shopcart.getAmount() > stock) {
//			model.addAttribute("msg", "商品 [ " + shopcart.getGood().getName() + " ] 库存不足! 当前库存只有: " + stock);
//		}
		return orderService.save(Arrays.asList(shopcart), user);
	}
	
	}
	
	/**
	 * 购买
	 * @return
	 */
	@RequestMapping("/cart")
	public @ResponseBody int cart(Shopcart shopcart, HttpSession session, Model model){
		Users user = (Users) session.getAttribute("user");
		if (user == null) {
			return -111;
		}
		shopcart.setUserId(user.getId());
		shopcartService.save(shopcart);
		int total = shopcartService.getTotal(user.getId());
		session.setAttribute("total", total);
			return "/index/register.jsp";
		}else if (userService.isExist(user.getUsername())) {
			model.addAttribute("msg", "用户名已存在!");
			return "/index/register.jsp";
		}else {
			String password = user.getPassword();
			userService.add(user);
			user.setPassword(password);
			return "/index/index"; // 注册成功后转去登录
		}
	}
	
	/**
	 * 用户登录
	 * @return
    @RequestMapping(value = "admin/home", method = RequestMethod.GET)
    public String goToPageByAjax(HttpSession session, Map<String, Object> map) throws ParseException {
        logger.info("获取管理员信息");
        Object adminId = checkAdmin(session);
        if (adminId == null) {
            return "admin/include/loginMessage";
        }
        Admin admin = adminService.get(null, Integer.parseInt(adminId.toString()));
        map.put("admin", admin);
        logger.info("获取统计信息");
        Integer productTotal = productService.getTotal(null, new Byte[]{0, 2});
        Integer userTotal = userService.getTotal(null);
        Integer orderTotal = productOrderService.getTotal(null, new Byte[]{3});
        logger.info("获取图表信息");
        map.put("jsonObject", getChartData(null, null,7));
        logger.info("获取图表信息");
        map.put("jsonObject", getChartData(null,null,7));
        map.put("productTotal", productTotal);
        map.put("userTotal", userTotal);
        map.put("orderTotal", orderTotal);
        logger.info("转到后台管理-主页-ajax方式");
        return "admin/homeManagePage";
    }
	public @ResponseBody boolean delete(int skuid, HttpSession session){
		Users user = (Users) session.getAttribute("user");
		if (user == null) {
			return false;
		}
		shopcartService.delete(skuid);
		session.setAttribute("total", shopcartService.getTotal(user.getId()));
		return true;
	}
	
	/**
	 * 总金额
	 * @return
	 */
	@RequestMapping("/total")
	public @ResponseBody int total(HttpSession session){
		Users user = (Users) session.getAttribute("user");
		if (user == null) {
			return -111;
		}
		return shopcartService.getTotalPrice(user.getId());
	}
	
        return "admin/homePage";
    }
    /**
     * 转到后台管理-主页(ajax方式)
     * @param session session对象
     * @param map 前台传入的Map
     * @return 响应数据
     * @throws ParseException 转换异常
     */
    @RequestMapping(value = "admin/home", method = RequestMethod.GET)
    public String goToPageByAjax(HttpSession session, Map<String, Object> map) throws ParseException {
        logger.info("获取管理员信息");
        Object adminId = checkAdmin(session);
        if (adminId == null) {
            return "admin/include/loginMessage";
        }
        Admin admin = adminService.get(null, Integer.parseInt(adminId.toString()));
        map.put("admin", admin);
		if (user == null) {
			request.setAttribute("msg", "请先登录!");
			return "/index/index";
		}
		request.setAttribute("typeList", typeService.getList());
		request.setAttribute("order", orderService.get(orderid));
		return "/index/pay.jsp";
	}
	
	/**
	 * 支付(模拟)
	 * @return
	 */
	@RequestMapping("/pay")
	public String pay(Orders order, ServletRequest request, HttpSession session) {
		Users user = (Users) session.getAttribute("user");
		if (user == null) {
			request.setAttribute("msg", "请先登录!");
}
用户相关接口:
/**
 * 用户相关接口
 */
@Controller
@RequestMapping("/index")
public class UserController{
	
	@Resource
	private UserService userService;
	@Resource
	private OrderService orderService;
	@Resource
	private GoodService goodService;
	@Resource
	private TypeService typeService;
	@Resource
	private ShopcartService shopcartService;
	@Resource
	private SkuService skuService;
	
            return "admin/include/loginMessage";
        }
        Admin admin = adminService.get(null, Integer.parseInt(adminId.toString()));
        map.put("admin", admin);
        logger.info("获取统计信息");
        Integer productTotal = productService.getTotal(null, new Byte[]{0, 2});
        Integer userTotal = userService.getTotal(null);
        Integer orderTotal = productOrderService.getTotal(null, new Byte[]{3});
        logger.info("获取图表信息");
        map.put("jsonObject", getChartData(null, null,7));
        logger.info("获取图表信息");
        map.put("jsonObject", getChartData(null,null,7));
        map.put("productTotal", productTotal);
        map.put("userTotal", userTotal);
        map.put("orderTotal", orderTotal);
        logger.info("转到后台管理-主页-ajax方式");
        return "admin/homeManagePage";
    }
    /**
		request.setAttribute("pageHtml", PageUtil.getPageHtml(request, goodService.getTotalByType(typeid), page, rows));
		return "/index/goods.jsp";
	}
	
	/**
	 * 商品详情
	 * @return
	 */
	@RequestMapping("/detail")
	public String detail(int goodid, HttpServletRequest request){
		request.setAttribute("typeList", typeService.getList());
		request.setAttribute("topList", topService.getList(Tops.TYPE_SUPPER, 1, 4));
		Goods good = goodService.get(goodid);
		request.setAttribute("good", good);
		request.setAttribute("type", typeService.get(good.getTypeId()));
		request.setAttribute("colorList", skuService.getColorList(goodid));
		request.setAttribute("sizeList", skuService.getSizeList(goodid));
		return "/index/detail.jsp";
	}
		return "/index/order.jsp";
	}
	
	
	/**
	 * 个人信息
	 * @return
	 */
	@RequestMapping("/my")
	public String my(HttpSession session, Model model){
		model.addAttribute("flag", 11);
		model.addAttribute("typeList", typeService.getList());
		Users user = (Users) session.getAttribute("user");
		if (user == null) {
			model.addAttribute("msg", "请先登录!");
	
	/**
	 * 支付页面
	 * @return
	 */
	@RequestMapping("/topay")
	public String topay(int orderid, ServletRequest request, HttpSession session) {
		Users user = (Users) session.getAttribute("user");
		if (user == null) {
			request.setAttribute("msg", "请先登录!");
			return "/index/index";
		}
		request.setAttribute("typeList", typeService.getList());
		request.setAttribute("order", orderService.get(orderid));
		return "/index/pay.jsp";
            cal.add(Calendar.DATE, i);
            String formatDate = time2.format(cal.getTime());
            dateStr.add(formatDate);
            //该天的订单总数
            int orderCount = 0;
            //循环订单集合数据的结果集
            for(int j = 0; j < orderGroupList.size(); j++){
                OrderGroup orderGroup = orderGroupList.get(j);
                //如果该订单日期与当前日期一致
                if(orderGroup.getProductOrder_pay_date().equals(formatDate)){
                    //从结果集中移除数据
                    orderGroupList.remove(j);
                    //根据订单状态将统计结果存入对应的订单状态数组中
                    switch (orderGroup.getProductOrder_status()) {
                        case 0:
                            //未付款订单
                            orderUnpaidArray[i] = orderGroup.getProductOrder_count();
                            break;
                        case 1:
                            //未发货订单
                            orderNotShippedArray[i] = orderGroup.getProductOrder_count();
                            break;
	@Resource
	private GoodService goodService;
	@Resource
	private TypeService typeService;
	@Resource
	private ShopcartService shopcartService;
	@Resource
	private SkuService skuService;
	
	/**
	 * 用户注册
	 * @return
	 */
	@GetMapping("/register")
	public String reg(Model model) {
		model.addAttribute("flag", -1); // 注册页面
		return "/index/register.jsp";
	}
	
	/**
	 * 用户注册
	 * @return
	 */
			return -111;
		}
		return shopcartService.getTotalPrice(user.getId());
	}
	
	
	/**
	 * 提交订单
	 * @return
	 */
	@RequestMapping("/save")
	public String save(ServletRequest request, HttpSession session, Model model){
		Users user = (Users) session.getAttribute("user");
		if (user == null) {
			model.addAttribute("msg", "请先登录!");
			return "/index/index";
		}
		List<Shopcart> shopcartList = shopcartService.getList(user.getId());
		if(Objects.isNull(shopcartList) || shopcartList.isEmpty()) {
			model.addAttribute("msg", "购物车没有商品");
			return shopcart(model, session);
@Controller
public class AdminHomeController extends BaseController {
    @Resource(name = "adminService")
    private AdminService adminService;
    @Resource(name = "productOrderService")
    private ProductOrderService productOrderService;
    @Resource(name = "productService")
    private ProductService productService;
    @Resource(name = "userService")
    private UserService userService;
    /**
     * 转到后台管理-主页
     * @param session session对象
     * @param map 前台传入的Map
     * @return 响应数据
     * @throws ParseException 转换异常
     */
    @RequestMapping(value = "admin", method = RequestMethod.GET)
    public String goToPage(HttpSession session, Map<String, Object> map) throws ParseException {
        logger.info("获取管理员信息");
        Object adminId = checkAdmin(session);
 * 前台相关接口
 */
@Controller
@RequestMapping("/index")
public class IndexController{
	
	private static final int rows = 8; // 默认每页数量
	@Autowired
	private TopService topService;
	@Autowired
	private GoodService goodService;
	@Autowired
	private TypeService typeService;
	@Autowired
	}
	
	/**
	 * 商品列表
	 * @return
	 */
	@RequestMapping("/goods")
	public String goods(int typeid, @RequestParam(required=false, defaultValue="1")int page, HttpServletRequest request){
		request.setAttribute("flag", typeid);
		request.setAttribute("typeList", typeService.getList());
		request.setAttribute("topList", topService.getList(Tops.TYPE_SUPPER, 1, 4));
		if (typeid > 0) {
			request.setAttribute("type", typeService.get(typeid));
		}
		request.setAttribute("goodList", goodService.getListByType(typeid, page, rows));
		request.setAttribute("pageHtml", PageUtil.getPageHtml(request, goodService.getTotalByType(typeid), page, rows));
		return "/index/goods.jsp";
	}
	
	/**
	 * 商品详情
	 * @return
	 */

你可能感兴趣的:(java,mysql)