将实体用作JSF支持Bean是否有意义?
@Entity
@ManagedBean
@ViewScoped
public class User {
private String firstname;
private String lastname;
@EJB
private UserService service;
public void submit() {
service.create(this);
}
// ...
}
还是将它们分开保存并在最后将数据从支持Bean传输到实体更好?
@ManagedBean
@ViewScoped
public class UserBean {
private String firstname;
private String lastname;
@EJB
private UserService service;
public void submit() {
User user = new User();
user.setFirstname(firstname);
user.setLastname(lastname);
service.create(user);
}
// ...
}
慕盖茨4494581
相关分类