src/main/java/com/xtu/hrms/controller/LoginController.java

(开头部分) 2KB

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

package com.xtu.hrms.controller;

import com.xtu.hrms.bean.Emp;
import com.xtu.hrms.bean.User;
import com.xtu.hrms.service.IEmpService;
import com.xtu.hrms.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
@Slf4j
public class LoginController {

//    定义后台用户业务对象
    @Autowired
    private IUserService userService;
    @Autowired
    private IEmpService empService;

//    @RequestMapping("/")
//    public String index() {
//        return "login";
//    }

    @PostMapping(value = "/user/login")
    public String login(User user, @RequestParam("tip") String tip, Map<String, Object> map, HttpSession session){

        if(tip.equals("1")){
        //        根据用户名和密码进行登录校验
        boolean login = userService.login(user);

        if(!login) {
//        登录失败
            map.put("msg","用户名密码错误!或用户已失效");
            return "login";

        } else {
//            登录成功,防止表单重复提交,可以重定向到主页
            session.setAttribute("loginUser",user.getUsername());
            return "redirect:/main.html";
        }
        }else {
            Emp emp =new Emp();
            emp.setName(user.getUsername());
            emp.setPassword(user.getPassword());
            Emp tbemp = empService.login(emp);
            if(tbemp!=null){
//                登录成功,防止表单重复提交,可以重定向到主页
                session.setAttribute("loginUser",user.getUsername());
                session.setAttribute("lo",tbemp.getId());
                log.info("user为:"+user);
                return "redirect:/dashboard1.html";
后面还有 15 行代码,购买后查看完整代码

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

AI 解读 AI

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

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