我開始學(xué)習(xí)Spring MVC和Web開發(fā)。我的控制器中有這個方法@GetMapping("/deleteCar")public String deleteCar(@RequestParam("carId") int carid) { carService.deleteCar(carid); return "redirect:/car/cars";}如何通過html表單傳遞請求參數(shù)?<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貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超18個贊
您缺少名稱屬性,因此請name
在輸入字段中使用參數(shù)名稱提及屬性。嘗試下面的代碼相同。還添加一個提交類型按鈕來提交表單。
<input type="text" name="carId" id="deleteCarWithID" value="${carId}">
- 1 回答
- 0 關(guān)注
- 102 瀏覽
添加回答
舉報(bào)
0/150
提交
取消