SpringMVC与Freemarker集成,配置项目全局的绝对路径
http://my.oschina.net/liygheart/blog/292353
首先定义一个类,继承FreeMarkerView。
import org.springframework.web.servlet.view.freemarker.FreeMarkerView; import javax.servlet.http.HttpServletRequest; import java.util.Map; public class MyFreeMarkerView extends FreeMarkerView { private static final String CONTEXT_PATH = "base"; @Override protected void exposeHelpers(Map<String, Object> model, HttpServletRequest request) throws Exception { model.put(CONTEXT_PATH, request.getContextPath()); super.exposeHelpers(model, request); } }
然后,springMVC配置文件中,加上关于Freemarker视图解析器的相关配置,如下:
<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> <!-- 自定义FreeMarkerView,用来定义项目的全局路径 --> <property name="viewClass" value="com.kyt.utils.MyFreeMarkerView" /> </bean>
这样就可以在ftl模板文件中,使用${base}获得项目路径了!
相关推荐
81314797 2020-11-18
89314493 2020-11-03
81941231 2020-09-17
thisisid 2020-09-09
如狼 2020-08-15
82384399 2020-06-16
86384798 2020-05-12
80183053 2020-05-02
86384798 2020-04-26
86384798 2020-04-11
rionchen 2020-04-09
86384798 2020-04-07
86384798 2020-04-04
80183053 2020-03-07
87201943 2020-03-06
83961233 2020-02-26
87201943 2020-02-21