java - Spring MVC :resources tag understanding

标签 java xml spring

在 Spring Petclinic 中,以下标记用于静态内容。

"<mvc:resources mapping="/resources/**" location="/resources/"/> "

但是我在理解这一点时遇到了问题,因为映射和位置是相同的。那么这个标签会解决什么目的呢?如果css文件请求是这样的。

"spring:url value="/resources/css/petclinic.css"var="petclinicCss""

执行 mvc:resources 标签后转换后的 URL 是多少。

最佳答案

<mvc:resources mapping="/resources/**" location="/resources/"/>

来自此 URL 模式的任何请求 /resources/** ,Spring会寻找/resources/

  1. mapping是 url 模式
  2. location资源存在于项目类路径中的位置

Configuring Serving of Resources

<小时/>

使用示例,

  1. 通过使用 JSTL <c:url>

    <script type="text/javascript" src="<c:url value="/resources/js/jquery.js" />"></script>
    
  2. 通过使用 <spring:url>

    <spring:url value="/resources/images/favicon.ico" var="favicon" />
    

关于java - Spring MVC :resources tag understanding,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25395895/

相关文章:

java - 如何检查某个消费者是否使用 java 连接到 Kafka 0.9.0.x?

java - UnsupportedMediaTypeException : Content type 'application/octet-stream' not supported for bodyType=java. util.Map<java.lang.String, java.lang.String>))

java - 计算代表已填充属性数量的 Java 对象的百分比

java - 如果同步块(synchronized block)中的锁对象发生更改,会发生什么情况

java - 如何仅从一个 GUI 进行 JUnit 测试?

java - 编译警告 "static method declared final"是什么原因?

java - Spring 启动: constructor injection with xml gives "there is already n bean method"

python - BeautifulSoup 能否保留 CDATA 部分?

python - 如何在 ATOM XML 文档中搜索大小写混合的标记名称?

java - 对大型 xml 文件的随机查询