package com.bohuikeji.frame.module.admin.config;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;

/**
 * 配置FreeMark
 * @author 10552
 *
 */
@Configuration
public class FreeMarkerConfig {
	/**
	 * 注入模板配置类
	 */
	@Autowired
    private freemarker.template.Configuration configuration;

	/**
	 * 获取application.yml配置文件中的配置项
	 */
    @Value("${server.servlet.context-path}")
    private String ctx;

    
    /**
     * 设置FreeMarker全局变量
     * @throws Exception
     */
    @PostConstruct
    public void setSharedVariable() throws Exception {
    	/**
    	 * 设置context-path(项目路径)
    	 */
    	ctx="/".equals(ctx)?"":ctx;
        configuration.setSharedVariable("ctx", ctx);
        configuration.setSharedVariable("static",ctx+"/static");

    }

}
