2

我看到了一些类似的问题,但我无法真正理解任何答案。我在从表单中获取列表时遇到问题。我一直在这样做:

@Entity
public class Foo extends Model {
@Id
public Long id;

@Required
@Valid
@ManyToMany
public static List<Bar> bars = new ArrayList<Bar>();
}

@Entity
public class Bar extends Model{
    @Id
public int id;

@Required
public String name;
        // @Required
@Valid
@ManyToMany
public static List<Foo> foo = new ArrayList<Foo>();
}

我试图根据我读过的答案制作界面

@form(routes.Application.newFoo()) {
<select multiple name = "bar[].name">
        <option name = "bars[].name" value="option1">Option1</option>
        <option name = "bars[].name" value="option2">Option2</option>
        <option name = "bars[].name" value="option3">Option3</option>
    </select>
...
}

但是当我尝试做 FormfilledForm = fooForm.bindFromRequest();

    if (filledForm.hasErrors()) {
        return badRequest(views.html.index
                .render(Problem.all(), filledForm));
    } else {
        Foo foo = filledForm.get();

foo 获取所有其他属性,但列表始终为空。我应该怎么办?

4

0 回答 0