【发布时间】:2022-10-15 02:19:50
【问题描述】:
基本上,我需要从我的 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 是如何工作的。
【问题讨论】:
-
localhost:8080/hotels/3?id=5是您的 URL 的外观。 item 将是“3”作为 String 和 id 5 作为 Int。 PathVariables = URL 的必需部分。 PathParams = 之后的可选过滤器?部分并由 , 符号分隔。
标签: java spring-boot thymeleaf