简体   繁体   English

Struts2准备拦截器-如何跳过某些方法

[英]Struts2 prepare interceptor - How to skip certain methods

I have prepare interceptor in use. 我正在使用拦截器。 In one action class, I have an action method named testSomething() , and I also have an action method named prepareTestSomething() . 在一个动作类中,我有一个名为testSomething()的动作方法,还有一个名为prepareTestSomething()的动作方法。

The problem I'm facing here is that the prepare interceptor would invoke the prepareTestSomething() action method as if it was a preparing method for testSomething() , in which case it is not. 我在这里面临的问题是准备拦截器将调用prepareTestSomething()动作方法,就好像它是testSomething()的准备方法一样,在这种情况下不是。

Is there a way to make the prepare interceptor to skip the invocation for certain action methods? 有没有一种方法可以使准备拦截器跳过某些操作方法的调用? Like for validation interceptor, we can use " excludeMethods " parameter. 像验证拦截器一样,我们可以使用“ excludeMethods ”参数。

Prepending the prepare word to an Xxx method is the Struts2 convention to tell the framework that it is the prepare() method for the Xxx action method. Struts2 约定Xxx方法之前加上了prepare字,以告知框架它是Xxx action方法的prepare()方法。 From the docs : 文档

if the action class have prepare{MethodName}() , it will be invoked 如果操作类具有prepare{MethodName}() ,则将调用它

Instead of doing other voodoos (like excluding methods) in order to make this voodoo work, simply change the method name, it is the only right way to go. 不用做其他的伏都教(例如排除方法)来使这种伏都教起作用,只需更改方法名称,这是唯一正确的方法。

Call it initTestSomething() , initializeTestSomething() , preparzTestSomething() ... whatever; initTestSomething()initializeTestSomething()preparzTestSomething() ...等等; but please, don't use a convention trying to make it work for something else. 但是请不要使用约定使它在其他方面起作用。 It is just... wrong. 只是...错了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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