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
This article will share with you the promotion ex...
In the second half of the mobile Internet, it has...
Rong'er's "60-Day Special Forces for ...
In recent months, the famous mathematician Terenc...
According to statistics from the World Health Org...
Since its large-scale launch in 2016, TWS earphon...
In 2019, Qiwen Education, a local K12 education a...
With the continuous development of the Internet, ...
Mobile payment has penetrated into our daily life...
Oyster sauce is a common seasoning in the kitchen...
I have been in the Internet circle for 6 years an...
As the concept of health has gained popularity, h...
Community has always been a very hot topic. I stu...
The big explosion of the sun's death created ...
In the current market environment, product promot...