gpt4 book ai didi

java - 将 ReactJS 前端添加到我的 REST API

转载 作者:行者123 更新时间:2023-11-30 10:42:52 25 4
gpt4 key购买 nike

我真的是前端开发的新手。我创建了一个 maven 项目并使用 spring boot 框架完成了我的 REST API 入口点的定义。我想在项目中添加一个使用 reactJS 的基本前端。所以我从基本的 html 欢迎开始。我添加了一个 war/WEB-inf/index.jsp 欢迎页面:

<html>
<head><title>Example</title></head>
<body>
<h1>Example</h1>
<p>This is my test.</p>
</body>
</html>

还有一个war/WEB-inf/web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >

<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>

</web-app>

尝试通过转到 localhost:8080 访问该页面

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue Jun 21 12:33:05 CEST 2016
There was an unexpected error (type=Not Found, status=404).
No message available

我会很感激一些帮助

最佳答案

如果你只想提供静态内容并且你正在使用 Spring boot,你可以简单地在 src/main/resources/public 中创建一个 index.html 文件> 或 src/main/resources/static 目录。如果您只打算使用 React(或任何其他 JavaScript 框架),则此设置应该有效。只需在此文件夹中添加所有 JavaScript/CSS/HTML。

如果你需要一个动态的 HTML 页面(例如使用 JSP/JSTL),你可以将它添加到 src/main/resources/templates 文件夹,但是你可能必须定义使用 index.jsp 模板文件的 Controller 。

您也不需要 Web 描述符 (web.xml),因此您可以将其删除。

关于java - 将 ReactJS 前端添加到我的 REST API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37942111/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com