2016-10-15 12 views
2

私は安らかなAPIのコードを書きました。 localhost:8099/demoproject/restcall.html春のmvcで.htmlを拡張せずに残りのAPIを呼び出す方法はありますか

拡張子なしの方法はありますか?このメソッドを呼び出す方法はありますか? > ONS - ここ

は、ここに私のコード コントローラ

@RestController 
public class demoAPIController { 

    @RequestMapping(value = "/restcall", method = RequestMethod.GET, produces = "application/json") 
    public ResponseEntity<String> GetParseResume() { 
     return new ResponseEntity("hello", HttpStatus.OK); 
    } 
} 

WebAppInitializer

public class WebAppInitializer implements WebApplicationInitializer { 

    @Override 
    public void onStartup(ServletContext servletContext) throws ServletException { 
     WebApplicationContext context = getContext(); 
     servletContext.addListener(new ContextLoaderListener(context)); 
     ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context)); 
     dispatcher.setLoadOnStartup(1); 
     dispatcher.addMapping("*.html"); 
     dispatcher.addMapping("*.pdf"); 
     dispatcher.addMapping("*.json"); 
    } 

    private AnnotationConfigWebApplicationContext getContext() 
    { 
     AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();  
     context.register(WebConfig.class); 
     return context; 
    } 

} 

WebConfig.java

@Configuration 
    @EnableWebMvc 
    @ComponentScan(basePackages = "com.demo") 
    public class WebConfig extends WebMvcConfigurerAdapter { 
     @Bean 
     public InternalResourceViewResolver getInternalResourceViewResolver() { 
      InternalResourceViewResolver viewResolve = new InternalResourceViewResolver(); 
      viewResolve.setPrefix("/WEB-INF/jsp/"); 
      viewResolve.setSuffix(".jsp"); 
      return viewResolve; 
     } 
    } 
+0

https://spring.io/blog/2013/05/11/content-negotiation-using-spring-mvc –

答えて

1

変更

WebAppInitializerですtartup =>

@Override 
    public void onStartup(ServletContext servletContext) throws ServletException { 
     WebApplicationContext context = getContext(); 
     servletContext.addListener(new ContextLoaderListener(context)); 
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context)); 
dispatcher.setLoadOnStartup(1); 
dispatcher.addMapping("/*"); 
} 

のWebConfig =>

@Configuration 
@EnableWebMvc 
public class WebConfig extends WebMvcConfigurerAdapter { 


    @Override 
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { 
    configurer.defaultContentType(MediaType.APPLICATION_XML); 
    } 
} 
+0

、以下を読んで考えてみましょう私は単純なdispatcher.addMapping( "/");どのように異なるのか/ * –

+1

http://stackoverflow.com/questions/4140448/difference-between-and-in-servlet-mapping-url-pattern – kuhajeyan

+0

私はどちらがどの状況に最も適しているか把握していません。答えて少し説明していただけますか? –

関連する問題