Spring boot + thymeleaf in IntelliJ: cannot resolve vars

后端 未结 8 1162
清酒与你
清酒与你 2021-02-05 02:44

I\'m writing a short web form application using spring boot and thymeleaf on IntelliJ, but it seems that in the html file, all fields in the model cannot be resolved. Here is my

8条回答
  •  野的像风
    2021-02-05 03:04

    1. If your IntelliJ version is < 2017.3, it is, as Andrew wrote, a known error IDEA-132738. There is a workaround how to get rid of the error marks in the IDE. IntelliJ also supports the semi-automatic generation of the below mentioned code:

    You can use Alt+Enter shortcut to invoke intention "Declare external variable in comment annotation" in order to get rid of "unresolved model attribute" in your views.

    Add the following code to your html file:

    
        
        
        
    
    

    If you use extensions objects constructed automatically by ThymeLeaf, such as #temporals from thymeleaf-extras-java8time for conversion of java.time objects:

    
    

    and IntelliJ cannot resolve them, use similar code, and just add # in front of the object name:

    
    
    1. If your IntelliJ version is >= 2017.3 (however some people complain that it still does not work for them), the issue IDEA-132738 should be fixed (@FloatOverflow: "I confirm that in version 2017.3 build 25.Oct.2017 the problem has been solved"):

    Status 2017.3

    Support for Spring Boot autoconfigured MVC applications is complete, all bundled autoconfiguration view types are supported.

    Fix versions: 2017.3

提交回复
热议问题