Getting URL Attribute Value in Thymeleaf (#12766)
This commit is contained in:
parent
efb70f280c
commit
38be954b01
|
@ -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";
|
||||||
|
}
|
||||||
|
}
|
|
@ -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>
|
Loading…
Reference in New Issue