springboot实现登录界面

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

提示:这里可以添加本文要记录的大概内容:
例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。


提示:以下是本篇文章正文内容,下面案例可供参考

一、springboot是什么?

简单来说:它是一个服务于spring框架的框架,能够简化配置文件,快速构建web应用, 内置tomcat,无需打包部署,直接运行。

核心原理:自动装配

二、如何创建springboot登陆界面

1.在bootstore下载一个index登陆界面,好多都是免费的,

这里放置静态资源
在这里插入图片描述
html页面放在templates模板里里面
在这里插入图片描述

代码如下(示例):

2.配置config

在config包下面创建
在这里插入图片描述
用来访问跳转

代码如下(示例):

3.写controller登录控制类

在这里插入图片描述

4.修改index.html里面的超链接

springboot有专门的模板:
在这里插入图片描述
依据上面的可以看出 要用@{} 的形式修改

修改的方面  :
 一:

在这里插入图片描述
要加上这段, “en” 表示用中文
二:
在这里插入图片描述

修改类似的连接 ,要加上th 标签和 @{}
原始的<link rel=“stylesheet” href=“css/style2.css”

最后运行就行了:
在这里插入图片描述

在这里插入图片描述

!](https://img-blog.csdnimg.cn/20210407192905362.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81MjUxNDU2Nw==,size_16,color_FFFFFF,t_70)

该处使用的url网络请求的数据。


总结

如果运行出现异常的话 如:500 多半是pom依赖错了 多换几个版本 最新的最好,亲测有效
  • 2
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
对于Spring Boot登录界面,你可以使用Spring Security来实现。下面是一个简单的示例代码: 首先,在pom.xml文件中添加Spring Security的依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> ``` 然后,创建一个登录面的HTML模板(例如login.html),并放置在src/main/resources/templates目录下: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Login</title> </head> <body> <h1>Login</h1> <form action="/login" method="post"> <div> <label for="username">Username:</label> <input type="text" id="username" name="username"> </div> <div> <label for="password">Password:</label> <input type="password" id="password" name="password"> </div> <div> <button type="submit">Login</button> </div> </form> </body> </html> ``` 接下来,在Spring Boot应用程序的配置类(如Application.java)上添加@EnableWebSecurity注解,并实现一个WebSecurityConfigurerAdapter: ```java import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/login") .permitAll() .anyRequest() .authenticated() .and() .formLogin() .loginPage("/login") .defaultSuccessUrl("/home") .permitAll() .and() .logout() .permitAll(); } @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser("user") .password("{noop}password") // 添加 {noop} 前缀表示密码不加密,仅用于示例 .roles("USER"); } } ``` 在这个示例中,配置类中的configure方法定义了访问权限和登录面的路径。configureGlobal方法定义了一个简单的用户认证。 最后,在控制器中添加处理登录请求的方法: ```java import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @Controller public class LoginController { @GetMapping("/login") public String login() { return "login"; } } ``` 这样就完成了一个简单的Spring Boot登录界面实现。用户访问"/login"路径时会显示login.html面,输入用户名和密码后可以登录
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值