我開始學習Spring MVC和Web開發。我的控制器中有這個方法@GetMapping("/deleteCar")public String deleteCar(@RequestParam("carId") int carid) { carService.deleteCar(carid); return "redirect:/car/cars";}如何通過html表單傳遞請求參數?<section> <form action="${pageContext.request.contextPath}/car/deleteCar"> <input type="text" id="deleteCarWithID" value="${carId}"> </form></section>我收到這個警告:WARNING: Resolved [org.springframework.web.bind.MissingServletRequestParameterException: Required int parameter 'carId' is not present]謝謝你!
1 回答

慕容森
TA貢獻1853條經驗 獲得超18個贊
您缺少名稱屬性,因此請name
在輸入字段中使用參數名稱提及屬性。嘗試下面的代碼相同。還添加一個提交類型按鈕來提交表單。
<input type="text" name="carId" id="deleteCarWithID" value="${carId}">
- 1 回答
- 0 關注
- 105 瀏覽
添加回答
舉報
0/150
提交
取消