I have one of my spring boot application and inside my application.properties there is one of the property is url=myurl.net
.
In the same application I have one thyme leaf html template. I wanted to get the url value into that template. I am using the following code inside the thymeleaf html template <font face=arial size=2 > access the url : </font> ${environment.getProperty(‘url’)}
Output I am getting :
access the url : $(environment.getProperty(‘url’)}
Output I am expecting:
access the url : myurl.net
Instead of actual value I am getting the same text. Can someone please help me on this. Appreciate your help.
Using session Object${session.name} will return the value of the name attribute stored in the current session. If no attribute with the specified name is found in the session, it will return null .
You just change @RequestParam to @Valid in your controller then change your select name to "task" in Thymeleaf and it should be into the form wrapper.
We can use the th:with attribute to declare local variables in Thymeleaf templates. A local variable in Thymeleaf is only available for evaluation on all children inside the bounds of the HTML tag that declares it.
You have to use
${@environment.getProperty('css.specific.name')}
this will fetch css.specific.name
property from the application.properties
file.
Map your prop value in your controller, and call it directly from Thymeleaf template.
@Controller
public class XController {
@Value("${pcn.app.url}")
private String url; // Directly instead of using envireonment
@RequestMapping(value = "form-show", method = RequestMethod.GET)
public ModelAndView showForm() {
ModelAndView model = new ModelAndView();
model.setViewName("your-view");
// The key which will look in your HTML with.
model.addObject("urlValue", url);
return model;
}
}
In your html normally call it like this
<html>
<body>
<span th:text="#{urlValue}"></span>
</body>
</html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With