the background interface should not be annotated with @ ResponseBody
and then directly return "/ index". This should be fine
that's how you want to write it.
@RequestMapping(value = "/", method = RequestMethod.GET)
public String welcome(){
return "home/welcome.html";
}
The returned address of
should be fully written, starting under static (springboot I use)
you can jump with @ ResponseBody. I'll give you a reference
.
@RequestMapping(value = "/", method = RequestMethod.GET)
@ResponseBody
public String index() {
return "<script>window.location.href='home/welcome.html';</script>";
}
return "redirect:home/welcome.html";
or
@RequestMapping(value = "XX")
@ResponseBody
public String index() {
return
}
then in ajax, according to the identification data window.location.href = home/welcome.html;
to allow background control to adjust, you cannot send a request using ajax.
the action execution request address of the front-end form, and the method specifies the request method;
do not add @ ResponseBody to the background interface to directly return the corresponding redirected page or redirect to another page
help you break down the problem:
using form's default data format is too troublesome. My data nesting is very serious , four layers of list nesting, if the index spelling input name is too painful.
so I want the form form to submit json data, and then submit the data to the background, and then jump to another page based on the data I transferred.
1. First of all, there is a serious problem of data nesting, which can be solved by transferring data in json format. The front end binds the json data to the specified parameter, and the back end receives the parameter and reads it in json format.
2. The second is the problem of redirecting to other pages according to the transmitted data. What you want to achieve is that controller can jump to the view specified by . Please refer to the documentation of spring. The controller can return multiple types as return values. It could be String,Model,Map,ModelAndView. Here you can return the String type to specify the name of the view, or you can return ModelAndView to specify which view.
/**
* @Param btPageReq
* @return
*/
@RequestMapping(value = "/detailUrl", method = RequestMethod.GET)
public String detail(@ModelAttribute("btPageReq") BtPageReq btPageReq, Model model) {
// btPageReq data
model.addAttribute("data", data);
return PREFIX + "/detail.html";
}
ignore your needs and just look at the results. I think you can directly group complex objects at the front end and transfer the ajax to the backend. It seems better for you to jump to the page directly after the callback result is sent to the front end. And can be more convenient to feedback the results of each step, the user experience is better.
ModelAndView/request/session
return "forward:url";