【问题标题】:I am using thymeleaf in my code and here the return type is String but i want return type like : Public response abc(){...ret response}我在我的代码中使用 thymeleaf,这里的返回类型是 String,但我想要返回类型,如:Public response abc(){...ret response}
【发布时间】:2017-09-13 17:40:13
【问题描述】:
@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";
}

【问题讨论】:

  • 但我希望返回类型为响应,例如:Public response abc(){...ret response} 帮我解决这个问题。

标签: java html thymeleaf


【解决方案1】:

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

【讨论】:

  • 没有得到您的解决方案..什么是视图名称????我是 thymeleaf 的新手...感谢您的回复!!!
  • ModelAndView 类。 public String hello(HttpServletRequest request,ModelAndView mav) { mav.setViewName("viewName"); }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-06-22
  • 2011-11-12
  • 1970-01-01
  • 2021-12-24
  • 1970-01-01
  • 2014-09-17
  • 1970-01-01
相关资源
最近更新 更多