0

我有一个以 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,调用 MyAction.getDto.setBar() ?

4

1 回答 1

1

您也许可以使用别名拦截来实现此目的。查看:

http://www.opensymphony.com/webwork/wikidocs/Alias%20Interceptor.html

于 2011-01-05T00:06:36.370 回答