SpringBoot+Thymeleaf: Property or field 'name' cannot be found on object of type

lucas :

I would like to show the Objects in the HTML File with Thymeleaf but it says "Property or field 'name' cannot be found on object of type 'com.example.demo.Entities.PeopleInformation' - maybe not public or not valid?"

That's my Controller for the Page

package com.example.demo.Controller;

import java.util.ArrayList;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.Entities.PeopleInformation;

@Controller
public class HelloWorld {

    @GetMapping(value= "/list_contacts")
    public String showContacts(Model m){
        ArrayList<PeopleInformation> kontakte = new ArrayList<PeopleInformation>();
        PeopleInformation a = new PeopleInformation("Lutz","Walter","0152 222556","Aktuell");
        PeopleInformation b = new PeopleInformation("Bosch","Holger","0152 567345","Aktuell");
        PeopleInformation c = new PeopleInformation("Schindler","Nicole","0152 220022","Aktuell");
        kontakte.add(a);
        kontakte.add(b);
        kontakte.add(c);
        m.addAttribute("kontakte",kontakte);
        return "list_contacts";
    }
}

That's the Entity using Lombok

package com.example.demo.Entities;

import org.springframework.data.annotation.Id;

import com.microsoft.spring.data.gremlin.annotation.Vertex;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@NoArgsConstructor @Setter @Getter 
public class PeopleInformation {
    @Id
    private Long id;
    private String name;
    private String vorname;
    private String telefon;
    private String status;

    public PeopleInformation(String name,String vorname,String telefon,String status) {
        this.name = name;
        this.vorname = vorname;
        this.telefon = telefon;
        this.status = status;
    }
}

And that's my HTML File with Thymeleaf

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="ISO-8859-1">
<title>Kontakt-Liste</title>
</head>
<body>
     <div>
         <table border="1">
            <tr>
               <th>Name</th>
               <th>Vorname</th>
               <th>Telefon</th>
               <th>Status</th>
            </tr>
            <tr th:each ="kontakte : ${kontakte}">
               <td th:utext="${kontakte.name}">...</td>
               <td th:utext="${kontakte.vorname}">...</td>
               <td th:utext="${kontakte.telefon}">...</td>
               <td th:utext="${kontakte.status}">...</td>
            </tr>
         </table>
      </div>
</body>
</html>

Can someone spot the Problem, Thanks :)

Wolobi :

if you want to see data you should declare the getters in the PeopleInformation entity

Like this:

    public Long getId() {
    return id;
}

public String getName() {
    return name;
}

public String getVorname() {
    return vorname;
}

public String getTelefon() {
    return telefon;
}

public String getStatus() {
    return status;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=16645&siteId=1