无法从一个控制器重定向到另一控制器-Spring MVC


问题内容

我是Spring MVC的新手,面临一些错误。
我有两个控制器,如下所示
1)LoginController.java

@Controller
@RequestMapping("/log")
public class LoginController {
    @Autowired
    private LoginService service;

    @RequestMapping(value="login.spring",method=RequestMethod.GET) 
    public ModelAndView prepareLoginForm()
    {
        System.out.println("In get");
        return new ModelAndView("Login", "login", new Login());
    }

    @RequestMapping(value="login.spring",method=RequestMethod.POST) 
    public ModelAndView processLogin(@ModelAttribute("login") Login login,BindingResult result)
    {
        int i=service.validateLogin(login);
        if(i==0){
            return  new ModelAndView("redirect:login.spring");
        }

        ModelAndView view=new ModelAndView("redirect:Customer/Searchform.spring");


        return view;
    }

}

2) CustomerController.java

@Controller
@RequestMapping("/Customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;


    @RequestMapping(value="Searchform.spring",method=RequestMethod.GET)
    public  ModelAndView prepareCustomer()
    {
        System.out.println("In customer controller");
        CustomerSearchForm customerSearchForm=new CustomerSearchForm();
        return new ModelAndView("CustomerSearch","customerSearchForm",customerSearchForm);

    }


    @RequestMapping(value="Search.spring",method=RequestMethod.POST)
    public  ModelAndView searchCustomer(@ModelAttribute("customer") CustomerSearchForm customerSearchForm,BindingResult result)
    {
        int i=customerService.serachCustomer(customerSearchForm);
        if(i==1)
        return new ModelAndView("Holdings");

        return new ModelAndView("redirect:Customer");
    }
}

因此,成功登录后,我尝试重定向到,CustomerController但在浏览器URL中,我可以看到该请求URL为
http://localhost:8080/Online_Fund_Trading/log/Customer/Searchform.spring。如logCustomer/Searchform.spring我得到404-The requested resource is not available错误之前被添加。

将请求网址设为,需要进行哪些更改http://localhost:8080/Online_Fund_Trading/Customer/Searchform.spring


问题答案:

一个简单的斜杠/是必需的

ModelAndView view=new ModelAndView("redirect:/Customer/Searchform.spring");

否则,该路径将被视为相对于您当前正在处理的请求的路径。