Output a List using Apache FreeMarker

Suppose you have a list of student names and now you need to output that list student names using Apache FreeMarker. So how do we do it? Let’s find out in this tutorial.

First, I will create a new Maven project as an example:

Output a List using Apache FreeMarker

Apache FreeMarker dependency:

The list.ftl file has no content and it will be used as an Apache FreeMarker template.

Application class has the following content:

As you can see, in the main() method of the Application class, we have a created Configuration object with version 2.3.27 and a Template object using our template file.

Now, to be able to output the list of student names that I have passed into the code above, I will add the contents to the template file list.ftl as follows:

In the code above, I used the <#list> tag of Apache FreeMarker to navigate through all the elements of the student names, assign the value of each element to the variable name, then output the value of this variable uses placeholder ${name}.

Result:

Output a List using Apache FreeMarker

 

Chia sẽ bài viết này ...Share on Facebook
Facebook
0Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin

Add Comment