Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to map Spring controllers to their thymeleaf views(intellij14)

I am trying to configure spring boot thymeleaf and intellij, and for the most part have nailed it, but I cant seem to be able to link controllers with their views, as intellij annoyingly keeps displaying the following message, and the auto-completing the system is not working:

Cannot Resolve 'varName'

my controller looks like this "main/java/..../controller.java"

@Controller
public class CardsController {

    @RequestMapping(value="/card/{id}",method = RequestMethod.GET)
    public String viewCardAction(@PathVariable("id") Card card,Model model){
        model.addAttribute("card",card);
        return "cards/view";
    }
}

And this is my mockup view "main/resources/cards/view/cards/view":

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
    <meta charset="UTF-8"/>
    <title th:text="${card.name}"></title> <!-- this line shows the message -->
</head>
<body>
    <div th:text="${card.name}"></div> <!-- this line shows the message -->
</body>
</html>

is it that intelij, is still not working for this, or am I missing some configuration

NOTE: it works and compiles, just wanna enable autocomplete

like image 350
Ricardo Garza V. Avatar asked Oct 23 '14 03:10

Ricardo Garza V.


People also ask

How does Thymeleaf pass value from view to controller?

First thing first, you need to bind your modelattribute to a th:object in your form as this: ModelAttribute("personList") then in your form your have this th:object="${personList}". Number 2: You will need a name attribute on your form in other to let thymeleaf bind your form input to your object attributes.

Is Thymeleaf view resolver?

The ViewResolver interface in Spring MVC maps the view names returned by a controller to actual view objects. ThymeleafViewResolver implements the ViewResolver interface, and it's used to determine which Thymeleaf views to render, given a view name.

Is Thymeleaf supported by Spring MVC?

Thymeleaf offers a set of Spring integrations that allow you to use it as a fully-featured substitute for JSP in Spring MVC applications.


1 Answers

Looks like this is a bug in Intellij.

Here's the youtrack link: https://youtrack.jetbrains.com/issue/IDEA-132738

It hasn't gotten much attention from the JetBrains developers yet so you may want to add your comments or vote it up there.

like image 77
cmorris Avatar answered Oct 18 '22 10:10

cmorris