Spring 3.0 forwarding request to different controller

后端 未结 3 434
广开言路
广开言路 2021-01-31 17:44

What is the proper way to forward a request in spring to a different controller?

@RequestMapping({\"/someurl\"})
public ModelAndView execute(Model model) {
    i         


        
3条回答
  •  佛祖请我去吃肉
    2021-01-31 18:06

    Try returning a String instead, and the String being the forward url.

    @RequestMapping({"/someurl"})
    public String execute(Model model) {
        if (someCondition) {
            return "forward:/someUrlA";
        } else {
            return "forward:/someUrlB";
        }
    }
    

提交回复
热议问题