4.4. SpringMVC集成
需要做如下配置即可
<bean id="beetlConfig" class="org.beetl.ext.spring.BeetlGroupUtilConfiguration" init-method="init"/>
<bean id="viewResolver" class="org.beetl.ext.spring.BeetlSpringViewResolver">
<property name="contentType" value="text/html;charset=UTF-8"/>
</bean>
同其他集成方式一样,模板的配置将放在beetl.properties中。
如果想获取GroupTemplate,可以调用如下代码
BeetlGroupUtilConfiguration config = (BeetlGroupUtilConfiguration) this.getApplicationContext().getBean("beetlConfig");
GroupTemplate group = config.getGroupTemplate();
Controller代码如下:
@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView index(HttpServletRequest req) {
ModelAndView view = new ModelAndView("/index");
//total 是模板的全局变量,可以直接访问
view.addObject("total",service.getCount());
return view;
}
http://git.oschina.net/xiandafu/springbeetlsql 有完整例子
通常可以把模板放到WEB-INF目录下,除了可以配置beetl.propertis 外,还可以使用Spring配置
<bean id="beetlConfig" class="org.beetl.ext.spring." init-method="init">
<property name="root" value="/WEB-INF/templates"/>
</bean>
当前内容版权归 ibeetl.com 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 ibeetl.com .