我在我的代码中使用thymeleaf,这里的返回类型是String,但我想要返回类型:public response abc(){... ret response}

时间:2017-09-13 08:57:30

标签: java html thymeleaf

@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String helloForm()
{
    return "helloform";
}

@RequestMapping(value = "/hello", method = RequestMethod.POST)
public String hello(HttpServletRequest request,Model model) {

    String name = request.getParameter("name");

    if (name == null) {
        name = "world";
    }
  // do what you want to code....

  model.addAttribute("message",HelloMessage.getMessage(name));
   // return "<h1>" + HelloMessage.getMessage(name) + "</h1>";
    return "hello";
}

1 个答案:

答案 0 :(得分:0)

在方法中尝试@ResponseBody并在模型中设置视图名称。