2
2
.
.
1
1
4
4
.
.
2
2
R
R
e
e
a
a
d
d
P
P
r
r
o
o
p
p
e
e
r
r
t
t
y
y
-
-
F
F
r
r
o
o
m
m
H
H
T
T
M
M
L
L
I
I
n
n
f
f
o
o
[
[
R
R
]
]
This tutorial shows how to read Property from application.properties from HTML.
Syntax
<p th:text="${@environment.getProperty('messages.hello')}"/>
Application Schema [Results]
Spring Boot Starters
GROUP
DEPENDENCY
DESCRIPTION
Web
Spring Web
Enables @Controller, @RequestMapping and Tomcat Server.
Template Engines
Thyemeleaf
Enables Controller to return reference to HTML file test.html
P
P
r
r
o
o
c
c
e
e
d
d
u
u
r
r
e
e
Create Project: properties_read_fromhtml (add Spring Boot Starters from the table)
Edit File: application.properties (inside src/main/resources)
Create Package: controllers (inside package com.ivoronline.test_spring_boot)
Create Class: MyController.java (inside package controllers)
Create HTML File: Test.html (inside directory resources/templates)
application.properties
messages.hello = Hello from Controller
MyController.java
package com.ivoronline.properties_read_fromhtml.controllers;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
@Controller
public class MyController {
@RequestMapping("/Hello")
public String hello() {
System.out.println("Hello from Controller");
return "Test";
}
}
Test.html
<title>Test.html</title>
<p th:text="${@environment.getProperty('messages.hello')}"/>
<form th:attr="action=${@environment.getProperty('form.action')}" method="get"/>
MyController
http://localhost:8080/Hello
hello()
Test.html
Browser
Tomcat
R
R
e
e
s
s
u
u
l
l
t
t
s
s
http://localhost:8080/Hello
Page Source
<title>Test.html</title>
<p> Hello from Controller </p>
<form action="http://localhost:8080/AddAuthor" method="get"/>
Console
Hello from Controller
Application Structure
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>