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
After reading this article, you will be able to i...
I just saw an article analyzing Changyu, pointing...
On Mother's Day , We are all calling for mate...
Use UIVisualEffectView to add special effects to ...
Course objectives: With Microsoft Office PowerPoi...
It is often said that "people who don't ...
I saw a joke on WeChat Moments some time ago: &qu...
The westernmost point of China Snow-capped mounta...
On March 11, the Zhejiang Provincial Department o...
The Spring Festival holiday has always been a tim...
In recent years, it is not uncommon to see intern...
Looking at the TV market in the spring of 2016, c...
Regarding OCPX, namely OCPC/ OCPM /OCPA advertisi...
Author: Chen Han, deputy chief physician of Shang...