0

我是 spring mvc3 开发的新手,遇到了一个小问题(我没有遇到 ASP.Net MVC3)。我想知道为控制器定义默认(或登陆)URL 的过程。

我有一个帐户控制器,我负责所有与帐户管理相关的工作。所以我所有的网址都映射到这个控制器。我想知道如何将我的“/accounts”url 请求映射到 hitopenAccountsDashboard方法?

代码 -

.... imports...

@Controller
@RequestMapping(value = "/accounts/*")
public class AccountController {

      @RequestMapping( value = "/", method = RequestMethod.GET)
      public ModelAndView openAccountsDashboard(HttpServletRequest request) {
           .....
           return new ModelAndView("accounts/landing");
      }

      @RequestMapping( value = "/change-password", method = RequestMethod.GET)
      public ModelAndView openPasswordChangePage(HttpServletRequest request) {
           .....
           return new ModelAndView("accounts/passwordChange");
      }
... other actions...

}

任何帮助都会很棒!

谢谢

4

1 回答 1

0

尝试这样的事情:

    .... imports...

@Controller
@RequestMapping(value = "/accounts/")
public class AccountController {

      @RequestMapping( value = "", method = RequestMethod.GET)
      public ModelAndView openAccountsDashboard(HttpServletRequest request) {
           .....
           return new ModelAndView("accounts/landing");
      }

      @RequestMapping( value = "/change-password", method = RequestMethod.GET)
      public ModelAndView openPasswordChangePage(HttpServletRequest request) {
           .....
           return new ModelAndView("accounts/passwordChange");
      }
... other actions...

}

然后你可以像这样使用url:

http://localhost:8080/yourwebapp/accounts/

点击 openAccountsDashboard 方法。问候, 阿雷克

于 2012-08-17T05:55:59.537 回答