如何判断控制器中是否已定义某个视图(图块)?

发布于 2024-12-08 00:25:23 字数 658 浏览 6 评论 0原文

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 技术交流群。

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

发布评论

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

评论(2

风月客 2024-12-15 00:25:23

我想你可能对Spring的支持主题,主题可以相互继承并回退到默认值。

I think you might be interested in Spring's support for themes, which can inherit from each other and fallback to a default.

吖咩 2024-12-15 00:25:23

显然,确实没有一个好方法可以做到这一点,除非您真的想一头扎进摆弄视图解析器。我没有时间或意愿去尝试解决这个问题,但如果比我聪明的人有时间,我很想听到解决方案。在那之前我只会下注并对特殊公司进行一些 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文