1
我想在我的web應用程序中實現Spring MVC,我有一個控制器類。RequestMapping在Spring MVC中的控制器有時得到改變
@Controller<br>
public class ContactController {
@Autowired<br>
private ContactService contactService;
@RequestMapping("/login")
public String displayLoginPage(HttpServletRequest httpReq, @ModelAttribute("login") Login login, BindingResult result){
return "login";
}
/*Spring will automatically calls this method whenever it encounters "/home" url in request.*/
@RequestMapping("/login/home")
public String displayHomePage(HttpServletRequest httpReq, Map<String, Object> map){
map.put("contact", new Contact());
map.put("contactList", contactService.listContact());
return "contact";
}}
啓動應用程序後,登錄屏幕出現,然後點擊按鈕,我觀察到RequestMapping的值有時會發生變化。有時它是「/ login/home」或有時候是「/ home」。爲什麼這不是恆定的?有什麼方法可以讓我知道requestMapping是什麼,以便我可以將它轉發給控制器中的相應方法?
PS:在login.jsp的,我有這樣的代碼如下:
形式行動= 「家」 的CommandName = 「登陸」
你的'行動'相對**指向'家'。所以如果表單的頁面在'/ login /'下面,'home'就是'/ login/home'。如果頁面位於'/ whatever /'下面,'home'將會是'/ whatever/home'。 – acdcjunior