我在JSP页面中访问public enum
类属性时遇到问题。我可以访问除invite.status
属性之外的所有其他邀请类属性。我做错了什么,但我无法弄清楚为什么它是错的以及我如何访问我返回的列表的enum
值。感谢您帮助解决我的问题!
我得到的错误类...domain.jpa.meeting.Invite
'没有属性status
。
这是我有的JPA课程
@Entity
public class Invite implements PersistentEntity {
@Id @GeneratedValue
private Long id;
@ManyToOne
private User inviter;
@ManyToOne
private User invitee;
@ManyToOne
private Meeting meeting;
/**
* Date when this invite has been created
*/
private Date created;
// @Column(nullable=false, length=1)
// @Enumerated(EnumType.STRING)
private InviteStatus status;
public Long getId() {
return id;
}
public User getInviter() {
return inviter;
}
public void setInviter(User inviter) {
this.inviter = inviter;
}
public User getInvitee() {
return invitee;
}
public void setInvitee(User invitee) {
this.invitee = invitee;
}
public Meeting getMeeting() {
return meeting;
}
public void setMeeting(Meeting meeting) {
this.meeting = meeting;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public InviteStatus getInviteStatus() {
return status;
}
public void setInviteStatus(InviteStatus status) {
this.status = status;
}
}
这是我拥有的枚举类公共类
/**
* Values for tracking invite status
*/
public enum InviteStatus {
// invite is created and invitee have not responded yet
CREATED,
// invitee accepted this invite
ACCEPTED,
// invitee declined this invite
DECLINED
}
我以这种方式保存在数据库中(成功为EnumType.ORDINAL)
// adding invites (table invite)
Invite invite = new Invite();
invite.setInviter(creator);
User invitee = jpaDAO.getById(User.class, Long.parseLong(friends[i]));
invite.setInvitee(invitee);
invite.setInviteStatus(InviteStatus.CREATED); //CREATED = 0, ACCEPTED = 1, ..
Date dateNow = new Date(); //yyyy-MM-dd HH:mm:ss
invite.setCreated(dateNow);
Meeting meeting = jpaDAO.getById(Meeting.class, meetingId);
invite.setMeeting(meeting);
jpaDAO.save(invite);
我有一个从数据库中检索邀请的方法。
@SuppressWarnings({ "unchecked", "null" })
public List<Invite> getUserInvites(Long userId){
// getting invites for current user with status CREATED
Query query = jpaDAO.getEntityManager().createNamedQuery(JPQConst.InviteJpq.QUERY_GET_BY_USER);
query.setParameter("userId", userId);
List<Invite> invites = (List<Invite>) query.getResultList();
return invites;
}
内部控制器看起来像这样:
/**
* Display Notifications tab
*/
@RequestMapping(value = "/home/notifications", method = RequestMethod.GET)
public String displayNotifications(ModelMap model, HttpSession session) {
User user = getCurrentUser(session);
List<Invite> invites = notificationService.getUserInvites(user.getId());
model.addAttribute("invites", invites);
return "home";
}
方法本身有效,我可以访问除jsp中的status属性之外的所有邀请属性字段。
<c:forEach var="meeting" items="${inviteeMeetings}">
<c:forEach var="invite" items="${invites}">
<c:choose>
<c:when test="${meeting.id == invite.meeting.id}">
<tr>
<td width="150px" align="center">
<c:out value="${meeting.startTime}" />
</td>
<td width="396px">
<a href="../meeting/${meeting.id}"><c:out value="${meeting.title}" /></a>
</td>
<td width="96px">
<c:out value="${invite.status}" />
<form action="../meeting/attendance" method="post">
<input type="hidden" name="venue" value="${meeting.id}" />
<input type="submit" name="attendance" value="attend" />
<input type="submit" name="attendance" value="reject" />
</form>
</td>
</tr>
</c:when>
</c:choose>
</c:forEach>
</c:forEach>
答案 0 :(得分:1)
实际上,你的班级没有这样的财产。它确实有inviteStatus
属性。
public InviteStatus getInviteStatus() {
return status;
}
属性基于信件。存储数据的内部值的名称不相关。