Thymeleaf in IntelliJ: cannot resolve variables

user9816511 :

Intellij Not Recognizing Model Variables in HTML. How to resolve model variables. I don't get any idea for this issue.

Here is my Controller

@Controller 
public void someController {
  @RequestMapping("/")
  public String someMethod() {
    model.addAttribute("message", "message");
    return "index";
}

And here is my "index.html"

<p th:text="${message}"> </p>

and of course in my html tag i'm using thymeleaf :

<html xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/html">

the problem is in myth:text="${message}" i see red squiggly lines saying that "Cannot resolve "message" variable..."

TwiN :

I've been ignoring that issue for as long as I've been using Thymeleaf. Even though it shows the squiggly lines, it should still work when you run the application.

IntelliJ would almost have to compile the code in the background to be able to automatically (and accurately, since you could have multiple methods who uses the same template) resolve the variables.

I've never given a tip like this, but after reading your comment that you just find the wiggly line annoying, I decided to suggest it anyways:

Disable the tip.

configure inspections

disable expression variables validation

I feel absolutely barbaric for posting this answer, forgive me SO

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=467677&siteId=1