[英]Spring MVC AngularJS - Post Redirect
我相信我只是缺少明显的东西。
我有一个有效的帖子,但它给了我HTML作为响应。 通常,如果我实际上是想在当前页面上加载更多信息,那会很棒。 但我真的希望它重定向。
MainService.js中的帖子
searchOpportunities : function(title, location) {
return $http
.post(
'/',
$.param({
title : title,
location : location
}),
{
headers : {
'Content-Type' : 'application/x-www-form-urlencoded'
}
})
}
响应
@RequestMapping(value = "/", method = RequestMethod.POST)
public ModelAndView search_Post(@RequestParam(value = "title", required = true) String title, @RequestParam(value = "location", required = true) String location) {
ModelAndView searchView = new ModelAndView("search");
searchView.addObject("searchTitle", title);
searchView.addObject("searchLocation", location);
return searchView;
}
澄清:
发送帖子后,我希望页面更改为searchView。 现在它只是发送HTML作为响应...但是我想使用正确的对象“ searchTitle”和“ searchLocation”进行重定向
因为您只是在POST
之后呈现 searchView
视图,而不是重定向到某个地方。 如果您确实要Redirect
,请使用redirect:
前缀。 假设您有一个/search
端点,并在/
上成功执行POST
后将其重定向到该端点,然后:
@RequestMapping(value = "/", method = RequestMethod.POST)
public String search_Post(@RequestParam(value = "title", required = true) String title, @RequestParam(value = "location", required = true) String location) {
...
return "redirect:/search";
}
如果需要,可以在/search
端点中呈现searchView
。 在此处阅读有关重定向视图的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.