玩2.2.1 Java Ebean-Finder.select(字符串列)不';t工作:所有列都已选中
我在使用ebean和Play时遇到了对象的select函数的问题!框架(2.2.1) 我有我的桌子退火运动:玩2.2.1 Java Ebean-Finder.select(字符串列)不';t工作:所有列都已选中,java,playframework,ebean,Java,Playframework,Ebean,我在使用ebean和Play时遇到了对象的select函数的问题!框架(2.2.1) 我有我的桌子退火运动: CREATE TABLE AnneePromotion ( anneePromotion_ID INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('AnneePromotionSequence'), anneePromotion_libelle INTEGER NOT NULL ); @Entity @Table(name = "Ann
CREATE TABLE AnneePromotion (
anneePromotion_ID INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('AnneePromotionSequence'),
anneePromotion_libelle INTEGER NOT NULL
);
@Entity
@Table(name = "AnneePromotion")
@SequenceGenerator(name = "AnneePromotionSequenceGenerator", sequenceName = "AnneePromotionSequence")
public class AnneePromotion extends Model {
/** serial ID */
private static final long serialVersionUID = -2072489268439045171L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "AnneePromotionSequenceGenerator")
@Column(name = "anneePromotion_ID")
private Integer id;
@Column(name = "anneePromotion_libelle")
private String libelle;
public Integer getId() {
return id;
}
public String getLibelle() {
return libelle;
}
public void setLibelle(String libelle) {
this.libelle = libelle;
}
public static Finder<Integer, AnneePromotion> find = new Finder<Integer, AnneePromotion>(
Integer.class, AnneePromotion.class);
}
我的实体AnneePromotion:
CREATE TABLE AnneePromotion (
anneePromotion_ID INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('AnneePromotionSequence'),
anneePromotion_libelle INTEGER NOT NULL
);
@Entity
@Table(name = "AnneePromotion")
@SequenceGenerator(name = "AnneePromotionSequenceGenerator", sequenceName = "AnneePromotionSequence")
public class AnneePromotion extends Model {
/** serial ID */
private static final long serialVersionUID = -2072489268439045171L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "AnneePromotionSequenceGenerator")
@Column(name = "anneePromotion_ID")
private Integer id;
@Column(name = "anneePromotion_libelle")
private String libelle;
public Integer getId() {
return id;
}
public String getLibelle() {
return libelle;
}
public void setLibelle(String libelle) {
this.libelle = libelle;
}
public static Finder<Integer, AnneePromotion> find = new Finder<Integer, AnneePromotion>(
Integer.class, AnneePromotion.class);
}
我不知道选择功能是否起作用,我是否犯了愚蠢的错误:/
希望你能帮助我
您好,Anthony。这是Ebean的常见行为,原因很简单:您请求的是具体类型的对象列表,因此它不能只返回字符串列表(没有
id
),因为它需要以某种方式标识行
最简单的解决方案是将其改写为新列表
List<String> libelles = new ArrayList<>();
for (AnneePromotion anneepromotion : listeDesAnneesdePromotion){
libelles.add(anneepromotion.getLibelle());
}
List libelles=new ArrayList();
对于(退火推进退火推进:ListedAnneesDePromotion){
add(anneepromotion.getLibelle());
}
您还可以选择使用Ebean,然后遍历
要获得相同的
libelles
list.BTW,为什么不在模型中使用公共字段?您不需要创建getter和setter。我不喜欢公共字段^^谢谢,我会这样做,然后尝试SqlQuery