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
Recently, the news that "three communities i...
Small convective cloud Convective clouds are clou...
Generally speaking, there are three main purposes...
1. Developer Registration First, you need to regi...
Recently, many businesses have just come into con...
As one of the earlier Android app stores to be la...
I believe that many operators will encounter this...
Recently, respiratory diseases have been prevalen...
Produced by: Science Popularization China Author:...
2020 has arrived. Many migrant workers who have e...
Review expert: Peng Guoqiu, deputy chief physicia...
A group of hackers spent months targeting Apple...
[[153073]] It may be a little early to predict th...
The China Academy of Information and Communicatio...
According to foreign media reports, the Volkswage...