does thymeleaf support auto binding form 1:n relation?

Question!

There are two entities User, Group. Group has many users.

User.java

@ManyToOne
@JoinColumn(name="group_id")
private Group group;

public Group getGroup() {
    return group;
}

public void setGroup(Group group) {
    this.group = group;
}

Group.java

@OneToMany(mappedBy="group")
private List<User> users;

public List<User> getUsers() {
    return users;
}

public void setUsers(List<User> users) {
    this.users = users;
}

form.html

<form th:object="${user}" class="form-horizontal" role="form"th:action="@{${#httpServletRequest.servletPath}}" method="post">
    <label for="group****????" class="col-sm-2 control-label">Group: </label>
    <input type="text" name="group****??????" required="required" />
 ...</form>

I want to bind group_id automatically. But I don't know getter, setter about group and group_id and pass parameters to controller.



Answers


This video can help you solving your question :)
By: admin