Skip to content

Instantly share code, notes, and snippets.

@ScienJus
Created June 5, 2016 13:18
Show Gist options
  • Save ScienJus/2fc2edca912977623939d4310000bb5b to your computer and use it in GitHub Desktop.
Save ScienJus/2fc2edca912977623939d4310000bb5b to your computer and use it in GitHub Desktop.
redirect by handler mapping
package com.scienjus;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import javax.servlet.http.HttpServletRequest;
/**
* @author ScienJus
* @date 16/6/5.
*/
public class ApiHandlerMapping extends RequestMappingHandlerMapping {
private static final String API_PREFIX = "/api/";
@Override
protected HandlerMethod lookupHandlerMethod(String lookupPath, HttpServletRequest request) throws Exception {
if (lookupPath.startsWith(API_PREFIX)) {
lookupPath = lookupPath.substring(API_PREFIX.length() - 1);
}
return super.lookupHandlerMethod(lookupPath, request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment