私は安らかな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;
}
}
https://spring.io/blog/2013/05/11/content-negotiation-using-spring-mvc –