Spring MVC - @PathVariable Les points (.) Sont tronqués

Spring MVC - @PathVariable point (.) Est tronqué

Examinez un exemple de Spring MVC@RequestMapping et@PathVariable.

@RequestMapping("/site")
public class SiteController {

    @RequestMapping(value = "/{q}", method = RequestMethod.GET)
    public ModelAndView display(@PathVariable("q") String q) {

        logger.debug("Site : q : {}", q);
        return getModelAndView(q, "site");

    }
//...

Voir les cas suivants:

  1. Pour l'entrée/site/google, «q» afficheragoogle

  2. Pour l'entrée/site/google.com, «q» affichera toujoursgoogle, le point (.) Est tronqué !?

  3. Pour l'entrée/site/google.com.my, «q» afficheragoogle.com, le dernier point (.) Est tronqué!

  4. Pour l'entrée/site/google.com.my.abc, «q» afficheragoogle.com.my

  5. Pour l'entrée/site/cloud.google.com, «q» afficheracloud.google

Le dernier point (.) Est toujours tronqué.

Note
Testé avec le ressort 3 et le ressort 4.

Solution

Pour résoudre ce problème, ajoutez un mappage regex{q:.+} dans@RequestMapping

@RequestMapping("/site")
public class SiteController {

    @RequestMapping(value = "/{q:.+}", method = RequestMethod.GET)
    public ModelAndView display(@PathVariable("q") String q) {

        logger.debug("Site : q : {}", q);
        return getModelAndView(q, "site");

    }
//...

Maintenant, pour l'entrée/site/google.com, «q» affichera lesgoogle corrects