Freemarker string manipulation

Source: Internet
Author: User
Tags truncated

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.