I have two HTML markups, one creates profiles with first name, last name, email and password. And also on the same HTML markup, a list of all profiles is published with a link to go to the second HTML form, on which the person already receives information about the profile, as you understand, in order to get to the second form, you need to click on the link, the fact is that by id it is completely finds and works almost everything perfectly, but there is one thing, it takes me to this page:
localhost:8080/profiles/?1
Accordingly, I do not receive information, and in order to receive it, I must manually change the link to this:
localhost:8080/profiles/1
I have a question, what did I do wrong and why is this happening?
profiles.html:
<div th:method="GET" th:action="@{/profiles/{id}}" th:object="${profileById}">
<p th:text="*{firstName}">
<p th:text="*{lastName}">
<p th:text="*{email}">
</div>
main.html:
<form th:method="POST" th:action="@{/profiles}" th:object="${profile}">
<input type="text" placeholder="Input First Name:" th:field="*{firstName}"/>
<input type="text" placeholder="Input Last Name:" th:field="*{lastName}"/>
<input type="email" placeholder="Input Email:" th:field="*{email}"/>
<input type="password" placeholder="Input Password:" th:field="*{password}"/>
<button type="submit">Create Profile</button>
</form>
<div th:each="profiles : ${profiles}">
<a th:href="@{/profiles/(${profiles.id})}" th:text="*{profiles.firstName}"></a>
</div>
I don’t see much sense in dropping information from controllers services and the repository, the problem is, as I indicated earlier, that th: href throws me to
profiles/?1
and not to
profiles/1 – I need it here
Thank you for your attention
2
Answers
I partially solved my problem, now by clicking on the link I go to the HTML markup where I get the information I need, but now, for some unknown reason, a small problem has appeared in the URL that can hardly even be called a problem, but still I would like to know how to solve it. I'll be back here when I know anything about this.
URL:
main.html:
Video: https://www.youtube.com/watch?v=8niAXQgsT0Y&ab_channel=KnowledgeBase
Use @PathVariable in Controller, The problem solved, good luck everyone.
According to the Standard URL Syntax, the correct syntax for a path variable looks like this: