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
Merchants can freely set the functions and usage ...
The 2nd anniversary celebration of Honor of Kings...
The explosive growth of the mobile game market is...
Today is the 15th day of the seventh lunar month,...
【51CTO.com original article】 [51CTO original arti...
The pixels of smartphone screens have reached a l...
[[319085]] What? A phone that doesn't support...
Autism is becoming the "invisible killer&quo...
On February 1, Tesla officially issued an apology...
From 2006 to 2016, it has been 10 years since You...
Now is the leaf-viewing season in southern my cou...
The general process of implementing a single prod...
Mixed Knowledge Specialized in treating misunders...
On March 5, the Long March 2C rocket successfully...
WeChat Mini Program is an application that users ...