Spring MVC Thymeleaf错误:实际请求参数未满足参数条件

时间:2017-08-01 18:16:24

标签: java html spring-mvc

我是Spring MVC Thymeleaf的新手,并试图让一些简单的输入/输出工作。下面的代码应该接受文本输入,然后在输出时输出 按下“提交”按钮。但是,我收到以下错误:

  

org.springframework.web.bind.UnsatisfiedServletRequestParameterException:实际请求参数未满足参数条件“submitInput”:

InputHolder.java

public class InputHolder {
    public String input;
}

GreetingController.java

@Controller
public class GreetingController {

    @RequestMapping(value="/greeting", params={"submitInput"})
    public String recieveInput(final InputHolder inputHolder, final BindingResult bindingResult, Model model) {
        model.addAttribute("input", inputHolder.input);
        return "greeting";
    }

}

greeting.html

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Test Page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
    <div>
        <form action="/greeting" th:object="${inputHolder}" method="POST">
            <fieldset>
                <div>
                    <label for="basicInput"></label>
                    <input type="text" th:field="*{basicInput}" />
                </div>
                <div>
                    <button type="submit" name="submitInput">Submit Input</button>
                </div>
                <div>
                    <p th:text="'Output: ' + ${input}"></p>
                </div>
            </fieldset>
        </form>
    </div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

在控制器类中,您使用“params = {”submitInput“}”,这意味着url需要该参数。 好像你没有在url中传递预期的参数“submitInput”,比如

本地主机:8080 / {APPNAME} /问候submitInput = {someinput}