首页>代码>spring boot+mysql+mybatis+easyUI整合实现简单网站用户后台管理系统>/system/src/main/java/com/kyh/system/controller/LoginController.java
package com.kyh.system.controller;

import com.kyh.system.entity.User;
import com.kyh.system.service.UserService;
import com.sun.deploy.net.HttpRequest;
import com.sun.deploy.net.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

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

@Controller
@RequestMapping(value = "login")
public class LoginController {

    @Autowired
    private UserService userService;
    @RequestMapping(value = "/",method = {RequestMethod.POST, RequestMethod.GET})
    public String login() {
        return "/login/login";
    }

    /***
     * 这是一种返回形式 以ModelAndView 视图返回数据的形式返回 和返回map一样 调用方式不一样
     * */
    @RequestMapping(value="/userLogin",method = {RequestMethod.POST, RequestMethod.GET})
    public  ModelAndView userLogin(HttpServletRequest request, HttpServletResponse response,HttpSession session){
         ModelAndView model=new ModelAndView();
         String id=request.getParameter("id");
         String password=request.getParameter("password");
         User user=new User();
         User loginUser=new User();
         user.setPassword(password);
         user.setUserId(Integer.parseInt(id));
         loginUser=userService.getUserById(user);
         if(null!=loginUser){
             session.setAttribute("user",loginUser);
             model.setViewName("login/index");
         }else {
             model.addObject("MSG","用户名或密码错误");
             model.setViewName("/login/login");
         }
         return  model;
    }
    /**
     * 登录成功 加载欢迎页面  返回String y页面的路径和名称
     * */
    @RequestMapping(value="welcome",method = {RequestMethod.POST,RequestMethod.GET})
    public  String welcome(){
         return "/login/welcome";
    }
}
最近下载更多
kangyongh  LV10 10月21日
SDASDASDAD  LV1 2023年10月16日
微信网友_6506630663868416  LV1 2023年6月6日
7346040  LV1 2022年11月18日
tanxin  LV3 2022年9月2日
123456789aweq  LV2 2022年7月21日
刘亦菲9527  LV15 2022年3月7日
9843637  LV9 2021年12月13日
Oxygeni  LV7 2021年12月1日
尹恒yingying  LV18 2021年10月23日
最近浏览更多
微信网友_7289626841501696  LV4 2024年12月24日
bluerstar  LV1 2024年10月23日
wwwww816  LV5 2024年5月22日
1941549176  LV4 2024年4月29日
微信网友_6927932988952576  LV12 2024年3月31日
skipple3  LV39 2024年1月22日
WHY-small  LV15 2023年12月20日
暂无贡献等级
fff2003  LV9 2023年11月18日
wnnmmb  LV2 2023年10月18日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友