【发布时间】:2018-12-16 08:01:06
【问题描述】:
所以,我之前有同样的代码工作,我不明白为什么它突然停止工作。
<form action="#" th:action="@{/PostOptions}" th:object="${Obj}" method="post">
<input type="hidden" name="id" th:field="*{id}" />
<td ><input id="viewable" type="text" name="param" th:field="*{param}" /></td>
<td><input type="submit" value="Search brackets" /></td>
</form>
一个用于检索下一阶段搜索参数的简单对象
@Entity
public class SearchParam {
@Id
@GeneratedValue
long id;
private String param;
//Getter & setter & contructor (empty and with param attributes)
这里我将对象绑定到 GET
@RequestMapping(value = "makeOptions")
public ModelAndView makeOptions() {
SearchParam searchParam = new SearchParam();
ModelAndView modelAndView = new ModelAndView("returnPage");
modelAndView.addObject("Obj", searchParam);
return modelAndView;
}
然后尝试在 POST 上阅读它
@RequestMapping(value = "PostOptions", method = RequestMethod.POST)
public ModelAndView postOptions(@ModelAttribute(value = "Obj") @Validated SearchParam param) {
System.out.println(param.getParam() );
//method has other stuff too
但现在我只在打印时得到空值。
这次我错过了什么? 我怎样才能有效地调试这个东西?
【问题讨论】:
-
添加你的getter和setter。
标签: spring-boot post thymeleaf