m0_45846273 2020-10-04 06:51 采纳率: 25%
浏览 69
已采纳

为什么会登录报错啊!!!!快急哭了

package com.baizhi.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class IndexController {
@GetMapping("index")
public String tologin (){
return "login";
}
}

package com.baizhi.controller;


import com.baizhi.entity.User;
import com.baizhi.sercive.UserService;
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.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("login")
    public String login(User user , HttpSession session){
        User userDB=userService.login(user);
        if(userDB!=null){
            session.setAttribute("user",userDB);
            return "redirect:/file/showAll";
        }else{
            return "redirect:/index";
        }
    }
}

```<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
</head>
<body>

<h1>欢迎访问用户文件管理系统</h1>
<form th: action="@{/user/login}" method="post">

    username: <input type="text" name="username" /> <br>
    password: <input type="text" name="password" /> <br>
    <input type="submit" value="登录">

</form>
</body>
</html>

![图片说明](https://img-ask.csdn.net/upload/202010/04/1601765323_725462.png)![图片说明](https://img-ask.csdn.net/upload/202010/04/1601765332_61080.png)![图片说明](https://img-ask.csdn.net/upload/202010/04/1601765337_610847.png)
  • 写回答

1条回答 默认 最新

  • threenewbee 2020-10-04 09:09
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入