我正在尝试为我的spring项目创建更新页面,当我尝试使用localhost打开我的编辑页面时:8080 / edit / 1我得到了 出现意外错误(type = Internal Server Error,status = 500)。 无法解析为表达式:“/ edit / {stockNumber}”(editItem:78)
我该怎么做才能解决这个问题?
@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>
答案 0 :(得分:1)
th:action
中的表达式不正确。它应该是
th:action="'/edit/'+ ${stockNumber}"