首先,当然是新建一个Word文档啦,然后编辑好你所需要的格式,比如字体颜色加粗表格什么之类的,然后再你需要从数据库获取的值用${data}来表示,一般推荐用${(data)!},可以判断是否为空值,空值则跳过不填,否则会出错,就像下面的例子:
然后,另存为xml格式,再把文件重命名为.ftl后缀就可以啦,使用的时候就能引用它啦!
附我的一个Demo:
http://download.youkuaiyun.com/detail/love_java_cc/9389390
墨衍会员
·
AI 创作全网分发
墨衍智能分发
本文由作者通过墨衍一键同步至各平台
1分发平台
1.2k累计阅读
1.3k平均单平台
已同步平台
优快云
微信公众号
微博
知乎
掘金
百家号
博客园
抖音
小红书
你的文章也可以这样分发
墨衍会员 ¥399起/年,写一次发全网
我也要 →
码龄12年
首先,当然是新建一个Word文档啦,然后编辑好你所需要的格式,比如字体颜色加粗表格什么之类的,然后再你需要从数据库获取的值用${data}来表示,一般推荐用${(data)!},可以判断是否为空值,空值则跳过不填,否则会出错,就像下面的例子:
然后,另存为xml格式,再把文件重命名为.ftl后缀就可以啦,使用的时候就能引用它啦!
附我的一个Demo:
http://download.youkuaiyun.com/detail/love_java_cc/9389390
基于模板的Java Word文件生成实用指南
Apache POI是一个开源的Java库,它允许开发者在不安装Microsoft Office的情况下创建、修改和读取Microsoft Office格式的文件。支持多种Microsoft Office文档格式,包括Word(.doc和.docx)、Excel(.xls和.xlsx)和PowerPoint(.ppt和.pptx)。FreeMarker自2000年诞生以来,已经成为Java平台下最受欢迎的模板引擎之一。
FreeMarker
Spring通过FreeMarker模板生成pdf报告
freemarker语法完整版
Freemarker页面语法 A 概念 最常用的 3 个概念 sequence 序列,对应java 里的list 、数组等非键值对的集合 hash 键值对的集合 namespace 对一个ftl 文件的引用, 利用这个名字可以访问到该ftl 文件的资源 B 指令 if, else, elseif 语法 Java代码 ... ... ... ... ... ... ... ... ... ... 用例 Freemarker代码 x is 1 x is 1 x is not 1 x is 1 x is 1 x is not 1 switch, case, default, break 语法 Freemarker代码 ... ... ... ... ... ... ... ... ... ... 用例 字符串 Freemarker代码 This will be processed if it is small This will be processed if it is medium This will be processed if it is large This will be processed if it is neither This will be processed if it is small This will be processed if it is medium This will be processed if it is large This will be processed if it is neither 数字 Freemarker代码 1 2 d 1 2 d 如果x=1 输出 1 2, x=2 输出 2, x=3 输出d list, break 语法 Freemarker代码 ... ... ... ... 关键字 item_index:是list当前值的下标 item_has_next:判断list是否还有值 用例 Freemarker代码 ${x_index + 1}. ${x}, ${x_index + 1}. ${x}, 输出: 1.winter, 2.spring, 3.summer, 4.autumn include 语法 Freemarker代码 或则 Java代码 options包含两个属性 encoding="GBK" 编码格式 parse=true 是否作为ftl语法解析,默认是true,false就是以文本方式引入.注意在ftl文件里布尔值都是直接赋值 的如parse=true,而不是parse="true" 用例 /common/copyright.ftl 包含内容 Ftl代码 Copyright 2001-2002 ${me} All rights reserved. Copyright 2001-2002 ${me} All rights reserved. 模板文件 Java代码 Some test Yeah ___________________________________________________________________________ Some test Yeah ___________________________________________________________________________ 输出结果: Some test Yeah. Copyright 2001-2002 Juila Smith All rights reserved. Import 语法 Freemarker代码 类似于java里的import,它导入文件,然后就可以在当前文件里使用被导入文件里的宏组件 用例 假设mylib.ftl 里定义了宏copyright 那么我们在其他模板页面里可以这样使用 Freemarker代码 <#-- "my"在freemarker里被称作namespace --> <#-- "my"在freemarker里被称作namespace --> compress 语法 Freemarker代码 ... ... 用来压缩空白空间和空白的行 escape, noescape 语法 Freemarker代码 ... ... ... ... ... ... 用例 主要使用在相似的字符串变量输出,比如某一个模块的所有字符串输出都必须是html安全的,这个时候就可以使用 该表达式 Freemarker代码 First name: ${firstName} Last name: ${lastName} Maiden name: ${maidenName} First name: ${firstName} Last name: ${lastName} Maiden name: ${maidenName} 相同表达式 Ftl代码 First name: ${firstName?html} Last name: ${lastName } Maiden name: ${maidenName?html} First name: ${firstName?html} Last name: ${lastName } Maiden name: ${maidenName?html} assign 语法 Freemarker代码 <#-- 或则 --> <#-- 或则 --> <#-- 或则 --> capture this <#-- 或则 --> capture this <#-- 或则 --> <#-- 或则 --> <#-- 或则 --> capture this <#-- 或则 --> capture this 用例 生成变量,并且给变量赋值 给seasons赋予序列值 Ftl代码 给变量test加1 Ftl代码 给my namespage 赋予一个变量bgColor,下面可以通过my.bgColor来访问这个变量 Ftl代码 将一段输出的文本作为变量保存在x里 Ftl代码 ${n} Number of words: ${x?word_list?size} ${x} Hello ${user}! error true ${n} Number of words: ${x?word_list?size} ${x} Hello ${user}! error true 同时也支持中文赋值,如: Ftl代码 java ${语法} java ${语法} 打印输出: java global 语法 Freemarker代码 <#--或则--> <#--或则--> capture this <#--或则--> <#--或则--> capture this 全局赋值语法,利用这个语法给变量赋值,那么这个变量在所有的namespace [A1] 中是可见的, 如果这个变量被当前的assign 语法覆盖 如 在当前页面里x=2 将被隐藏,或者通过${.global.x} 来访问 setting 语法 Freemarker代码 用来设置整个系统的一个环境 locale number_format boolean_format date_format , time_format , datetime_format time_zone classic_compatible 用例 假如当前是匈牙利的设置,然后修改成美国 Ftl代码 ${1.2} ${1.2} ${1.2} ${1.2} 输出 1,2 1.2 因为匈牙利是采用", "作为十进制的分隔符,美国是用". " macro, nested, return 语法 Freemarker代码 ... ... ... ... ... ... 用例 Ftl代码 Test text, and the params: ${foo}, ${bar}, ${baaz} Test text, and the params: ${foo}, ${bar}, ${baaz} 输出 Test text, and the params: a, b, 23 Test text, and the params: a, b, -1 Test text, and the params: a, Bar, 23 Test text, and the params: a, Bar, -1 定义循环输出的宏 Ftl代码 ${title?cap_first}: *${x?cap_first} ${title?cap_first}: *${x?cap_first} 输出结果: Animals: *Mouse *Elephant *Python 包含body 的宏 Ftl代码 ${c}. ${halfc} Last! ${c}. ${halfc} Last! 输出 1. 0.5 2. 1 3. 1.5 4. 2 Last! t, lt, rt 语法 Freemarkder代码 去掉左右空白和回车换行 去掉左边空白和回车换行 去掉右边空白和回车换行 取消上面的效果 去掉左右空白和回车换行 去掉左边空白和回车换行 去掉右边空白和回车换行 取消上面的效果 C 一些常用方法或注意事项 表达式转换类 ${expression} 计算expression 并输出 #{ expression } 数字计算#{ expression ;format} 安格式输出数字format 为M 和m M 表示小数点后最多的位数,m 表示小数点后最少的位数如#{121.2322;m2M2} 输出121.23 数字循环 1..5 表示从1 到5 ,原型number..number 对浮点取整数 ${123.23?int} 输出 123 给变量默认值 ${var?default("hello world")?html} 如果var is null 那么将会被hello world 替代 判断对象是不是 null Ftl代码 Mouse found Mouse found 也可以直接${mouse?if_exists})输出布尔形 -------------------------------------------- (1)解决输出中文乱码问题: freemarker乱码的原因: 没有使用正确的编码格式读取模版文件,表现为模版中的中文为乱码 解决方法:在classpath上放置一个文件freemarker.properties,在里面写上模版文件的编码方式,比如 default_encoding=UTF-8 locale=zh_CN 注意:eclipse中除了xml文件、java文件外,默认的文件格式iso8859-1 数据插入模版时,没有使用正确的编码,表现出模版中的新插入数据为乱码 解决方法:在result的配置中,指定charset,s2的FreemarkerResult.java会将charset传递freemarker /pages/Person/view.ftl text/html;charset=UTF-8 (2)提高freemarker的性能 在freemarker.properties中设置: template_update_delay=60000 避免每次请求都重新载入模版,即充分利用cached的模版 (3)尽量使用freemarker本身的提供的tag,使用S2 tags 的标签会在性能上有所损失 (4)freemarker的标签种类: ${..}:FreeMarker will replace it in the output with the actual value of the thing in the curly brackets. They are called interpolation s. # ,代表是FTL tags(FreeMarker Template Language tags) ,hey are instructions to FreeMarker and will not be printed to the output ... @ ,代表用户自定义的标签 <#-- --> 注释标签,注意不是<!-- --> (5)一些特殊的指令: r代表原样输出:${r"C:\foo\bar"} ${x} ?引出内置指令 String处理指令: html:特殊的html字符将会被转义,比如"<",处理后的结果是< cap_first 、lower_case 、upper_case trim :除去字符串前后的空格 sequences处理指令 size :返回sequences的大小 numbers处理指令 int:number的整数部分,(e.g. -1.9?int is -1) (6)对于null,或者miss value,freemarker会报错 ?exists:旧版本的用法 !:default value operator,语法结构为: unsafe_expr !default_expr,比如 ${mouse!"No mouse."} 当mouse不存在时,返回default value; (product.color)!"red" 这种方式,能够处理product或者color为miss value的情况; 而product.color!"red"将只处理color为miss value的情况 ??: Missing value test operator ,测试是否为missing value unsafe_expr ?? :product.color??将只测试color是否为null (unsafe_expr )??:(product.color)??将测试product和color是否存在null Ftl代码 <#if mouse??> Mouse found No mouse found Creating mouse... <#if mouse??> Mouse found No mouse found <#if mouse??> Mouse found No mouse found Creating mouse... <#if mouse??> Mouse found No mouse found (7)模版值插入方式 (interpolation) 通用方式 ( Universal interpolations): ${expression } 对于字符串:只是简单输出 对于数值,会自动根据local确定格式,称为human audience,否则称为computer audience,可以"?c", 比如, Details...,因此这里的id是给浏览器使用的,不需要进行格式化,注意?c只对数值有效 对于日期,会使用默认的日期格式转换,因此需要事先设置好默认的转换格式,包括date_format , time_format ,atetime_format 对于布尔值,不能输出,会报错并停止模版的执行,比如${a = 2} 会出错,但是可以 string built-in来进行转换 数值处理,具体参考:Built-ins for numbers http://freemarker.org/docs/ref_builtins_number.html#ref_builtin_string_for_number 数值处理的例子: ${answer} ${answer?string} <#-- the same as ${answer} --> ${answer?string.number} ${answer?string.currency} ${answer?string.percent} 除了使用内置的formate,可以使用任何用Java decimal number format syntax 书写的formate,比如 ${1234} ${12345?string("0.####E0")} 更加方便的格式: US people writes: ${12345678?string(",##0.00")} Hungarian people writes: ${12345678?string(",##0.00")} 日期处理,参考Built-ins for dates http://freemarker.org/docs/ref_builtins_date.html#ref_builtin_string_for_date 日期处理的例子: ${openingTime?string.short} ${openingTime?string.medium} ${openingTime?string.long} ${openingTime?string.full} ${nextDiscountDay?string.short} ${nextDiscountDay?string.medium} ${nextDiscountDay?string.long} ${nextDiscountDay?string.full} ${lastUpdated?string.short} ${lastUpdated?string.medium} ${lastUpdated?string.long} ${lastUpdated?string.full} 注意: 由于java语言中的Date类型的不足,freemarker不能根据Date变量判断出变量包含的部分(日期、时间还是全部),在这种情况下,freemarker 不能正确显示出${lastUpdated?string.short} 或者 simply ${lastUpdated},因此,可以通过?date, ?time and ?datetime built-ins 来帮助freemarker来进行判断,比如${lastUpdated?datetime?string.short} 除了使用内置的日期转换格式外,可以自己指定日期的格式,使用的是Java date format syntax,比如: ${lastUpdated?string("yyyy-MM-dd HH:mm:ss zzzz")} ${lastUpdated?string("EEE, MMM d, ''yy")} ${lastUpdated?string("EEEE, MMMM dd, yyyy, hh:mm:ss a '('zzz')'")} 数值专用方式 ( Numerical interpolations):#{expression } or #{expression ; format },这是数值专用的输出方式,但是 最好使用通用方式的string built-in或者number_format 来完成转换,Numerical interpolations方式将会被停用 (8)创建自定义模版 Ftl代码 Hello Joe! 评论这张 转发至微博
java使用Freemarker、Flying sauser生成pdf,中文不显示、设置页眉、换页、红色中文字体不能加粗显示、中文不能换行解决...
因为做这个很坑,花了几天时间,终于爬出来了,为了实现功能,借鉴了很多代码,找起来很麻烦,现整合一下,方便使用,所以记录下。 首先上两个效果图: 需求图1:demo图2: 做了个demo导出pdf,demo的看不出换行,懒得去加数据了,所以把自己用的图发出来。 本人使用的jar包: freemarker-2.3.22.jar,flying-saucer-core-9.1.1...
机器学习(三) ----------线性回归算法(梯度下降+正则化)
线性回归算法在机器学习中具有核心地位,它以其简单性和直观性为基础,为理解数据间的关系提供了基本框架。作为许多复杂算法的基础,线性回归不仅用于预测目标变量,还用于解释自变量对目标的影响。同时,它也是机器学习入门的经典算法,对于推广机器学习知识和技术具有重要意义。
从仿真到真机:如何将XTDrone的VINS-Fusion+RTABMap建图方案部署到真实无人机上?
本文详细介绍了如何将XTDrone的VINS-Fusion+RTABMap建图方案从仿真环境迁移到真实无人机上。内容涵盖硬件选型、传感器配置、VINS-Fusion调优、RTABMap性能优化以及系统集成等关键步骤,特别针对三维稠密重建在真实环境中的挑战提供了实用解决方案。
word导出ftl中常见的标签(Freemarker)
注:上面表示的是上边距为2厘米,下边距为0.4厘米,左边距为3厘米,右边距为2厘米。
使用下一代的嵌入式IDE-PlatformIO 教程
1.生成工程 1.1 打开STM32CubeMX: 选择你的MCU,这里我用的是STM32F103RC RCC中开启外部HSE时钟,外部时钟比HSI更稳定些 开启DEBUG 4线 打开串口1用于打印调试信息,波特率115200,校验位0,停止位1 打开串口2用于MODBUS协议,波特率9600,校验位0,停止位1 接入RT-thread:参考官方文档 基于 CubeMX 移植 RT-Thread Nano 根据官方文档,需要1.取消生成HardFault_Handler、PendSV_Handler、Sy
flex 字体加粗
默认的情况在flex中 对label进行字体加粗的时候,只能对英文的字体加粗,而中文的就不可以加粗; 为了能够使中文能够加粗,需要将label的字体修改成中文的“宋体”或者“微软雅黑”等中文字体,然后将fontFamily设置为bold即可;例子如下: <s:Label text="标签:" fontWeight="bold" fontFamily="微软雅黑" fontSize...
【TCN回归预测】TCN时间卷积神经网络数据回归预测(多输入单输出)【含Matlab源码 2317期】
TCN时间卷积神经网络数据回归预测 完整的代码,方可运行;可提供运行操作视频!适合小白!
【某音电商】protobuf聊天协议逆向
某音电商私信、聊天消息protobuf协议逆向分析与解析
Freemarker模板生成Word,特殊字符处理的三种方法
方法一:处理字段中指定的特殊字符 可灵活转义待处理的特殊字符,但是如果所有字段都需要转移的话,就比较繁琐,不推荐使用 content = content.replace("<", "<"); content = content.replace(">", ">"); content = content.replace("&", "&"...
手把手教你完成基于YOLOv8的水果/商品/食堂/蔬菜/饮料/书籍识别与计价系统,前台+后台管理系统
手把手教你完成基于YOLOv8的商店的水果/商品/食堂/蔬菜/饮料/书籍识别与计价系统,前台+后台管理员系统,可进行目标检测的操作和展示,实现对图片、视频和摄像头的实时目标检测
总结一下最近用freemarker生成word然后转pdf踩得坑
最近在项目开发中有需要是将数据生成word然后再转成pdf下载的功能,使用的是freemarker模板生成word,然后再用aspose-words将word转成pdf的思路 首先是生成word 1.拿到需要生成的word模板 2.将模板转成xml文件,切记千万别直接改后缀名,要使用另存为 3.将生成的xml文件后缀名改为ftl 4.放到idea中,使用alt+ctrl+L格式化,然后将你要填入的数据用字符占位 相关的list、map、if去网上查找 5.插入数据生成word String file
利用插件扩展 Qt 应用程序
不仅 Qt 本身可以通过插件进行扩展,而且 Qt 应用程序也可以通过插件来扩展,这需要应用程序使用 `QPluginLoader` 检测和加载插件。
13、超声断层乳腺图像融合算法:乳腺癌诊断新突破
本文介绍了一种新型超声断层乳腺图像融合算法,通过结合超声透射(UTTc、UTTα)和反射断层图像(URT),实现对乳腺组织的多参数自动可视化。该算法能有效区分良性与恶性肿瘤,具有高准确性、无辐射、低成本等优势,适用于大规模乳腺癌早期筛查。初步临床测试验证了其可行性,未来有望成为乳腺癌诊断的新标准。
SpringBoot 中使用 freemarker 模板文件动态生成/导出 word 文档
SpringBoot 中使用 freemarker 模板文件动态生成/导出 word 文档
IDEA的使用指南
IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.
java用模板生成word(docx)文档(含动态表格)
java导出word
深度学习工具包 DeepLearningToolbox
深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[](https://bitdeli.com/free "Bitdeli Badge")
锂电池充电器电路设计 里面有电路
锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。
使用Freemarker模板引擎生成word
FreeMarker 是一款 模板引擎: 即一种基于模板和要改变的数据, 并用来生成输出文本(HTML网页,电子邮件,配置文件,源代码等)的通用工具。它不是面向最终用户的,而是一个Java类库,是一款程序员可以嵌入他们所开发产品的组件。模板编写为FreeMarker Template Language (FTL)
廖雪峰Python教程[完整版]
廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白
通过freemarker生成word
通过freemarker将数据导出到word的模板中。 //新的接口,改为web页面填写生成word @RequestMapping(value="/insertProcess.do") public @ResponseBody Object insertProcess(HttpServletRequest req ) { String activityId = (Strin
JAVA 基于模板生成 Word 文件
基于模板生成 Word 文档是一种常见的需求,特别是在需要生成带有固定格式和动态数据的报表或文档时。本篇文章采用 Freemarker 模板引擎为例,详细描述了从编写 Word 模板到 Java 中基于模板填充参数并生成 Word 文档的过程。附带完整测试 Demo 代码以及测试过程图片。
springboot项目中利用Freemarker模板生成word文档-包含表格和图片
标题因项目需要导出word报告,就研究了一下java生成word,网上的文章无非就是那几种方式,最简单的还是使用Freemarker的模板导出word,下面简单介绍使用方法: Freemarker介绍: FreeMarker是一款模板引擎: 即一种基于模板和要改变的数据, 并用来生成输出文本(HTML网页、电子邮件、配置文件、源代码等)的通用工具。 它不是面向最终用户的,而是一个Java类库,是一款程序员可以嵌入他们所开发产品的组件。 FreeMarker是免费的,基于Apache许可证2.0版本发布。其模
JAVA利用FreeMarker生成(导出)Word文档
首先下载相应的jar包:freemarker.jar自定义Word模板,将需要填入数据的空格使用“${xxx}”替换,另存为.XML文件 图1另存为xml格式如下: 图2使用编辑器打开XML文件,使用在线XML格式化美化下XML代码,网址如:http://web.chacuo.net/for...
java生成word文档
最近工作需要从数据库查询数据,代码生成word文档,便在网上查询了一下办法。之前类似的工作也曾经做过,当时是在word模板中设置标记,在代码中填充标记。当前网络上简便的方法也是类似,word文档不是凭空生成的,需要先设计一个word模板,在文档中需要从数据库取值的地方,用${参数名}代替(如图一)。 java代码生成Word文档示例 下面提一下主角,freemarker,一个基于模板和源数据来生...
Java Freemarker生成word
JavaFreemarker生成word freeMaker简介: FreeMarker是一款模板引擎:即一种基于模板和要改变的数据, 并用来生成输出文本(HTML网页、电子邮件、配置文件、源代码等)的通用工具。它不是面向最终用户的,而是一个Java类库,是一款程序员可以嵌入他们所开发产品的组件。 FreeMarker是免费的,基于Apache许可证...
使用freemarker模板导出word文档
最近项目中要使用到导出word这项功能,参考了许多导出的方法,发现使用freemarker模板导出word的效果最好可以保持原样。 导入freemarker的架包 1.首先我们需要用word制作一份模板,打开word编辑我们想要的word样式。 如图: 2.在需要填写的地方用变量来代替。如果有图片需要先用图片来填充。然后另存为xml文件,然后再把后缀名改为.ftl的格式 3.处理...
1405

被折叠的 条评论
为什么被折叠?



