【问题标题】:How to use <mvc:resource/> in Groovy如何在 Groovy 中使用 <mvc:resource/>
【发布时间】:2015-04-01 02:59:13
【问题描述】:

我想用&lt;mvc:resource/&gt;比如&lt;mvc:resources mapping="/images/**" location="/images/" /&gt;&lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt;context-mvc.groovy,不知道怎么写。帮帮我~

import org.springframework.web.servlet.view.InternalResourceViewResolver

beans {
    xmlns context: "http://www.springframework.org/schema/context"


    context."component-scan"("base-package" : "com.oberon.fm")

    viewResolver(InternalResourceViewResolver) {
        prefix = "/pages/"
        suffix = ".jsp"
    }
}

【问题讨论】:

    标签: spring spring-mvc groovy gradle


    【解决方案1】:

    为了在你的 Groovy 中使用 mvc 命名空间,你需要将它添加到 xmlns

    然后你可以像上下文一样使用它。

    beans {
    
        xmlns([ctx:'http://www.springframework.org/schema/context',
               mvc:'http://www.springframework.org/schema/mvc'])
    
        ctx.'component-scan'('base-package': "com.oberon.fm")
        mvc.resources(mapping:"/images/**", location:"/images/")
        mvc.resources(mapping:"/resources/**", location:"/resources/")
    }
    

    【讨论】:

    • 感谢您回答我的问题,我是spring的学习者,有时我觉得很难,感谢这些热心的人,尤其是你们。还有一个问题,我的DipatcherServlet 是“/ ",那么当我使用 mvc.resources(mapping:"/images/**", location:"/images/") 时,我的 viewResolver 不起作用
    • import org.springframework.web.servlet.view.InternalResourceViewResolver beans { xmlns ([context: "springframework.org/schema/context", mvc: "springframework.org/schema/mvc"]) mvc.resources(mapping:"/images/ **", location:"/images/") mvc.resources(mapping:"/css/**", location:"/css/") context."component-scan"("base-package" : "com .oberon.fm") viewResolver(InternalResourceViewResolver) { prefix = "/pages/" suffix = ".jsp" } }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-11
    • 1970-01-01
    • 1970-01-01
    • 2022-10-22
    • 2023-01-04
    相关资源
    最近更新 更多