package com.yuxinglab.utils;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.servlet.view.freemarker.FreeMarkerView;
public class MyFreeMarkerViewClass extends FreeMarkerView {
@Override
protected void exposeHelpers(Map<String, Object> model,
HttpServletRequest request) throws Exception {
model.put("base", request.getContextPath());
super.exposeHelpers(model, request);
}
}
覆写FreeMarkerView的exposeHelpers方法。
<bean id="freemarkerViewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> <property name="viewClass" value="com.yuxinglab.utils.MyFreeMarkerViewClass"></property> <property name="contentType" value="text/html; charset=UTF-8" /> <property name="exposeRequestAttributes" value="false" /> <property name="exposeSessionAttributes" value="false" /> <property name="exposeSpringMacroHelpers" value="true" /> <property name="prefix" value="/WEB-INF/freemarker/" /> <property name="suffix" value=".html" /> </bean>