首页>代码>基于(SpringMVC + Spring + Mybatis + Shiro + Bootstrap)开发的ssm教务后台管理系统>/Examination_System/src/main/java/com/system/controller/LoginController.java
package com.system.controller; import com.system.po.Userlogin; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.UsernamePasswordToken; import org.apache.shiro.subject.Subject; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; /** * Created by Jacey on 2017/6/30. */ @Controller public class LoginController { //登录跳转 @RequestMapping(value = "/login", method = {RequestMethod.GET}) public String loginUI() throws Exception { return "../../login"; } //登录表单处理 @RequestMapping(value = "/login", method = {RequestMethod.POST}) public String login(Userlogin userlogin) throws Exception { //Shiro实现登录 UsernamePasswordToken token = new UsernamePasswordToken(userlogin.getUsername(), userlogin.getPassword()); Subject subject = SecurityUtils.getSubject(); //如果获取不到用户名就是登录失败,但登录失败的话,会直接抛出异常 subject.login(token); if (subject.hasRole("admin")) { return "redirect:/admin/showStudent"; } else if (subject.hasRole("teacher")) { return "redirect:/teacher/showCourse"; } else if (subject.hasRole("student")) { return "redirect:/student/showCourse"; } return "/login"; } }
最近下载更多
yangyang567 LV1
3月8日
五折也挺好的 LV13
2023年7月12日
lds85930 LV11
2023年5月29日
qiangmin1223 LV11
2023年4月24日
wubinbin LV11
2023年3月29日
ed8vid LV4
2023年3月21日
ycx199422 LV6
2023年2月28日
dongandmin LV6
2023年2月27日
levmar LV12
2023年2月1日
mikebarton LV4
2022年11月15日