出现意外错误(type = Bad Request,status = 400)。必需的字符串参数' name'不在场

时间:2016-08-18 09:39:28

标签: java

用户可以搜索我的列表中的内容



 <form action="/worldoffragrance">
        <input name="search"/>
        <input type="submit" value="search"/>
&#13;
&#13;
&#13;

如果列出它是空的,我想建立另一个网站,用户可以放置他想要的东西,我该如何解决这个问题? :)

@RequestMapping("/")
public String fragrance() { return "fragrance"; }


@RequestMapping("/worldoffragrance")
public String worldoffragrance(
        @RequestParam(value = "search") String search,
        @RequestParam(value = "operation", required = false, defaultValue = "search") String operation, Model model) {
    List<Fragrance> matchingPerfumes = advisor.findMatchingPerfume(search);
    if (matchingPerfumes.isEmpty()) {
        return "redirect:/fragrancenotfound";
    }
    model.addAttribute("matchingPerfumes", matchingPerfumes);
    return "result";
}

@RequestMapping("/fragrancenotfound")
public String fragranceNotFound(
        @RequestParam(value = "name", required = true) String getName,
        @RequestParam(value = "ingredients", required = true) String getIngredients,
        @RequestParam(value = "operation", required = false, defaultValue = "add" ) String operation, ModelMap model)
 {
     model.addAttribute("getName", "getIngredients");
    return "redirect: /createNewFragrance";
}

@RequestMapping("/createnewfragrance")
public String createnewfragrance() {
    return "createNewFragrance";}

1 个答案:

答案 0 :(得分:0)

您正在重定向到/fragrancenotfound,其中包含您未提供的必需参数name(和ingredient)。提供这些值或使它们不是必需的