AbstractController的Spring MVC URL

时间:2011-07-01 15:21:38

标签: java spring spring-mvc

我有一个继承自org.springframework.web.servlet.mvc.AbstractController类的控制器

我已经用这种方式对其进行了配置:

  <bean name="/gameServiceController.json" class="xx.xxx.GameController"/> 

所以可以接受此表格的网址

 http://<hostname>:<port>/<context-path>/gameServiceController.json 

但是客户向我提供了以这种方式写URL的要求

 http://<hostname>:<port>/<context-path>/createNewGame?parameter=<value> 

但我认为无法将此类型的URL映射到我的控制器。任何人都知道可以使用的配置类型来配置这种类型的URL映射吗?

否则,要求以这种方式更改URL的格式是合法的

     http://<hostname>:<port>/<context-path>/gameServiceController.json?command=createNewGame&phoneNumber=<phoneNumber> 

所以我可以在自定义控制器的“handleRequestInternal”方法中管理命令参数,该方法继承自org.springframework.web.servlet.mvc.AbstractController类??

1 个答案:

答案 0 :(得分:0)

请勿使用旧版Controller框架,请使用annotated controllers。在那里,您可以轻松使用URL templates,如下所示:

@Controller
public class GameController{

    @RequestMapping(value="/createNewGame?parameter={param}",
                    method=RequestMethod.GET)
    public String createNewGame(@PathVariable String param, Model model) {
      // do stuff here
      return "viewName"; 
    }

}