Getting URL Attribute Value in Thymeleaf (#12766)

This commit is contained in:
ACHRAF TAITAI 2022-09-25 20:06:25 +02:00 committed by GitHub
parent efb70f280c
commit 38be954b01
2 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,13 @@
package com.baeldung.thymeleaf.url;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class UrlController {
@GetMapping("/search") public String test(Model model, @RequestParam("query") String query){
return "url/index";
}
}

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div th:if="${param.query != null}">
<p th:text="${param.query }"></p>
</div>
<div th:if="${param.query != null}">
<p th:text="${param.query[0]}" th:unless="${param.query == null}"></p>
</div>
<div th:if="${#request.getParameter('query') != null}">
<p th:text="${#request.getParameter('query')}" th:unless="${#request.getParameter('query') == null}"></p>
</div>
</body>
</html>