我开始学习Java和RESTful API中的服务器端开发,我不想使用任何框架来实现持久性等......除了Jersey之外的RESTful API端点。
所以我基本上有3层:
我的主要问题是最后两点。
我已经读过bean只包含getter和setter以及构造函数,所以我在考虑使用Conversation class
用例,它可以通过两种方式实现:
1. Operations and logic in the bean & access to the database on the managers
OR
2. Conversation Bean with only getters and setters & access to the database and logic and use of various beans objects on the managers
哪一个是正确的?
当时这是我的Conversation类Bean的样子:
public class Conversation implements Serializable {
private static final long serialVersionUID = 1L;
private String id;
private String initiatorUserId;
private String targettedUserId;
private Date startTime;
private Map<String, Set<Message>> assignedMessages;
private Set<Message> initiatorUserMessages;
private Set<Message> targettedUserMessages;
public Conversation (String initiatorUserId, String targettedUserId, Message firstMessage, Date startTime) {
this.initiatorUserId = initiatorUserId;
this.targettedUserId = targettedUserId;
this.startTime = startTime;
initiatorUserMessages.add (firstMessage);
assignedMessages.put (initiatorUserId, initiatorUserMessages);
}
// Getters and setters
}
这样做的正确方法是什么?谢谢。