package com.example.web.controller;

import com.example.pojo.User;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public String login(User user ,HttpSession session){
        User users = this.userService.userLogin(user);
        session.setAttribute("users",users);
        return "redirect:/page/index";
        // redirect 从定向不走视图解析器
    }

    @RequestMapping(value = "/showUser")
    public String showUser(int id,Model model){
        User user = this.userService.findUserById(id);
        model.addAttribute("users",user);
        return "showUser";
    }


}
