public List<MemberEntity> getMember() {
EntityManagerFactory entityManagerFactory = Persistence
.createEntityManagerFactory("PrimeEclipseLink");
EntityManager entityManager = entityManagerFactory
.createEntityManager();
Query query = entityManager
.createNativeQuery("Select * FROM member");
memberEntities = (List<MemberEntity>)query.getResultList();
return memberEntities;
}
我想从数据库中填充我的数据库。但它不起作用请帮助我:)当我点击列表按钮表填充像picture.by的方式,我的数据库包含3记录。为什么3零。
xhtml页面就在这里。
<h:form id="member">
<p:dataTable var="members" value="#{mainScreen.memberEntities}">
<p:column headerText="name">
<h:outputText value="#{memberEntity.name}" />
</p:column>
<p:column headerText="surname">
<h:outputText value="#{memberEntity.surname}" />
</p:column>
<p:column headerText="fathername">
<h:outputText value="#{memberEntity.fathername}" />
</p:column>
<p:column headerText="age">
<h:outputText value="#{memberEntity.age}" />
</p:column>
<p:column headerText="email">
<h:outputText value="#{memberEntity.email}" />
</p:column>
<p:column headerText="username">
<h:outputText value="#{memberEntity.username}" />
</p:column>
<p:column headerText="password">
<h:outputText value="#{memberEntity.password}" />
</p:column>
</p:dataTable>
</h:form>
`@ManagedBean
@Entity
@Table(name = "member")
public class MemberEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int memberid;
private int age;
private String name;
private String surname;
private String fathername;
private String email;
private String username;
private String password;
public MemberEntity(int memberid, int age, String name, String surname,
String fathername, String email, String username, String password) {
super();
this.memberid = memberid;
this.age = age;
this.name = name;
this.surname = surname;
this.fathername = fathername;
this.email = email;
this.username = username;
this.password = password;
}
public MemberEntity() {
super();
// TODO Auto-generated constructor stub
}
public int getMemberid() {
return memberid;
}
public void setMemberid(int memberid) {
this.memberid = memberid;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public String getFathername() {
return fathername;
}
public void setFathername(String fathername) {
this.fathername = fathername;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "Member [memberid=" + memberid + ",name=" + name + ",surname="
+ surname + ",age=" + age + ",email=" + email + ",fathername="
+ fathername + ",username=" + username + ",password="
+ password + "]";
}
}
答案 0 :(得分:1)
在p:dataTable
var
属性的名称为membres
时,您使用的p:column
值为memberEntity
,因此您必须将其更改为members
。
来自:
<p:column headerText="name">
<h:outputText value="#{memberEntity.name}" />
</p:column>
致:
<p:column headerText="name">
<h:outputText value="#{members.name}" />
</p:column>
答案 1 :(得分:0)
我找到了解决方案。在 getMember()方法而不是createNativeQuery(“Select * FROM member”)true ---&gt; createNativeQuery(“Select * FROM members,MemberEntity.class)