[英]The difference between return statements in struts 2
在struts 2中為您的execute方法返回SUCCESS
和Action.SUCCESS
有什么區別? 我知道返回一個SUCCESS
字符串,但是我無法弄清楚Action.SUCCESS
一個嗎?
看一下Action
源代碼:
public static final String SUCCESS = "success";
我認為這一行比Action.SUCCESS
和字符串常量"success"
相同的任何詞都解釋得更好。
Action.SUCCESS
是在Action
接口中定義的String
常量。 看這里
在實現此接口的所有Action類中,它將可用。 您自己的動作類繼承了此常數。
因此,在實現Action
的類中, Action.SUCCESS
和SUCCESS
實際上沒有區別。
如果在Action
類中指向相同的常量,則它們是相同的。 但是,使用第一種情況需要無論是動作類來實現Action
與擴展更好的界面ActionSupport
它實現了Action
界面還是使用靜態進口。 第二種情況是訪問靜態資源的常用方法。
它們都被字符串映射到“成功”字符串。
public interface Action {
/**
* The action execution was successful. Show result
* view to the end user.
*/
public static final String SUCCESS = "success";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.