首页>代码>spring+spring mvc+mybatis+mysql+maven整合开发服装购物商城实例>/shop/src/main/java/com/zgzcwy/controller/LoginController.java
package com.zgzcwy.controller;
import javax.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.zgzcwy.entity.User;
import com.zgzcwy.service.LoginService;
/**
* @ClassName: LoginController
* @Description: 用户登录登出
* @author: Administrator
* @date: 2018年1月5日 上午11:37:06
*
*/
@Controller
public class LoginController {
private static final Logger logger = LoggerFactory.getLogger(UserController.class);
@Autowired
private LoginService loginService;
/**
* 登录
* @param mav
* @param username
* @param password
* @param checkCode
* @param session
* @return
*/
@RequestMapping("/login")
public ModelAndView login(
ModelAndView mav,
String username,
String password,
String checkCode,
HttpSession session){
logger.info("用户名"+username);
logger.info("密码"+password);
//1.比较验证码
String sessionCode=(String) session.getAttribute("checkCode");
if(checkCode!=null&&checkCode.equalsIgnoreCase(sessionCode)){
logger.info("验证码:"+checkCode);
//登录操作
User user=loginService.findUserByUsernaeAndPassword(username,password);
logger.info("user"+user);
if(user!=null){
//验证用户状态
int status=user.getStatus();
if(status==1){
session.setAttribute("user",user);
mav.setViewName("redirect:index");
logger.info("登录成功");
return mav;
}else{
mav.addObject("msg","请联系管理员");
mav.setViewName("login");
return mav;
}
}else{
mav.addObject("msg","用户名或者密码错误");
mav.setViewName("login");
return mav;
}
}else{
mav.addObject("msg","验证码错误");
mav.setViewName("login");
return mav;
}
}
/**
* 登出
*/
@RequestMapping("/logout")
public String logout(HttpSession session){
//销毁session
session.invalidate();
return "redirect:index";
}
}
最近下载更多
曾显示 LV6
2024年7月7日
郭宇航裹裹 LV5
2024年6月9日
sunlea LV20
2024年5月12日
杨豫川 LV12
2024年1月15日
微信网友_6680567232876544 LV8
2023年10月10日
gecongkai LV8
2023年6月23日
teamdragon LV6
2023年5月17日
微信网友_6436772032335872 LV3
2023年4月17日
601601lmy LV5
2023年3月5日
22344341 LV2
2023年1月27日
最近浏览更多
tianjj
6月5日
暂无贡献等级
暂无贡献等级
sn764889012
4月16日
暂无贡献等级
orang801 LV2
2月24日
ryadmin123 LV2
2月14日
微信网友_7310057461567488
2024年12月24日
暂无贡献等级
马平川
2024年12月15日
暂无贡献等级
微信网友_7261870476267520
2024年11月20日
暂无贡献等级
Xppasdf LV3
2024年10月29日
gql0720 LV1
2024年9月25日

