2015-12-13 36 views
0

有什么区别:getExternalContext()getSessionMap()获得( “豆”)

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

如果bean尚不存在,@ManagedProperty方式会自动创建bean。如果事先没有(自动)创建bean,则getSessionMap()方式不会,因此可能会返回null

以最小的努力和关注达到相同的代码更好。

+0

感谢您回复:D – gastonovic