spring-boot设置contextPath

spring boot 设置contextPath

方法一 、velocity 配置

1
2
3
4
5
6
7
8
9
@Bean(name = "velocityViewResolver")
public VelocityLayoutViewResolver velocityViewResolver(VelocityProperties properties) {
VelocityLayoutViewResolver resolver = new VelocityLayoutViewResolver();
properties.applyToViewResolver(resolver);
resolver.setLayoutUrl("common/main_layout.vm");
resolver.setRequestContextAttribute("rc");
return resolver;
}
vm页面中获取 $!rc.contextPath 即可

方法二、springMacroRequestContext内置对象

1
2
$!{springMacroRequestContext.contextPath}
可以直接获取到contextPath,不用任何设置