Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing data into html from Java via Spring

Tags:

java

spring

Is there a way to pass a String value from my Spring controller class to my HTML? In various "hello world" examples, they say to use

ModelAndView model = new ModelAndView("htmlPageName");
model.addAttribute("variableName", "someValue");

in the controller and

${variableName}

in the HTML. But when I load the page it shows literally ${variableName} instead of "someValue"

Am I missing something?

like image 902
Andrew Torr Avatar asked May 23 '18 09:05

Andrew Torr


People also ask

Can we write html code in spring boot?

This is a very basic Web Application using Spring Boot that serves a “Hello World” static HTML web page. This will start the embedded Tomcat server at port 8080. The web server is available out of the box with Spring Boot.


Video Answer


1 Answers

If you use Thymeleaf

<h1 th:text="${variableName}"></h1>

You wrote: {$variableName} instead of ${variableName}

like image 185
Rafał Sokalski Avatar answered Oct 05 '22 23:10

Rafał Sokalski