Springboot 整合 html,有些小伙伴们参与的项目不是前后端分离的,或者需要一些中转页去做,jsp的方式之前分享过了,现在分享一下html标签的方式。
项目下载地址:https://download.csdn.net/download/qq_27535933/11435600
博客地址:https://blog.csdn.net/qq_27535933/article/details/97397582
创建项目的步骤就省略的。。。。。。
Springboot 整合 html应用工具:Springboot gradle-4.6 java-8
首先我们引包
plugins {
id 'org.springframework.boot' version '2.1.6.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
新增配置:
#端口号
server.port=8080
# 配置
spring.thymeleaf.prefix=classpath:/templates/
在templates下创建创建一个html标签
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8"/>
<title>Hello World!</title>
</head>
<body>
Hello World!
</body>
</html>
写一个测试类
package com.example.rest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @author YanChengLong
* @date 2019/7/25
* @desc 测试
*/
@Controller
public class Test {
@RequestMapping("/test")
public String test(){
return "/index";
}
}
项目的目录结构:
小伙伴们有哪些问题或者意见,请私信或者与我联系,感谢