Emilio Gumayagay
Emilio Gumayagay

Reputation: 69

Creating an update page in Spring using Thymeleaf

I'm trying to create an update page for my spring project, When I try to open my edit page using localhost:8080/edit/1 I get There was an unexpected error (type=Internal Server Error, status=500). Could not parse as expression: "/edit/{stockNumber}" (editItem:78)

What can I do to solve this issue?

 @GetMapping(path="edit/{stockNumber}")
  public String editItemForm(@PathVariable Long stockNumber, Model model){
	  model.addAttribute("item",itemRepository.findOne(stockNumber));
	  return "editItem";
  }
  
 @PostMapping(path="edit/{stockNumber}")
 public String editItem(@ModelAttribute Item item){
	  itemRepository.save(item);
	  return "redirect:/item";
  }
<form action="#" th:object="${item}" th:action="/edit/{stockNumber}" method="post">
  <div class="form-group">
    <label for="txtItemDesc">Item Description</label>
    <input type="text" th:field="*{itemDesc}" class="form-control" id="txtItemDesc" placeholder="item Description" />
  </div>
  <div class="form-group">
    <label for="txtUnit">Unit</label>
    <input type="text" th:field="*{unit}" class="form-control" id="txtUnit" placeholder="Unit" />
  </div>
  <div class="form-group">
    <label for="txtAbc">ABC</label>
    <input type="text" th:field="*{abc}" class="form-control" id="txtAbc" placeholder="ABC" />
  </div>
  <button type="submit" value="Submit" class="btn btn-default">Submit</button>
</form>

Upvotes: 0

Views: 1138

Answers (1)

Branislav Lazic
Branislav Lazic

Reputation: 14806

Your expression in th:action is incorrect. It should be

th:action="'/edit/'+ ${stockNumber}" 

Upvotes: 1

Related Questions