yml配置跳转html,springboot项目添加html

1.application.yml 配置

spring:

thymeleaf:

prefix: classpath:/templates/

suffix: .html

mode: LEGACYHTML5

cache: false

server:

port: 29000

2.pom.xml配置

org.springframework.boot

spring-boot-starter-thymeleaf

3.controller写法

package com.xjn.demo.controller;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

@Controller

public class PageController {

//通过controller返回html界面

@RequestMapping("/test")

public String testJumpPage(){

return "test";

}

//通过controller返回html界面

@RequestMapping("/index")

public String indexJumpPage(){

return "index";

}

}

4.html写法,html位置:demo\src\main\resources\templates\index.html

demo\src\main\resources\templates\test.html

index.html

spring boot web project
spring boot web project index.html

a123.jpg

test.html

spring boot web project
==================spring boot web project test=======================

5.启动项目,浏览器访问html,通过controller返回html界面:

http://localhost:29000/index

http://localhost:29000/test

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot是一个流行的Java框架,它简化了构建生产级应用程序的过程,特别是对于那些基于Web的应用。在Spring Boot中实现登录和注册功能,通常会用到Spring Security模块,这是一个强大的安全框架,可以帮助处理身份验证和授权。 以下是Spring Boot项目中实现登录注册的基本步骤: 1. **设置依赖**: 首先,在`pom.xml`或`build.gradle`文件中添加Spring Security的依赖。 2. **配置Spring Security**: 在`application.properties`或`application.yml`中配置Spring Security的基本属性,如HTTP端点保护、密码编码规则等。 3. **创建用户模型**(User Model): 定义一个User实体类,含用户名、密码和其他必要的字段(如邮箱、角色等)。 4. **注册/登录控制器**(Controller): 使用Spring Security的`@RestController`和`@PostMapping`创建API接口,接收用户提交的注册和登录请求。 5. **视图重定向**: 创建HTML模板用于显示登录/注册表单,并配置视图解析器,以便在用户成功登录或注册后跳转到相应的页面。 6. **实现认证逻辑**: 实现`UserDetailsService`接口来加载用户数据,以及`PasswordEncoder`接口来处理密码加密。 7. **表单验证**: 使用`@Valid`注解和`@NotBlank`等验证注解来确保输入数据的正确性。 8. **错误处理**: 设置异常处理器来处理未授权访问或其他错误情况。 9. **配置Thymeleaf或FreeMarker等模板引擎**: 显示登录失败消息或者成功提示。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值