How to find out if a project is in debug mode and get a variable of a logical type in the thymeleaf template.
<h1 th:if="${DEBUG}">...</h1>
How to find out if a project is in debug mode and get a variable of a logical type in the thymeleaf template.
<h1 th:if="${DEBUG}">...</h1>
You can achieve this while injecting the Environment
bean to your contorller:
@Controller
@RequestMapping("/public")
public class PublicController {
private final Environment environment;
public PublicController(Environment environment) {
this.environment = environment;
}
@GetMapping("/debug")
public String returnFoo(Model model) {
String envValue = environment.getProperty("debug");
boolean isDebugMode = (envValue != null && !envValue.equals("false"));
model.addAttribute("DEBUG", isDebugMode);
System.out.println(isDebugMode);
return "yourView";
}
}
This is implementation is working for every possible way you might set the debug
flag to your application (How can I tell whether my Spring boot application is in debug mode?)