Now I'm working on java using spring framework spring boot version = '1.5.9.RELEASE'. But every time I run my web app it gives me
org.springframework.beans.NotReadablePropertyException: Invalid property 'id' of bean class [java.util.ArrayList]: Bean property 'id' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter? at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:631) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:622) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.servlet.support.BindStatus.(BindStatus.java:149) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.thymeleaf.spring4.util.FieldUtils.getBindStatusFromParsedExpression(FieldUtils.java:401) ~[thymeleaf-spring4-2.1.6.RELEASE.jar:2.1.6.RELEASE]
my User class is
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class User {
@Id
private int id;
private String name;
private int age;
public User() {
}
public User(int id, String name, int age) {
this.id = id;
this.name = name;
this.age = age;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
my controller class is
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
@Controller
public class UserController {
@Autowired
private UserService userService;
@RequestMapping(value = "/")
public String display(ModelMap modelMap){
User user = new User(1, "Endriyas", 21);
userService.addUser(user);
List<User> users = userService.getAllUser();
modelMap.put("users", users);
return "users";
}
}
and my HTML form is
<div>
<form action="#" th:action="@{/}" th:object="${users}" method="post">
<div>
<label>
<span>ID</span>
</label>
<input type="number" th:field="*{id}"/>
</div>
<div>
<label>
<span>Name</span>
</label>
<input type="text" th:field="*{name}"/>
</div>
<div>
<label>
<span>Age</span>
</label>
<input type="number" th:field="*{age}"/>
</div>
<div>
<button type="submit" name="save">SAVE</button>
</div>
</form>
</div>
I need help
Thanks
User
object or opposite? – Sergey Prokofiev