【问题标题】:Thymeleaf returns Null field with ModelAndView bindingThymeleaf 返回带有 ModelAndView 绑定的 Null 字段
【发布时间】: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


【解决方案1】:

Java 赢了这一轮...

经过数小时的查找后唯一的解决方案是恢复到上次提交... 管理员可以关闭/删除问题,谢谢

【讨论】:

    猜你喜欢
    • 2020-10-01
    • 2019-03-09
    • 1970-01-01
    • 1970-01-01
    • 2021-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多