'"Cannot resolve ..." / The IDE can't find some of the data i would like to have in the html-file / Springboot, Java
I think i've done almost all of the things I have to, but somehow it isn't working. I want the blog.html file to get all of the data from the maincontroller I programmed. I also made a Class with a constructor, and all I need is that I should get the data from those other files. It also want it to make another div-tag for each blog. My question now is, why isn't it getting the data? It doesn't get blog.title, blog.... and when I hover over it, it says: "Cannot resolve title or ...",
I'd appreciate your help.
Here's the code: // blog.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="de-ch">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Title</title>
</head>
<body>
<div th:each="blog: ${blogEntries}"> //blogEntries is marked red
<h2 th:text="${blog.title}"></h2> //title is marked red
<p th:text="${blog.text}"></p> //text, author is marked red
<p th:text="${blog.author}"></p> //for all it says: "Cannot resolve '...'"
</div> //only "blog" isn't marked red
</body>
</html>
// MainController.java
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.ArrayList;
@Controller
public class MainController {
@GetMapping("") // "" = URL
public String home() {
return "index";
}
@GetMapping("/blog")
public String blog(Model model){
ArrayList<BlogEntry> blogEntries= new ArrayList<>();
BlogEntry blog1 = new BlogEntry("Pizze Caprese", "This Caprese Pizza is a 30-minute dinner that everyone in your family will enjoy. Made with homemade basil sauce, tomatoes, and mozzarella, it is light and delicious. Make it for summer picnics with a simple salad on the side and accept the compliments.", "The Wok");
BlogEntry blog2 = new BlogEntry("Sandwich Caprese", "Sandwich all of that inside a crusty loaf of French baguette, and you will have a perfectly portable sandwich for picnics or road trips. Or, enjoy it at home for a quick meal from now through the end of tomato season this fall.", "John Xina");
BlogEntry blog3 = new BlogEntry("Spaghetti al Pesto", "Simple, simple, simple! That what this delicious spaghetti al pesto is! Just throw your herbs in the food processor and go. Spaghetti al Pesto is great garnished with a wide variety of veggies. Try it with tomatoes, fresh herbs, mushrooms, zucchini, or eggplant.", "Baba Chun");
blogEntries.add(blog1);
blogEntries.add(blog2);
blogEntries.add(blog3);
model.addAttribute("blog", blogEntries);
return "blog";
}
}
// BlogEntry.java
import org.apache.tomcat.jni.Local;
import java.time.LocalDate;
public class BlogEntry {
private String title;
private String text;
private String author;
private LocalDate publicationDate;
BlogEntry(String title, String text, String author){
this.title = title;
this.text = text;
this.author = author;
}
private String getTitle(){
return title;
}
private void setTitle(String title){
this.title = title;
}
private String getText(){
return text;
}
private void setText(String text){
this.text = text;
}
private String getAuthor(){
return author;
}
private void setAuthor(String author){
this.author = author;
}
private LocalDate getPublicationDate(){
return publicationDate;
}
private void setPublicationDate(LocalDate publicationDate){
this.publicationDate = publicationDate;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
