Java Springboot 中的服务器端渲染 React [英] Server side rendering React in Java Springboot

查看:51
本文介绍了Java Springboot 中的服务器端渲染 React的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是服务器端渲染的新手 &我想在服务器端渲染 React 组件并在 html 中传递它.

I'm new to server side rendering & I want to render React components on server side and pass down it in html.

我在 https://spring.io/上遵循了本教程指南/教程/react-and-spring-data-rest/.它仍在客户端呈现.

I followed this tutorial on https://spring.io/guides/tutorials/react-and-spring-data-rest/. It is still rendering on client.

我找不到在 thymeleaf 模板中执行 renderToString 的方法.

I cannot find a way to do renderToString in the thymeleaf template.

我该怎么做?

推荐答案

使用 Nashorn 你可以做到,Nashorn 是一个默认用 Java 打包的 JavaScript 引擎.

Using Nashorn you can do, Nashorn is a JavaScript engine packaged by default with Java.

Nashorn 已作为 Java 8 的一部分发布.这主要侧重于允许在 Java 中嵌入 JavaScript 应用程序.

Nashorn has been released as part of Java 8. This is primarily focused on allowing embedded JavaScript applications in Java.

Nashorn 将内存中的 JavaScript 编译为 Java 字节码,并将其传递给 JVM 执行.

Nashorn compiles JavaScript in-memory to Java Bytecode and passes it to the JVM for execution.

更多详情,您可以查看以下链接:-

And more details you can check below link:-

https://www.baeldung.com/react-nashorn-isomorphic-app.

**

Nashorn 现已弃用,因此您可以为此使用 GraalVM

**

https:///medium.com/graalvm/improve-react-js-server-side-rendering-by-150-with-graalvm-58a06ccb45df

这篇关于Java Springboot 中的服务器端渲染 React的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆