I wonder how I can shorten the code. I have a select list written in HTML. This is a list of airports. However, it is very long. Too long.
<body> <form action="#" th:action="@{/connect}" th:object="${FlightDTO}" method="post">
<div class="container">
<div class="main">
<h2>Destination</h2>
<select name="myselect" id="myselect" th:field="*{departure}" >
<option value="AALAalesund">Aalborg</option>
<option value="ZID">Aarhus</option>
<option value="AAR">Aarhus</option>
<option value="JEG">Aasiaat</option>
<option value="ABD">Abadan</option>
... etc.
Please help me .
you add add airports to database.
Create Airport java Class
Airport Class
:
public class Airport {
private String name;
private String value;
// setter and getter ...
}
and generate list of airports List<Airport>
and add to model
model.addAttribute("airports", List<Airport> );
and then in html page you can use this:
<option th:each="items : ${airports}"
th:value="${items.value}"
th:text="${items.name}">
</option>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.