struts2中使用注解返回自定义结果

发布于 2024-09-08 22:30:58 字数 436 浏览 3 评论 0原文

我知道您可以通过在 struts.xml 文件中指定声明来使用 struts2 返回自定义对象。我已经做到了,让它发挥作用。

我想做的就是摆脱这一点,并通过注释完成同样的事情。如果我有一个操作将返回自定义结果类型,我希望能够做到这一点。我玩了一下,但没能做任何事情。

@Result(name="success", type="results.MyResult.class")
public class MyAction extends ActionSupport
{ ...

这不起作用

@Result(name="success", type=results.MyResult.class)
public class MyAction extends ActionSupport
{ ...

这不能编译

I know that you can return custom objects using struts2 by specifying a declaration in your struts.xml file. I've done that, gotten that to work.

What I want to do is move away from that, and accomplish the same thing via annotations. If I have an action that is going to return a custom result type I would like to be able to do it. I played around a bit but haven't been able to get anything to work.

@Result(name="success", type="results.MyResult.class")
public class MyAction extends ActionSupport
{ ...

This doesn't work

@Result(name="success", type=results.MyResult.class)
public class MyAction extends ActionSupport
{ ...

This doesn't compile

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

So要识趣 2024-09-15 22:30:58

我也遇到了这个问题并且已经解决了。

在这种情况下,您需要在 struts.xml 中添加一行,如下所示:

<constant name="struts.convention.default.parent.package" value="test2"/>
<package name="test2" extends="struts-default">
  <result-types>
    <result-type name="imageResult"class="common.util.CustomizeStreamResult" />
  </result-types>
</package>

I came across this problem too and have solved it.

In such case you need to add one line in struts.xml just like this:

<constant name="struts.convention.default.parent.package" value="test2"/>
<package name="test2" extends="struts-default">
  <result-types>
    <result-type name="imageResult"class="common.util.CustomizeStreamResult" />
  </result-types>
</package>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文