struts2中使用注解返回自定义结果
我知道您可以通过在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也遇到了这个问题并且已经解决了。
在这种情况下,您需要在
struts.xml
中添加一行,如下所示: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: