Struts:“别名”参数名称,来自“foo.bar”;至“b”
我有一个包含 DTO 作为成员的 Struts Action:
public class MyAction {
private MyDTO dto;
void execute() {
String bar = dto.getBar() ;
//struts has mapped GET parameter dto.bar by calling dto.setBar()
// do something with bar:
return bar != null ? SUCCESS : INPUT;
}
}
我希望将名为“b”的参数映射到 dto.bar,只是为了使我的 GET url 更清晰。而不是: http://myurl?dto.bar=xxx 我想: http://myurl?b=xxx
我知道我可以通过在我的操作中添加 setB(final String b),但这会使我的代码更脆弱且更难以理解。
有没有办法告诉 Struts 进行此映射,以便对于 http://myurl?b=xxx< 的 url /a>, MyAction.getDto.setBar() 被调用了吗?
I have a Struts Action that has a DTO as a member:
public class MyAction {
private MyDTO dto;
void execute() {
String bar = dto.getBar() ;
//struts has mapped GET parameter dto.bar by calling dto.setBar()
// do something with bar:
return bar != null ? SUCCESS : INPUT;
}
}
I want the parameter named "b" to be mapped to dto.bar, simply to make my GET url cleaner. Instead of:
http://myurl?dto.bar=xxx
I want:
http://myurl?b=xxx
I know I can do this by adding to my Action a setB(final String b), but that would make my code more brittle and harder to understand.
Is there a way I can tell Struts to do this mapping, so that for a url of http://myurl?b=xxx, MyAction.getDto.setBar() is called?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您也许可以使用别名拦截来实现此目的。查看:
http://www.opensymphony.com/webwork/wikidocs/Alias% 20Interceptor.html
You might be able to use aliasing interception to achieve this. Check out:
http://www.opensymphony.com/webwork/wikidocs/Alias%20Interceptor.html