简体   繁体   English

Struts 2中return语句之间的区别

[英]The difference between return statements in struts 2

What is the difference between returning a SUCCESS and Action.SUCCESS for your execute method in struts 2? 在struts 2中为您的execute方法返回SUCCESSAction.SUCCESS有什么区别? I know about returning a SUCCESS string, but I couldn't figure the Action.SUCCESS one? 我知道返回一个SUCCESS字符串,但是我无法弄清楚Action.SUCCESS一个吗?

Take a look on source code of Action : 看一下Action 代码:

public static final String SUCCESS = "success";

I think that this line explains better than any words that Action.SUCCESS and string constant "success" are the same. 我认为这一行比Action.SUCCESS和字符串常量"success"相同的任何词都解释得更好。

Action.SUCCESS is a String constant defined in the Action interface. Action.SUCCESS是在Action接口中定义的String常量。 see here 看这里

It will be available in all your Action classes that implement this interface. 在实现此接口的所有Action类中,它将可用。 Your own action classes inherit this constant. 您自己的动作类继承了此常数。

So there is practically no difference between Action.SUCCESS and SUCCESS inside a class that implements Action . 因此,在实现Action的类中, Action.SUCCESSSUCCESS实际上没有区别。

They are the same if point to the same constant in Action class. 如果在Action类中指向相同的常量,则它们是相同的。 But to use the first case required either the action class to implement the Action interface better with extending the ActionSupport which implements the Action interface or use static imports. 但是,使用第一种情况需要无论是动作类来实现Action与扩展更好的界面ActionSupport它实现了Action界面还是使用静态进口。 The second case is the usual way to access static resources. 第二种情况是访问静态资源的常用方法。

They are both string mapped to "success" string. 它们都被字符串映射到“成功”字符串。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM