如何使控制器映射更具体

时间:2016-02-26 16:34:50

标签: java spring

我已将Spring控制器映射定义如下:

@Controller
@RequestMapping("/common")
public class GenericController {

    @RequestMapping(value="/test2", method = RequestMethod.GET)
    public @ResponseBody JsonResponse test2(HttpServletRequest httpRequest, ModelMap model) throws IOException{
        System.out.println("###############");
        return null;
    }

现在,当我启动WL时,我可以看到日志:

- Mapped URL path [/common/test2] onto handler 'genericController'
- Mapped URL path [/common/test2.*] onto handler 'genericController'
- Mapped URL path [/common/test2/] onto handler 'genericController'

不用说上面的日志是真的,所以我可以http://localhost:7001/MyWeb/forms/common/test2http://localhost:7001/MyWeb/forms/common/test2.dohttp://localhost:7001/MyWeb/forms/common/test2/访问我的应用程序。

我确实想要这么多的映射曝光,我希望它只能作为http://localhost:7001/ITDWeb/forms/common/test2访问。

我试图搜索选项但找不到任何选项。有人知道如何使控制器映射更具体吗?

1 个答案:

答案 0 :(得分:1)

您可以定义自己的自定义配置

@Configuration
public class MyWebConfig extends WebMvcConfigurationSupport {
    @Override
    @Bean
    public RequestMappingHandlerMapping requestMappingHandlerMapping() {
        RequestMappingHandlerMapping handlerMapping = super.requestMappingHandlerMapping();
        handlerMapping.setUseSuffixPatternMatch(false); // no prefix matches
        handlerMapping.setUseTrailingSlashMatch(false); // no affix matches
        return handlerMapping;
    }
}