Freemarker expressions are very flexible for string manipulation, you can concatenate string constants and variables, you can return substrings of strings, and so on.
There are two kinds of syntax for string connections: 1, using ${...} Or #{...} Inserts the value of the expression in the string constant section to complete the string connection. 2, connect the string directly using the Join operator +
For example, there is the following data model: Map root = new HashMap (); Root.put ("User", "Annlee"); The user variables and constants are concatenated as follows: ${"Hello, ${user}!"} Use the first syntax to connect ${"Hello," + user + "!"} Using the + sign to connect the above output string is hello,annlee!, you can see the effect of the two syntax is exactly the same.
It is worth noting that the ${...} Can only be used for text parts and cannot be used in expressions, the following code is wrong: < #if ${isbig}>wow!</#if > < #if "${isbig}" >wow!</#if > should be written as: <# If isbig>wow!</#if >
The Intercept substring can be based on the index of the string, and if only one index value is specified when the substring is truncated, the character corresponding to the specified index in the string is obtained, and if two index values are specified, the string substring in the middle of the two index is returned. If you have the following data model: Map root = new HashMap ( ); Root.put ("book", "Struts2,freemarker"); The substring can be truncated by the following syntax: ${book[0]}${book[4]}//Result su ${book[1..4]}//result is Tru
Freemarker string manipulation