如何在同一HTML文件中获取模型的两个属性
方法中的代码
@RequestMapping(value = "/cars", params = "request")
public String showSomeAmountCars(HttpServletRequest request, Model model) {
String count = request.getParameter("count");
int parsedCount = Integer.parseInt(count);
model.addAttribute("someCars", carService.getCars(parsedCount));
return "cars";
}
- showeomeamountcars 我在URL链接中使用参数获得了一些汽车。
- 在方法
Showallcars
中,我获得了整个汽车列表。
预期行为
- 如果我请求
/cars
,那么如果我请求/cars?count = 2
,我从HTML文件中获取汽车列表 - ,然后我获得两个列表来自同一HTML文件
问题
的汽车如何在HTML文件中获取两个添加的属性并确保它们不会冲突?
Code
@RequestMapping(value = "/cars", params = "request")
public String showSomeAmountCars(HttpServletRequest request, Model model) {
String count = request.getParameter("count");
int parsedCount = Integer.parseInt(count);
model.addAttribute("someCars", carService.getCars(parsedCount));
return "cars";
}
- In the method
showSomeAmountCars
I get some number of cars using parameter in URL link. - In the method
showAllCars
I get the whole list of cars.
Expected behavior
- if I request
/cars
, then I get the list of cars from the HTML file - if I request
/cars?count = 2
, then I get the list of two cars from the same HTML file
Question
How can I get the two added attributes in the HTML file and make sure they don't conflict?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用这样的可选请求参数:
You can have an optional request parameter like this: