我有一个 grails 应用程序,将持久性注释 POJO 用于域模型。Grails 按预期从它们生成控制器和视图,但是一个类对我来说是一个难题。
我需要表示一个字符串集合(目前是字符串的 ArrayList),它是 grails-view '友好'的,并将呈现为下拉列表。
ArrayList 中的数据“相当”恒定,所以我认为 enum 可以用于它,但我不确定。
有问题的班级:
/**
* available categories:
* Airplane
* Rotorcraft
* Glider
* Lighter than air
* Powered lift
* Powered parachute
* Weight-shift-control
*/
@Entity
public class AircraftCategory {
public AircraftCategory(){
this.aircraftCategories.add("Airplane");
this.aircraftCategories.add("Rotorcraft");
this.aircraftCategories.add("Glider");
this.aircraftCategories.add("Lighter Than Air");
this.aircraftCategories.add("Powered Lift");
this.aircraftCategories.add("Powered Parachute");
this.aircraftCategories.add("Weight Shift Control");
}
long id;
private long version;
private ArrayList <String> aircraftCategories = new ArrayList<String>();
public ArrayList <String> getAircraftCategories() {
return aircraftCategories;
}
public void setAircraftCategories(ArrayList <String> aircraftCategories) {
this.aircraftCategories = aircraftCategories;
}
@Id
@GeneratedValue
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getVersion() {
return version;
}
public void setVersion(long version) {
this.version = version;
}
}