List is frequently used in freemarker.
For example, you need a simple traversal (taking the year as an example) on the page without calling any data, which is very convenient.
Code:
In this case, a problem occurs. When the data exceeds three digits, freemarker automatically uses a comma to intercept the format, for example, 2,008.
How can this problem be solved?
1> Add. tostring (), for example: $ {(userid). tostring ()}
2> Add? C, such as: $ {(userid )? C}
3> Add freemarker configuration file freemarker. PropertiesNumber_format = #
Judge whether it is null:
1. <# If XX? Exists>
2. <# If XX?>
3. <# If XX? Default ("XXX")>
Otherwise, when xxlist has no data, a huge yellow page will be waiting for you.
Data type conversion:
$ {XX? String} // string
$ {XX? Number} // integer
$ {XX? Currency} // decimal number
$ {XX? Percent} // percentage
Truncation String Length:
Sometimes we do not need to display such long strings on the page, such as the news title. In this way, we can use the following columns to customize the display length.
<Lt. <= LTE.> GT.> = GTE
<# If jstbqkvo.gz dd? Length Lt 8>
<A href >$ {jstbqkvo.gz dd? Default ("")} </a>
<# Else>
<A href Title = "zookeeper jstbqkvo.gz dd}" >$ {jstbqkvo.gz dd [0 .. 3]? Default ("")}... </a>
</# If>
This means that if the length of this string is less than 8, it will be displayed normally, and otherwise, it will take four digits.
Nested list:
In many cases, numbers are stored in the database, and the Chinese characters to be displayed on the page are not in the same table. Check the column.
<# List jssklist as jsskvo>
<# List kclist as KCVO>
<# If KCVO. kch = jsskvo. kch> (KCVO contains numbers and names, while jsskvo only has numbers)
$ {KCVO. KCM}
</# If>
</# List>
</# List>
Sort:
1. Ascending. sort_by ()
<# List? Sort_by ("field") as x>
</# List>
2. Descending Order. sort_by ()? Reverse
<# List? Sort_by ("field ")? Reverse as x>
</# List>
Remove space:
$ {XX? Trim}
Format Date:
$ {Date? String ("yyyy-mm-dd hh: mm: SS ")}
$ {Date? String ("yyyymmdd ")}