基于SpringBoot框架快速入门学习Beetl

1、简单介绍

  • 超高的性能:Beetl 远超过主流java模板引擎性能(引擎性能5-6倍与freemaker,2倍于JSP。参考附录),而且消耗较低的CPU。

 

2、pom文件中添加依赖

       <dependency>
             <groupId>com.ibeetl</groupId>
             <artifactId>beetl</artifactId>
             <version>2.7.15</version>
       </dependency>

3、编写核心配置类BeetlConfig

import java.io.IOException;

import org.beetl.core.resource.WebAppResourceLoader;
import org.beetl.ext.spring.BeetlGroupUtilConfiguration;
import org.beetl.ext.spring.BeetlSpringViewResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternUtils;


@Configuration
public class BeetlConfig {
	
	
	@Bean(initMethod="init")
	public BeetlGroupUtilConfiguration beetlConfiguration(){
		
		BeetlGroupUtilConfiguration configuration=new BeetlGroupUtilConfiguration();
		ResourcePatternResolver patternResolver = ResourcePatternUtils.getResourcePatternResolver(new DefaultResourceLoader());
		
		String path=null;
		try {
			path = patternResolver.getResource("classpath:/").getFile().getPath();
			System.out.println("==================path:"+path);
			WebAppResourceLoader resourceLoader=new WebAppResourceLoader(path);
			
			configuration.setResourceLoader(resourceLoader);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return configuration;
	}

	@Bean
	public BeetlSpringViewResolver getBeetlSpringViewResolver(){
		BeetlSpringViewResolver beetlSpringViewResolver = new BeetlSpringViewResolver();
		beetlSpringViewResolver.setPrefix("WEB-INF/views/");
		beetlSpringViewResolver.setSuffix(".html");
		beetlSpringViewResolver.setContentType("text/html;charset=UTF-8");
		beetlSpringViewResolver.setOrder(0);
		beetlSpringViewResolver.setConfig(beetlConfiguration());
		
		return beetlSpringViewResolver;
	}
	
}

 

4、控制层方法

@RequestMapping(value={"/beetl/add"},method=RequestMethod.GET)
	public ModelAndView testBeetl(){
		
		ModelAndView modelAndView = new ModelAndView();
		System.out.println("add request");
        modelAndView.addObject("email", "apk2sf@163.com");
        modelAndView.setViewName("add");
		
		return modelAndView;
	}

5、在src\main\resources路径下创建文件夹WEB-INF,再在WEB-INF下创建文件夹views,最后在views文件夹下创建add.html文件。add.html文件代码如下:

 <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>add</title>
    </head>
    <body>
    add Html web info

    <hr>
    获取项目的context-path-->${ctxPath}
    <hr>
    获取后台返回的数据--->${email}

    </body>
    </html>

6、按照控制层方法请求,即可看到页面。

 

 

我的学习资料来自:

https://blog.csdn.net/pyfysf/article/details/78960977

http://ibeetl.com/guide/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值