Fly*_*ine 1 java model-view-controller 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;
}
}
Run Code Online (Sandbox Code Playgroud)
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");
}
}
Run Code Online (Sandbox Code Playgroud)
因此,在成功登录后我尝试重定向到CustomerController但在浏览器网址中我可以看到请求网址是
http://localhost:8080/Online_Fund_Trading/log/Customer/Searchform.spring.由于log之前被添加Customer/Searchform.spring我得到404-The requested resource is not available的错误.
请求url需要进行哪些更改http://localhost:8080/Online_Fund_Trading/Customer/Searchform.spring.
一个简单的斜杠/是必需的
ModelAndView view=new ModelAndView("redirect:/Customer/Searchform.spring");
Run Code Online (Sandbox Code Playgroud)
否则,路径将被视为相对于您当前正在处理的请求的路径.
| 归档时间: |
|
| 查看次数: |
8829 次 |
| 最近记录: |