如何判断控制器中是否已定义某个视图(图块)?
Spring 3.0.5 + Tiles
在我的控制器内,我正在创建一个新的 ModelAndView,但出现了一种情况,一家公司想要自己的视图。一旦发生这种情况,我就能看到这种情况在其他人也想要自己的地方发展。
@RequestMapping(params="companyId")
public ModelAndView newCompanyView(HttpServletRequest request, String companyId) {
// right here I'd like to check if the "companyABC" view is a defined tile
// and if it is the send that back as a view and I can eliminate a bunch of if
// checks.
if(companyId.equals("ABC")) {
return new ModelAndView("companyABC", "vo", getCompanyVo());
} else {
return new ModelAndView("company", "vo", getCompanyVo());
}
}
这可能吗?如果可能的话怎么办?
Spring 3.0.5 + Tiles
Inside my controller I'm creating a new ModelAndView but a situation has come up where one company wants their own view. Once this happens I can see this growing where other's want their own as well.
@RequestMapping(params="companyId")
public ModelAndView newCompanyView(HttpServletRequest request, String companyId) {
// right here I'd like to check if the "companyABC" view is a defined tile
// and if it is the send that back as a view and I can eliminate a bunch of if
// checks.
if(companyId.equals("ABC")) {
return new ModelAndView("companyABC", "vo", getCompanyVo());
} else {
return new ModelAndView("company", "vo", getCompanyVo());
}
}
Is this possible and if so then how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想你可能对Spring的支持主题,主题可以相互继承并回退到默认值。
I think you might be interested in Spring's support for themes, which can inherit from each other and fallback to a default.
显然,确实没有一个好方法可以做到这一点,除非您真的想一头扎进摆弄视图解析器。我没有时间或意愿去尝试解决这个问题,但如果比我聪明的人有时间,我很想听到解决方案。在那之前我只会下注并对特殊公司进行一些 IF 检查。
Apparently there really isn't a good way to do this unless you really want to dive head first into fiddling with view resolvers. I don't have the time or the desire to try and figure it out but if someone smarter than I has some time I'd love to hear a solution. Until then I'm just going to punt and have some IF checks for special companies.