src/main/java/com/system/controller/LoginController.java

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

package com.system.controller;

import com.system.po.Coursedate;
import com.system.po.Userlogin;
import com.system.service.CoursedateService;
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.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;


@Controller
public class LoginController {

    @Resource(name = "coursedateServiceImpl")
    private CoursedateService coursedateService;

    //登录跳转
    @RequestMapping(value = "/login", method = {RequestMethod.GET})
    public String loginUI() throws Exception {
        return "../../login";
    }

    //登录表单处理
    @RequestMapping(value = "/login", method = {RequestMethod.POST})
    public String login(Userlogin userlogin, Model model, HttpSession session) 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")) {
            Date date = new Date();
          // DateFormat的格式(即yyyy/MM/dd HH:mm:ss)就是将获得日期字符串显示的格式
            DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" );
            String nowDateStr = sdf.format(date);
            Coursedate coursedate= coursedateService.selectnew();
            if(coursedate==null){
                session.setAttribute("cdate",null);
            }else if(sdf.parse(coursedate.getEndtime()).after(date)){
                session.setAttribute("cdate",coursedate);
            }else{
                session.setAttribute("cdate",null);
后面还有 8 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。