【发布时间】:2020-06-10 17:02:48
【问题描述】:
我有一个要求,我想通过 Thymeleaf 使用 React 代码。 我使用 create-react-app 和 npm start 工作正常。没有添加任何其他代码。 这是我的设置- src\main\resources\templates\index.html
<!DOCTYPE HTML>
<html>
<head>
<title>Getting Started: Serving Web Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="/css/main.5f361e03.chunk.css" rel="stylesheet">
<script src="/js/2.b38996be.chunk.js"></script>
<script src="/js/main.8a01ac9e.chunk.js"></script>
</head>
<body>
<div class="root"></div>
</body>
</html>
你可以看到我在上面链接了我的 React 和 CSS 构建代码。
src\main\resources\static 这个位置有css、js、媒体文件夹
当我转到http://localhost:8080/ 时,前端是空的。
这是我的 pom 文件。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.test</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
链接到 Github 项目- https://github.com/kedarnadkarny/springreact
【问题讨论】:
标签: java reactjs spring spring-boot thymeleaf