【问题标题】:Thymeleaf form not returning json objectThymeleaf 表单不返回 json 对象
【发布时间】:2018-01-04 01:32:14
【问题描述】:

我的 Html 页面没有以 json 对象的形式检索有效负载。相反,它正在返回字符串。任何帮助

HTML 代码片段:

<form th:object="${case}" novalidate="true" data-model="case" action="/hcp/patient/details/insurance" method="POST">

控制器:

@ResponseBody
@RequestMapping(value = {"/hcp/patient/details/insurance"},
        produces = "application/json", method = {RequestMethod.PUT, RequestMethod.POST})
final String updatePatientInsurance(final HttpServletRequest request,
                                    @RequestBody String payload, BindingResult bindingResult)
        throws InvalidFormException, Exception {...

【问题讨论】:

  • 因为payload 是字符串?
  • 应该是字符串化的Json。但是字符串不是json格式的。
  • 这可能会有所帮助:stackoverflow.com/questions/34001725/…
  • 表单无法触发ajax调用,将转换为json。
  • 所以我有一个 ajax 调用,但是当我使用这个表单访问选项卡时,渲染功能没有触发。这就是我发现的问题。期待解决这个问题。完成后会更新。感谢您的回复。

标签: javascript java ajax spring thymeleaf


【解决方案1】:

访问时显式呈现选项卡解决了问题。

P.S:render 函数实际上是把 payload 转换为 JSON 对象

formController.render(tabContent, url);

【讨论】:

    猜你喜欢
    • 2015-10-05
    • 1970-01-01
    • 2019-07-12
    • 1970-01-01
    • 2021-06-30
    • 1970-01-01
    • 1970-01-01
    • 2018-08-11
    • 2014-03-06
    相关资源
    最近更新 更多