我想在springboot 2.0.0中有一些复选框。这是我写的:
@Controller
@Transactional
public class AdminController {
@RequestMapping(value = {"/admin/questionForm"},method = RequestMethod.GET)
public String initForm(Model model) {
QuestionForm questionForm = new QuestionForm();
model.addAttribute("questionForm", questionForm);
List<String> types = new ArrayList<String>();
types.add("yes/no");
types.add("Checkbox with multiple selection");
types.add("Radio buttons");
model.addAttribute("types", types);
return "questionForm";
}
@RequestMapping(method = RequestMethod.POST)
public String submitForm(Model model, QuestionForm questionForm,
BindingResult result) {
model.addAttribute("questionForm", questionForm);
return "ProductList";
}
}
在QuestionForm.class中,我定义了两个属性:
private boolean newQuestion;
private List<String> types;
这是questionForm.jsp:
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<html>
<title>Ask</title>
</head>
<body>
<h2>Ask a Question</h2>
<form:form method="POST" commandName="questionForm">
<table>
<tr>
<td>Is this a new Question?</td>
<td><form:checkbox path="newQuestion" />
</td>
</tr>
<tr>
<td>Which type is your question?</td>
<td><form:checkboxes path="types" items="${types}" />
</td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit"></td>
</tr>
<tr>
</table>
</form:form>
</body>
</html>
现在的问题是:
为什么我去http://localhost:8080/admin/questionForm
时不显示questionForm.jsp?
这是错误:
Whitelabel错误页面 此应用程序没有针对/ error的显式映射,因此您将其视为后备。 2019年1月23日星期六11:35:14 发生意外错误(类型=内部服务器错误,状态= 500)。 解决模板“ questionForm”时出错,该模板可能不存在或任何配置的模板解析器都无法访问