springboot 简单的登录(不带数据库)
2021/12/15 2:22:27
本文主要是介绍springboot 简单的登录(不带数据库),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
项目结构
看一眼config包下的MyMvcConfig类 不用写也会 localhost:8080自动找index页面并跳转
//自己对mvc的一些配置,虽然springboot帮我们配置了,但是有些我想弄成别的样的所以得自己配一下 @Configuration public class MyMvcConfig implements WebMvcConfigurer { @Override public void addViewControllers(ViewControllerRegistry registry) { //这样的话我在浏览器的地址栏打"/"或者"/index.html"都会跳转到index(首页) 虽然直接写localhost:8080也能自动跳转到首页 registry.addViewController("/").setViewName("index"); registry.addViewController("/index.html").setViewName("index"); } }
Controller
@Controller public class LoginController { // @RequestMapping("/user/login") // public String login(User user){ // if (user.username == "hi" || user.userpassword == "hi"){ // return "dashboard"; // }else { // model.addAttribute("msg","登陆失败"); // return "index"; // } // } @RequestMapping("/user/login") public String login(@RequestParam("username") String username, @RequestParam("userpassword") String userpassword, Model model){ if (username == "hi" || userpassword == "hi"){ return "dashboard"; }else { model.addAttribute("msg","登陆失败"); return "index"; } } }
前端页面
thymleaf的头
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
这篇关于springboot 简单的登录(不带数据库)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-28AI给的和自己写的Python代码,都无法改变输入框的内容,替换也不行
- 2024-09-27Sentinel配置限流资料:新手入门教程
- 2024-09-27Sentinel配置限流资料详解
- 2024-09-27Sentinel限流资料:新手入门教程
- 2024-09-26Sentinel限流资料入门详解
- 2024-09-26Springboot框架资料:初学者入门教程
- 2024-09-26Springboot框架资料详解:新手入门教程
- 2024-09-26Springboot企业级开发资料:新手入门指南
- 2024-09-26SpringBoot企业级开发资料新手指南
- 2024-09-26Springboot微服务资料入门教程