我在用百里香。
此模板:
<a th:href="@{/}">a</a>
生成以下html:
<a href="/">a</a>
这就是我所期望的。
我在WebMvcConfigurerAdapter扩展类中放入ResourceUrlEncodingFilterbean来尝试ContentVersionStrategy。
@Bean
public ResourceUrlEncodingFilter resourceUrlEncodingFilter() {
return new ResourceUrlEncodingFilter();
}
生成的html变成:
<a href="">a</a>
href的值为空。我希望href是"/",即使我放入ResourceUrlEncodingFilterbean。在这两种情况下CCD_ 1都变为CCD_。
我做错什么了吗?
非常感谢。
更新:
这是我的建筑.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'io.spring.gradle:dependency-management-plugin:0.5.1.RELEASE'
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
version = '1.0'
jar {
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': version
}
}
repositories {
mavenCentral()
}
dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:1.1.2.RELEASE'
}
}
dependencies {
compile('org.webjars:bootstrap:3.3.1')
compile('org.webjars:knockout:3.2.0')
compile('org.webjars:momentjs:2.9.0')
compile('org.webjars:numeral-js:1.5.3-1')
compile('org.webjars:underscorejs:1.7.0-1')
compile('org.webjars:sugar:1.4.1')
compile('org.webjars:jqplot:1.0.8r1250')
compile('org.webjars:jquery-cookie:1.4.1-1')
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.springframework.boot:spring-boot-starter-batch")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-tomcat")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-test")
compile("org.springframework:spring-context-support") // this is for mail
compile('commons-codec:commons-codec')
compile("commons-io:commons-io")
compile('com.google.guava:guava')
compile('org.hibernate:hibernate-validator')
compile("com.sun.mail:javax.mail")
compile('mysql:mysql-connector-java')
compile("org.yaml:snakeyaml")
compile("org.apache.commons:commons-lang3:3.2")
compile('com.amazonaws:aws-java-sdk:1.9.4')
compile('net.sf.supercsv:super-csv:2.2.0')
compile('edu.vt.middleware:vt-password:3.1.2')
}
test {
//systemProperties 'property': 'value'
systemProperties 'spring.profiles.active': 'unittest'
systemProperties 'MAIL_PROP': 'mail.properties'
systemProperties 'user.timezone': 'UTC'
}
uploadArchives {
repositories {
flatDir {
dirs 'repos'
}
}
}
感谢您的详细解释和repo项目!
这实际上是一个错误:请参阅SPR-13241,将在Spring 4.1.8和4.2.0中修复。
Spring Boot为静态web资源位置的自动配置添加了"/**"匹配器。位置为/META-INF/resources/、/resources/和/static/和/public/。
当你把下面的html放在Thymelaf模板中时,
<a th:href="@{/}">a</a>
ResourceUrlProvider.java中的以下方法是由于匹配器和进入for循环而被调用的:
public final String getForLookupPath(String lookupPath) {
// -- omission --
for(String pattern : matchingPatterns) {
// -- omission --
String pathWithinMapping = getPathMatcher().extractPathWithinPattern(pattern, lookupPath);
String pathMapping = lookupPath.substring(0, lookupPath.indexOf(pathWithinMapping));
// -- omission --
String resolved = chain.resolveUrlPath(pathWithinMapping, handler.getLocations());
if (resolved == null) {
continue;
}
// -- omission --
return pathMapping + resolved;
}
// -- omission --
}
参数,lookupPath是"/"乘以"@{/}",然后:
- 路径WithinMapping将为"
- 路径映射将为"
- 解决的将是"
因此,此方法返回",并且值设置为href="。
在我看来,如果pathWithinMapping是",那么继续for循环似乎很好。调用chain.resolveUrlPath似乎不太好。
谢谢,