Java 中标名单';按下按钮时不显示(+;字符串参数';类型';不存在)
这是我第一次使用StackOverflow,对于问题摘要中的任何错误,我深表歉意 我正在尝试为视频目录网页创建一个Java 中标名单';按下按钮时不显示(+;字符串参数';类型';不存在),java,html,button,web-development-server,white-labelling,Java,Html,Button,Web Development Server,White Labelling,这是我第一次使用StackOverflow,对于问题摘要中的任何错误,我深表歉意 我正在尝试为视频目录网页创建一个按钮,当按下该按钮时,将返回具有合适类型的电影。这些电影都是静态的,并且都已经为它们分配了一种类型,比如genre='Action',在名为getGenre()的函数中作为字符串返回。 我制作了一个函数,检查每部电影是否有一种类型,然后将它们放入过滤后的列表中,然后作为“目录”返回(我将在下面展示函数代码) 我知道filtered目前包含所有电影,但我想让它在按下按钮时检查HTML文
按钮
,当按下该按钮时,将返回具有合适类型的电影。这些电影都是静态的
,并且都已经为它们分配了一种类型,比如genre='Action',在名为getGenre()
的函数中作为字符串返回。
我制作了一个函数,检查每部电影是否有一种类型,然后将它们放入过滤后的列表中,然后作为“目录”返回(我将在下面展示函数代码)
我知道filtered目前包含所有电影,但我想让它在按下按钮时检查HTML文件中特定类型的字符串类型,然后返回正确的电影
过滤功能:
@PostMapping("/genre")
String dvdCatalog(Model model, @RequestParam("genre") String genre ) {
Iterable<Disc> dvdList = catalog.findByType(DiscType.DVD);
List<Disc> filtered = new ArrayList<Disc>();
for (Iterator<Disc> iterator = catalog.findByType(DiscType.DVD).iterator();
iterator.hasNext(); )
{
Disc disc = iterator.next();
if (disc.getGenre().equals(genre))
{
filtered.add(disc);
}
}
model.addAttribute("catalog", filtered);
model.addAttribute("title", "catalog.bluray.title");
return "catalog";
<form method="post" class="ui form" id="form" th:action="@{/genre}" >
<button type="submit" class="ui button" th:value="'Action'" th:text="Action" id="genre"></button>
</form>
@PostMapping(“/genre”)
字符串DVD目录(模型,@RequestParam(“类型”)字符串类型){
Iterable dvdList=catalog.findByType(DiscType.DVD);
List filtered=new ArrayList();
for(Iterator Iterator=catalog.findByType(DiscType.DVD).Iterator();
迭代器.hasNext();)
{
Disc=iterator.next();
if(disc.getGenre().equals(genre))
{
过滤。添加(光盘);
}
}
model.addAttribute(“目录”,已过滤);
model.addAttribute(“title”、“catalog.bluray.title”);
返回“目录”;
在我对应的HTML文件中,我设置了“Action”按钮,在检查网页时,它可以正常工作,直到我按下Action按钮。我对Web开发非常陌生,不知道它是如何工作的,当按下时,我会看到一个白色标签错误页,我会在下面显示它
html按钮:
@PostMapping("/genre")
String dvdCatalog(Model model, @RequestParam("genre") String genre ) {
Iterable<Disc> dvdList = catalog.findByType(DiscType.DVD);
List<Disc> filtered = new ArrayList<Disc>();
for (Iterator<Disc> iterator = catalog.findByType(DiscType.DVD).iterator();
iterator.hasNext(); )
{
Disc disc = iterator.next();
if (disc.getGenre().equals(genre))
{
filtered.add(disc);
}
}
model.addAttribute("catalog", filtered);
model.addAttribute("title", "catalog.bluray.title");
return "catalog";
<form method="post" class="ui form" id="form" th:action="@{/genre}" >
<button type="submit" class="ui button" th:value="'Action'" th:text="Action" id="genre"></button>
</form>
白标错误:
@PostMapping("/genre")
String dvdCatalog(Model model, @RequestParam("genre") String genre ) {
Iterable<Disc> dvdList = catalog.findByType(DiscType.DVD);
List<Disc> filtered = new ArrayList<Disc>();
for (Iterator<Disc> iterator = catalog.findByType(DiscType.DVD).iterator();
iterator.hasNext(); )
{
Disc disc = iterator.next();
if (disc.getGenre().equals(genre))
{
filtered.add(disc);
}
}
model.addAttribute("catalog", filtered);
model.addAttribute("title", "catalog.bluray.title");
return "catalog";
<form method="post" class="ui form" id="form" th:action="@{/genre}" >
<button type="submit" class="ui button" th:value="'Action'" th:text="Action" id="genre"></button>
</form>
此应用程序没有/error的显式映射,因此您将其视为回退
出现意外错误(类型=错误请求,状态=400)。必需
字符串参数“流派”不存在
org.springframework.web.bind.MissingServletRequestParameterException:
所需的字符串参数“流派”在
org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:204)
我的问题是:为什么我的String
参数不存在,即使我正在HTML中检查它?我不知道如何实现这一点,我不知道为什么它找不到流派参数
如果有人知道你能告诉我是怎么做到的吗?我想理解并从中学习,这很令人沮丧
谢谢
编辑:将id=“genre”更改为name=“genre”已经解决了查找参数的问题(真的非常感谢),但是当我现在按下按钮时,它会显示一个只有按钮的空白页面,那里发生了什么?我如何让它返回我的列表?我认为您的按钮需要name=“genre”
,而不是id
。你说得对,非常感谢页面终于显示出来了,但是当它应该返回具有合适类型的电影时,它是空的。你知道为什么吗?首先要检查的是,你的列表过滤后的
实际上包含一些数据。你可以添加一个system.out.println或附加一个调试器来查看结果发生了什么事。