SpringMVC集成

需要做如下配置即可

  1. <bean id="beetlConfig" class="org.beetl.ext.spring.BeetlGroupUtilConfiguration" init-method="init"/>
  2. <bean id="viewResolver" class="org.beetl.ext.spring.BeetlSpringViewResolver">
  3. <property name="contentType" value="text/html;charset=UTF-8"/>
  4. </bean>

同其他集成方式一样,模板的配置将放在beetl.properties中。

如果想获取GroupTemplate,可以调用如下代码

  1. BeetlGroupUtilConfiguration config = (BeetlGroupUtilConfiguration) this.getApplicationContext().getBean("beetlConfig");
  2. GroupTemplate group = config.getGroupTemplate();

Controller代码如下:

  1. @RequestMapping(value = "/", method = RequestMethod.GET)
  2. public ModelAndView index(HttpServletRequest req) {
  3. ModelAndView view = new ModelAndView("/index");
  4. //total 是模板的全局变量,可以直接访问
  5. view.addObject("total",service.getCount());
  6. return view;
  7. }

http://git.oschina.net/xiandafu/springbeetlsql 有完整例子

通常可以把模板放到WEB-INF目录下,除了可以配置beetl.propertis 外,还可以使用Spring配置

  1. <bean id="beetlConfig" class="org.beetl.ext.spring." init-method="init">
  2. <property name="root" value="/WEB-INF/templates"/>
  3. </bean>