springboot用controller跳转html页面的实现
作者:minolk 时间:2022-08-15 06:57:51
在学习SpringBoot的过程中遇到一个问题,因为SpringBoot是集成了tomcat的,所以项目是打成jar包,通过SpringMVC注解的方式去运行的,所以静态页面就放在maven工程的resources目录下的templates目录下所以怎么去跳转是个问题,现在就是解决这个问题
首先看项目结构
pom.xml文件依赖
<!-- 1.创建一个Maven工程,选择jar类型项目2.引入SpringBootMaven依赖。 -->
<!-- Maven parent 目的,聚合工程、继承关系 -->
<!--Spring parent 目的: 统一整合第三方框架依赖信息 (SpringBoot 支持依赖 不需要写版本号) -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>
<dependencies>
<!-- -springboot 整合Web组件 整合SpringMVC 就会把传统方式的SpringMVC依赖的jar全部给下载来 -->
<!-- 引入spring-boot-starter-web 帮你整合好所有相关的依赖jar包 原理 maven依赖传递 -->
<!-- 原理: spring-boot-starter-parent< 中,整合号相关 jar依赖信息 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
controller代码,这里为了更加的清楚项目结构带上包的路径
package cn.hd.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class FTLIndexController {
@RequestMapping("/ftlIndex")
public String ftlIndex() {
System.out.println("fff");
return "user/index";
}
}
html代码直接截图
访问页面
application.properties配置文件中不需要写任何东西
来源:https://blog.csdn.net/minolk/article/details/81750304
标签:springboot,controller,html
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
iOS新浪微博、腾讯微博分享功能实例
2023-06-16 09:15:53
![](https://img.aspxhome.com/file/2023/0/101960_0s.png)
Spring-Bean创建对象的步骤方式详解
2023-04-12 22:00:47
Android 微信摇一摇功能实现详细介绍
2023-06-21 21:00:09
详解Java的回调机制
2023-07-27 07:17:43
![](https://img.aspxhome.com/file/2023/7/60657_0s.png)
Java 从互联网上爬邮箱代码示例
2022-02-27 16:40:57
centos 安装java环境的多种方法
2023-08-10 16:01:37
Java super关键字的使用详解
2021-11-30 13:40:43
![](https://img.aspxhome.com/file/2023/0/60780_0s.jpg)
java获取包下被指定注解的类过程解析
2023-08-08 11:12:27
SpringCloud Feign转发请求头(防止session失效)的解决方案
2022-08-29 12:25:59
java8中:: 用法示例(JDK8双冒号用法)
2023-11-25 06:21:21
Android自定义attr的各种坑
2023-07-12 06:11:50
Java如何去掉指定字符串的开头的指定字符
2022-05-23 13:28:31
JVM代码缓存区CodeCache原理及用法解析
2023-08-09 06:02:29
![](https://img.aspxhome.com/file/2023/8/61768_0s.jpg)
Logback日志基础及自定义配置代码实例
2022-09-04 01:01:41
Scala方法与函数使用和定义详解
2021-10-05 06:34:12
mybatis-spring:@MapperScan注解的使用
2021-11-22 09:58:33
![](https://img.aspxhome.com/file/2023/0/75410_0s.png)
SpringBoot上传文件大小受限问题的解决办法
2023-04-19 09:46:16
![](https://img.aspxhome.com/file/2023/9/63629_0s.jpg)
Android RecyclerView基本使用详解
2023-07-24 21:13:30
![](https://img.aspxhome.com/file/2023/6/86016_0s.gif)
基于Spring AOP proxyTargetClass的行为表现总结
2022-05-23 18:33:43
详解SpringBoot使用RedisTemplate操作Redis的5种数据类型
2022-12-03 07:35:29
![](https://img.aspxhome.com/file/2023/0/75010_0s.png)