2016-06-18 3 views
0

이의 내 웹 사이트 이름이 있다고 가정 해 봅시다 : foo.com봄 RequestMapping (/ {사용자})

사용자 유형 foo.com, 내가 index.html을을 표시 할 때.

사용자가 foo.com/something을 입력하면 서버가 요청을 컨트롤러에 전송하려고합니다. 여기

내가 HomeController에서 한 것입니다 : 원형보기 경로 [index.html을 :

@Controller 
public class HomeController { 
    @RequestMapping(value={"/"}, method=RequestMethod.GET) 
    public String getHome() { 
     return "index.html"; 
    } 
} 

그리고, CustomController 요청 그러나

@Controller 
public class CustomController { 
    @RequestMapping(value={"/{custom}"}, method=RequestMethod.GET) 
    public String getCustom(@PathVariable String custom) { 
     // Do something here.. 
    } 
} 

을 잡을해야한다, 그것은 오류가 발생합니다 ] : 현재 처리기 URL [/index.html]로 다시 디스패치합니다. HomeController가 index.html 문자열을 반환 한 후 CustomController가 GET 요청을 캐치하기 때문입니다 : foo.com/index.html.

public class WebMvcConfiguration extends WebMvcConfigurerAdapter { 
    @Override 
    public void addResourceHandlers(ResourceHandlerRegistry registry) { 
     registry.setOrder(Ordered.HIGHEST_PRECEDENCE); 
     registry.addResourceHandler("/assets/**").addResourceLocations("classpath:/assets"); // My asset 
     registry.addResourceHandler("index.html").addResourceLocations("file:/index.html"); 
    } // It's not working 

    @Override 
    public void addViewControllers(ViewControllerRegistry registry) { 
     registry.addViewController("/").setViewName("forward:/" + FileNames.INDEX); 
    } // This also not working 
} 

그리고 CustomController에 @RestController에 @Controller에서 주석을 변경이 옵션을 선택하지 않습니다 :

는이 같은 조사를했다.

또한 프로젝트에 JSP 파일이 없습니다. 일반 * .html 파일입니다. 나는 봄을 1.3.3 버전을 사용하고

My project setup

, 그래서 저를 도와주세요.

답변

0

이 솔루션은 ui-router (AngularJS 라이브러리)과 작동합니다. 또한, 당신은 변경해야 $ resourceProvider 설정 :

// In your app module config 
$resourceProvider.defaults.stripTrailingSlashes = false; 

다음, 봄 서버 코드에, 당신은이 작업을 수행 할 수 있습니다 https://spring.io/blog/2015/05/13/modularizing-the-client-angular-js-and-spring-security-part-vii

:

@RequestMapping(value = "/{custom:[^\\.]*}") 
public String redirect(@PathVariable String custom) { 
    // Do something here... 
    return "forward:/"; 
} 

이 링크에서 해결책을 찾을 수