Spring Boot Thymeleaf fill path variable from controller -
on page projects have button navigate collection of clusters belong project.
project , cluster have own controllers.
on projects page have following button:
<td><a th:href="@{/projects/project/{pid}/clusters(pid=${p.id})}" class="btn btn-info" role="button">clusters</a> </td>
this brings me url /projects/project/{pid}/clusters, pid id of project. pid filled in here. on clusters page have button create new cluster. code button:
<a th:href="@{'/projects/project/{pid}/clusters/create'}" class="btn btn-info" role="button">create cluster</a>
when click button following url: /projects/project/%7bpid%7d/clusters/create.
so problem doesn't have pid(id of project) how can pass project id it?
@controller @requestmapping("/projects/project/{pid}/clusters") public class clustercontroller { @requestmapping(value="/create", method = requestmethod.get) public string createcluster(model model){ cluster cluster = new cluster(); model.addattribute("cluster", cluster); return "createcluster"; } @requestmapping(value = "/create", method = requestmethod.post) public string createtestcluster(@pathvariable("pid") integer projectid, @modelattribute("cluster") testcluster cluster){ system.out.println(projectid); project project = this.projectservice.findprojectbyid(projectid); cluster.setproject(project); this.clusterservice.cluster(cluster); return "redirect:/clusters"; }
i'm new spring boot don't know how fix this.
Comments
Post a Comment