BAEL-3012 Spring Request Parameters with Thymeleaf (#7412)
This commit is contained in:
parent
76bb391379
commit
dee7128b92
|
@ -0,0 +1,28 @@
|
||||||
|
package com.example.demo;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class ParticipantController {
|
||||||
|
|
||||||
|
@RequestMapping("/")
|
||||||
|
public String index(
|
||||||
|
@RequestParam(value = "participant", required = false) String participant,
|
||||||
|
@RequestParam(value = "country", required = false) String country,
|
||||||
|
@RequestParam(value = "action", required = false) String action,
|
||||||
|
@RequestParam(value = "id", required = false) Integer id,
|
||||||
|
Model model
|
||||||
|
) {
|
||||||
|
model.addAttribute("id", id);
|
||||||
|
List<Integer> userIds = asList(1,2,3,4);
|
||||||
|
model.addAttribute("userIds", userIds);
|
||||||
|
return "participants";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<h2>Enter participant</h2>
|
||||||
|
<form th:action="@{/}">
|
||||||
|
|
||||||
|
<input type="text" th:name="participant"/>
|
||||||
|
<select name="country">
|
||||||
|
<option value="de">Germany</option>
|
||||||
|
<option value="nl">Netherlands</option>
|
||||||
|
<option value="pl">Poland</option>
|
||||||
|
<option value="lv">Latvia</option>
|
||||||
|
</select>
|
||||||
|
<button type="submit" th:name="action" th:value="in">check-in</button>
|
||||||
|
<button type="submit" th:name="action" th:value="out">check-out</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<th:block th:if="${id != null}">
|
||||||
|
<h2 >User Details</h2>
|
||||||
|
<p>Details for user [[${id}]] ...</p>
|
||||||
|
</th:block>
|
||||||
|
|
||||||
|
<h2>Users</h2>
|
||||||
|
<th:block th:each="userId: ${userIds}">
|
||||||
|
<p>
|
||||||
|
<a th:href="@{/(id=${userId})}"> User [[${userId}]]</a>
|
||||||
|
</p>
|
||||||
|
</th:block>
|
||||||
|
|
||||||
|
</html>
|
Loading…
Reference in New Issue