有什么区别:
public class GameController implements Serializable{
@ManagedProperty(value="#{Gamebean}")
private Game game;
和
public class GameController implements Serializable{
private Game game;
public GameController(){
game =(Game)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("Gamebean");
}
如果没有什么区别,哪种方法更好? 干杯。
答案 0 :(得分:0)
@ManagedProperty
方式将自动创建bean,如果它还不存在的话。如果预先没有(自动)创建bean,getSessionMap()
方式将不会返回null
。
以最少的努力和关注实现同样的代码更好。