SpringBoot搭建一个简单员工管理系统 (3) 登录功能实现
编写登录控制类
由于还没有加入数据库 默认密码123456成功
package com.jie.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class LoginController {
@RequestMapping("/usr/login")
public String login(@RequestParam("username") String username, @RequestParam("password") String password, Model model){
//具体的业务:
if("123456".equals(password)){
return "dashboard";
}
else {
model.addAttribute("msg","用户名密码错误!");
return "index";
}
}
}
在index.html插入这句话使得登录失败显示信息
`<p style="color: red" th:text="${msg}" th:if="${not #strings.isEmpty(msg)}"></p>`

浙公网安备 33010602011771号