What is freemarker? Before we talk about this, we all know that the battle between web and native controls is just that. Performance, loading speed, traffic, data interaction… If I use webView to load a url page, I have to parse the css through the network, parse the html code, and then render the generated page What is freemarker? To put it simply, put the above HTML file into the application in advance, and just pass in the data when using it. Freemarker advantages and applications Save traffic and speed up web page loading For example, some chart functions are more convenient to implement with js library, just put in html template in advance and pass in data. This greatly saves traffic and loading speed Or if you already have a web page, you don't need to create an Android interface. This feature is universal on iOS, so you only need one template to use it on both iOS and Android, which greatly saves development time. Implementation principle WebView loads local template engine process main.tpl ——–> main.ftl+data ————> main.html ————> webView.load(main.html) 1. Import the freemarker library
2. Put the main.tpl file into the assets directory
3. Convert main.tpl to main.ftl
4. Generate main.html file from main.ftl and data
5. WebView loads main.html
Problem points 1. Why do we need to convert mian.tpl into main.ftl file first, instead of putting the mian.ftl file directly into assets, and then directly load the main.ftl file in the template? Because the files in assets cannot be read directly, you need to put the files in data/data/package/… before operating 2. Suddenly found that the 2016 version of freemarker cannot pass objects. For example, in the main.ftl file, ${model.name} can no longer be converted to main.html, and the following error is prompted
The official statement says it is possible, but I have tested it countless times and still cannot compile object transfer. The name can be obtained as follows
The following method cannot obtain the name
Summarize ***I didn't find that the webView page loading was much faster, maybe because the data volume was small. After all, it had to operate the SD card. The traffic was indeed saved, and there was less direct data interaction code between Java and HTML. |
<<: The six easiest programming languages to learn for beginners
>>: Regarding Android adaptation, it is enough to read this article
According to foreign media reports, the BepiColom...
Recently, according to a report by German Wirtsch...
The Douyin Assistant is in the Douyin APP. The wa...
Many conspiracy theories start like this: as long...
Today I will tell you what simple and reliable fu...
Welcome to the 70th issue of the Nature Trumpet c...
[[177050]] Bao Xiehao, Xiaomi MIUI department, he...
This activity was based on the WeChat service acc...
People often say "a glass of wine a day, liv...
Perhaps no one expected that 2020 would hit us ha...
Generally speaking, if you have a good night'...
Preface: At present, with the entry of giants suc...
You have been creating short videos for a while. ...
Introduction to the content of the training course...
On May 15, Taobao made a new move. Alimama issued...