基本上,我需要從我的 URL 中獲取資料。
HTML 代碼如下所示:
<h4><a th:text="${h.nombre}" class="card-title" style="color: #1c1f23;text-decoration: none;" th:href="@{/hoteles/{id}(id=${h.getId()})}"></a></h4>
我得到的那種 URL 的例子:
localhost:8080/hoteles/3
現在,我需要得到那個號碼并將其放在控制器上。
我當前的控制器如下所示:
@RequestMapping("/hoteles/{item}")
public @ResponseBody ModelAndView resultadoHotel(@PathVariable(value="item") String numerito,
@RequestParam Integer id) {
List<Hotel> listaHoteles = hotelService.getAll();
BuscadorID numero = new BuscadorID(id);
Hotel definitivo = buscadorService.Comparar(numero,listaHoteles);
ModelAndView model = new ModelAndView("hotelWeb");
model.addObject("definitivo", definitivo);
return model;
}
我只是不知道我是否做錯了什么。我不明白 RequestParam 是如何作業的。
uj5u.com熱心網友回復:
在沒有值的 RequestParam 中,默認情況下,它根據檔案需要一個空字串。試試這個...
@RequestMapping("/hoteles/{item}") public @ResponseBody ModelAndView resultadoHotel(@PathVariable(value="item") String numerito,
@RequestParam(value = "id") Integer id) { List listaHoteles = hotelService.getAll(); BuscadorID 編號 = 新 BuscadorID(id); 酒店定義 = buscadorService.Comparar(numero,listaHoteles); ModelAndView 模型 = new ModelAndView("hotelWeb"); model.addObject(“定義”,定義);回傳模型;}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/513991.html
標籤:爪哇弹簧靴百里香叶
上一篇:SpringJPADerivedDeletewithOptionalReturnType回傳已洗掉的物體計數而不是已洗掉的物體
