@RequestMapping("/login.do")
  public String login(@ModelAttribute("user") User user, HttpSession session) throws Exception {

    System.out.println("/login.do");
    // Business Logic
    User dbUser = userService.getUser(user.getUserId());

    if (user.getPassword().equals(dbUser.getPassword())) {
      session.setAttribute("user", dbUser);
    }

    return "redirect:/index.jsp";
  }
  @RequestMapping("/updateUser.do")
  public String updateUser(@ModelAttribute("user") User user, Model model, HttpSession session)
      throws Exception {

    System.out.println("/updateUser.do");
    // Business Logic
    userService.updateUser(user);

    String sessionId = ((User) session.getAttribute("user")).getUserId();
    if (sessionId.equals(user.getUserId())) {
      session.setAttribute("user", user);
    }

    return "redirect:/getUser.do?userId=" + user.getUserId();
  }
Esempio n. 3
0
  @RequestMapping
  public ModelAndView addPurchase(
      @ModelAttribute("purchase") Purchase purchase,
      @RequestParam("prodNo") int prodNo,
      @RequestParam("buyerId") String buyerId)
      throws Exception {
    System.out.println(purchase);
    System.out.println(prodNo);
    Product product = new Product();
    product.setProdNo(prodNo);
    User user = new User();
    user.setUserId(buyerId);

    purchase.setPurchaseProd(product);
    purchase.setBuyer(user);
    purchase.setTranCode("1");
    purchaseService.addPurchase(purchase);

    product = productService.getProduct(prodNo);
    ModelAndView mav = new ModelAndView();
    mav.addObject("product", product);
    mav.setViewName("forward:/product/getProduct.jsp"); // ���ſϷ� ������
    return mav;
  }