Servlet与FreeMarker整合
http://oma1989.iteye.com/blog/1421804
SpringTemplateLoader
public class SpringTemplateLoader implements TemplateLoader { protected final Log logger = LogFactory.getLog(getClass()); private final ResourceLoader resourceLoader; private final String templateLoaderPath; /** * Create a new SpringTemplateLoader. * @param resourceLoader the Spring ResourceLoader to use * @param templateLoaderPath the template loader path to use */ public SpringTemplateLoader(ResourceLoader resourceLoader, String templateLoaderPath) { this.resourceLoader = resourceLoader; if (!templateLoaderPath.endsWith("/")) { templateLoaderPath += "/"; } this.templateLoaderPath = templateLoaderPath; if (logger.isInfoEnabled()) { logger.info("SpringTemplateLoader for FreeMarker: using resource loader [" + this.resourceLoader + "] and template loader path [" + this.templateLoaderPath + "]"); } } public Object findTemplateSource(String name) throws IOException { if (logger.isDebugEnabled()) { logger.debug("Looking for FreeMarker template with name [" + name + "]"); } Resource resource = this.resourceLoader.getResource(this.templateLoaderPath + name); return (resource.exists() ? resource : null); } public Reader getReader(Object templateSource, String encoding) throws IOException { Resource resource = (Resource) templateSource; try { return new InputStreamReader(resource.getInputStream(), encoding); } catch (IOException ex) { if (logger.isDebugEnabled()) { logger.debug("Could not find FreeMarker template: " + resource); } throw ex; } } public long getLastModified(Object templateSource) { Resource resource = (Resource) templateSource; try { return resource.lastModified(); } catch (IOException ex) { if (logger.isDebugEnabled()) { logger.debug("Could not obtain last-modified timestamp for FreeMarker template in " + resource + ": " + ex); } return -1; } } public void closeTemplateSource(Object templateSource) throws IOException { }
FreeMarkerConfigurationFactory:
protected TemplateLoader getTemplateLoaderForPath(String templateLoaderPath) { if (isPreferFileSystemAccess()) { // Try to load via the file system, fall back to SpringTemplateLoader // (for hot detection of template changes, if possible). try { Resource path = getResourceLoader().getResource(templateLoaderPath); File file = path.getFile(); // will fail if not resolvable in the file system if (logger.isDebugEnabled()) { logger.debug( "Template loader path [" + path + "] resolved to file path [" + file.getAbsolutePath() + "]"); } return new FileTemplateLoader(file); } catch (IOException ex) { if (logger.isDebugEnabled()) { logger.debug("Cannot resolve template loader path [" + templateLoaderPath + "] to [java.io.File]: using SpringTemplateLoader as fallback", ex); } return new SpringTemplateLoader(getResourceLoader(), templateLoaderPath); } } else { // Always load via SpringTemplateLoader (without hot detection of template changes). logger.debug("File system access not preferred: using SpringTemplateLoader"); return new SpringTemplateLoader(getResourceLoader(), templateLoaderPath); } }
FreeMarkerConfigurationFactory:
public Configuration createConfiguration() throws IOException, TemplateException { Configuration config = newConfiguration(); Properties props = new Properties(); // Load config file if specified. if (this.configLocation != null) { if (logger.isInfoEnabled()) { logger.info("Loading FreeMarker configuration from " + this.configLocation); } PropertiesLoaderUtils.fillProperties(props, this.configLocation); } // Merge local properties if specified. if (this.freemarkerSettings != null) { props.putAll(this.freemarkerSettings); } // FreeMarker will only accept known keys in its setSettings and // setAllSharedVariables methods. if (!props.isEmpty()) { config.setSettings(props); } if (!CollectionUtils.isEmpty(this.freemarkerVariables)) { config.setAllSharedVariables(new SimpleHash(this.freemarkerVariables, config.getObjectWrapper())); } if (this.defaultEncoding != null) { config.setDefaultEncoding(this.defaultEncoding); } // Register template loaders that are supposed to kick in early. if (this.preTemplateLoaders != null) { this.templateLoaders.addAll(this.preTemplateLoaders); } // Register default template loaders. if (this.templateLoaderPaths != null) { for (String path : this.templateLoaderPaths) { this.templateLoaders.add(getTemplateLoaderForPath(path)); } } postProcessTemplateLoaders(this.templateLoaders); // Register template loaders that are supposed to kick in late. if (this.postTemplateLoaders != null) { this.templateLoaders.addAll(this.postTemplateLoaders); } TemplateLoader loader = getAggregateTemplateLoader(this.templateLoaders); if (loader != null) { config.setTemplateLoader(loader); } postProcessConfiguration(config); return config; }
相关推荐
### FreeMarker中文手册知识点概述 #### 一、FreeMarker简介 FreeMarker是一个用Java语言编写的模板引擎,它基于一种简单的模板语言来处理文本输出。该手册为FreeMarker 2.3.19版本的中文翻译版,由南磊翻译,并...
<bean id="freemakerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> <value>/WEB-INF/web/ <prop key="defaultEncoding">gbk ``` #### 方法二:处理...
freemarker调试实现了freemarker / spring mvc反模式。 用于跟踪工具开发的代码。 只需使用Maven运行它: mvn jetty:run 打开浏览器: 进行慢速演示用于模板崩溃演示(仅用于获取堆栈跟踪) ......
在Java中,Freemarker与ModelAndView、Velocity等模板引擎类似,它通过模板语言(Template Language)来描述数据如何被渲染。... 1. **导出Excel** - 使用Freemarker导出Excel通常涉及到Apache POI库。...
基于transUnet和swinUnet的医学图像分割项目实验对比,包含完整代码,可以一键运行。评估指标包括dice、iou、recall、precision等
,stm32f030无感foc方案,资料包括原理图,pcb,源程序,观测器参数,电流环参数计算表格。
分布式电源DG选址定容优化及帕累托最优解集的粒子群算法研究,多目标粒子群算法 分布式电源 DG 定容选址 网损 成本 电压偏差 通过分布式能源的选址定容确定得到帕累托最优解集,然后选择最优值进行分析,程序采用改进粒子群算法, ,核心关键词:多目标粒子群算法; 分布式电源选址定容; 网损; 成本; 电压偏差; 帕累托最优解集。,改进粒子群算法在分布式电源选址定容中的应用:优化网损与成本,考虑电压偏差
交变磁场感应材料对沥青路面温度影响的研究,交变磁场下含感应材料沥青路面温度 ,交变磁场; 感应材料; 沥青路面; 温度; 变化; 加热效率,交变磁场对含感应材料沥青路面温度的影响研究
基于Comsol模拟的三层顶板随机裂隙浆液扩散模型:考虑重力影响的瞬态扩散规律分析,Comsol模拟,考虑三层顶板包含随机裂隙的浆液扩散模型,考虑浆液重力的影响,模型采用的DFN插件建立随机裂隙,采用达西定律模块中的储水模型为控制方程,分析不同注浆压力条件下的浆液扩散规律,建立瞬态模型 ,Comsol模拟; 随机裂隙浆液扩散模型; 浆液重力影响; DFN插件; 达西定律模块储水模型; 注浆压力条件; 浆液扩散规律; 瞬态模型,Comsol浆液扩散模型:随机裂隙下考虑重力的瞬态扩散分析
对于Sqlserver数据库只是提供了简单的图形化的导出导入工具,在实际的开发和生产环境不太可能让用户在图形化的界面选择移行的对象,进行移行。 我们在数据库的移行中也遇到这种问题,需要提供一个工具给客户使用。所以我们开发了针对SQLServer数据库的cmd形式导入导出的工具。在长期的实践中不断完善,基本可以实现Oracle的导入导出工具的80%的功能,也比较的稳定。有需要的可以下载使用,也可以提供定制化的服务
内容概要:本文介绍了DeepSeek模型在不同平台上部署的方法。首先阐述了基于Ollama的本地部署,包括Ollama的安装、模型拉取以及交互模式的使用。接着讲解了DeepSeek在移动设备(iOS和Android)上的部署细节:iPhone需要通过Safari安装快捷指令,配置API Key并通过快捷指令测试运行;Android则借助Termux安装必要组件,并手动搭建Ollama环境以加载和测试模型。最后详细叙述了基于Open WebUI部署的方式,涉及Ollama、Docker Desktop及Open WebUI的安装流程及其之间的配合使用来最终达成模型的成功部署。 适用人群:面向有兴趣了解或者实际操作DeepSeek模型跨平台部署的技术开发者、研究人员以及AI爱好者。 使用场景及目标:适用于希望利用DeepSeek模型快速构建本地化应用程序、开展实验研究的用户;具体目标为掌握DeepSeek模型在桌面系统(如Linux、macOS、Windows)、iOS和Android智能手机以及云端WebUI界面上的不同部署手段和技术。 其他说明:对于每种类型的部署都提供了详细的步骤指导,旨在帮助使用者顺利完成所需工具和环境的安装,并确保模型能够正常工作。文中给出的具体链接和命令行脚本,有助于降低初次接触者的上手难度,提升部署效率和成功率。此外,还强调了一些重要的配置注意事项,例如正确输入API key以及对Ollama的初始化检查等。
,FOC 无感 混合磁链观测器 电机控制 代码 PMSM MiniDD(直驱)电机变频无感程序,包含偏心,重量,共振等感知算法,所有算法都不基于库函数,MCU底层配置完全手写
nodejs010-nodejs-cmd-shim-1.1.0-4.1.el6.centos.alt.noarch.rpm
基于S7-200 PLC的交通灯倒计时控制及组态王界面实现原理图解析,S7-200 PLC和组态王交通灯带倒计时控制 923 47 带解释的梯形图接线图原理图图纸,io分配,组态画面 ,S7-200 PLC; 交通灯; 倒计时控制; 组态王; 梯形图接线图; IO分配; 组态画面,"S7-200 PLC与组态王交通灯倒计时控制:梯形图原理及IO分配详解"
西门子四轴卧加后处理系统:828D至840D兼容,四轴联动高效加工解决方案,支持图档处理及试看程序。,西门子四轴卧加后处理,支持828D~840D系统,支持四轴联动,可制制,看清楚联系,可提供图档处理试看程序 ,核心关键词:西门子四轴卧加后处理; 828D~840D系统支持; 四轴联动; 制程; 联系; 图档处理试看程序。,西门子四轴卧加后处理程序,支持多种系统与四轴联动
FPGA篮球赛事24秒倒计时计时器设计与实现(基于Verilog与VHDLL的优化对比),基于fpga篮球倒计时24s。 verilog和vhdl两个版本 ,基于FPGA篮球倒计时24s; Verilog版本; VHDL版本,FPGA篮球比赛倒计时24秒系统:Verilog与VHDL双版本实现
论生成式AI在大学生学习中的应用与伦理问题.pdf
免费JAVA毕业设计 2024成品源码+论文+数据库+启动教程 启动教程:https://www.bilibili.com/video/BV1SzbFe7EGZ 项目讲解视频:https://www.bilibili.com/video/BV1Tb421n72S 二次开发教程:https://www.bilibili.com/video/BV18i421i7Dx
"S7-200plc与MCGS智能居家控制系统的深度融合:组态画面、IO分配与梯形图接线图原理详解",No.63 S7-200plc和 MCGS智能居家控制系统组态 带解释的梯形图接线图原理图图纸,io分配,组态画面 ,核心关键词:S7-200plc; MCGS智能居家控制系统; 梯形图接线图原理图; io分配; 组态画面。,"S7-200 PLC与MCGS智能居家系统组态及梯形图原理图解析"
方便暖通工程师及板换用户了解艾齐尔板式换热器选型计算,免费使用。