'Spring boot not saving path variable to database
I currently have a form that allows users to upload data, however, I want to save the path variable to the database for that object. The thymeleaf form action is as follows.
<form th:action="@{/homepage/{room_id}/saveLayout(room_id=${Room.room_id})}" th:object="${layout}" method="post">
This is the controller that the form corresponds to
@PostMapping("/homepage/{room_id}/saveLayout")
public String saveLayout(@ModelAttribute("layout") Layout layout, @PathVariable(value = "room_id")long room_id) {
layout.setroomid(room_id);
layout.Service.saveLayout(layout);
return "redirect:/homepage";
}
The idea is that when a user sends the form after clicking on say room 2, the URL should be
homepage/2/saveLayout
However, the issue is that the URL does not contain the ID of the room, instead it looks like this
homepage//saveLayout
Which in turn causes spring boot to return an error saying the URL contained malicious content '//'. Even after removing the path variables and hard coding an integer 2 into the setroomid method, the room id does not change in the database. I have another controller which directs the user to the form to input the data, this adds attributes layout and room to the model. There are no red underlines in either of the HTML documents within the thymeleaf code. My setroomID method is
public void setroomid(long room_id){
roomid = roomid;
}
I should also make it clear that the actual data uploading works, however the roomID for a layout remains unchanged. If anyone is able to recommend any changes to make this work, or suggest an alternate way of binding a roomID to a layout in the database then it would be appreciated, thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
