简体   繁体   中英

Spring MVC URL for the AbstractController

I have a controller that inherits from the org.springframework.web.servlet.mvc.AbstractController class

I have configurated it in this way:

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

so can accepts url of this form

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

but the customer has provided to me the requirement to write URL in this way

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

but I think that is not possible to map this type of URL with my controller. Anyone know the type of configuration that can be used in order to configure this type of URL mapping?

Otherwise, is legal to ask to change the format of the URL in this way

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

so I can manage the command parameter in the "handleRequestInternal" method of my custom controller that inherits from the org.springframework.web.servlet.mvc.AbstractController class??

Don't use the legacy Controller framework, use annotated controllers . There, you can easily use URL templates , something like this:

@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"; 
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM