Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在SpringMVC中,是否仍然可以在不扩展.html的情况下调用RESTAPI_Java_Spring_Rest_Spring Mvc - Fatal编程技术网

Java 在SpringMVC中,是否仍然可以在不扩展.html的情况下调用RESTAPI

Java 在SpringMVC中,是否仍然可以在不扩展.html的情况下调用RESTAPI,java,spring,rest,spring-mvc,Java,Spring,Rest,Spring Mvc,我为restful api编写了代码。我必须通过调用这个api, localhost:8099/demoproject/restcall.html 每次我必须追加.html时,有没有没有没有扩展名的方法可以调用这个方法 这是我的密码 控制器 @RestController public class demoAPIController { @RequestMapping(value = "/restcall", method = RequestMethod.GET, produces =

我为restful api编写了代码。我必须通过调用这个api, localhost:8099/demoproject/restcall.html

每次我必须追加.html时,有没有没有没有扩展名的方法可以调用这个方法

这是我的密码 控制器

@RestController
public class demoAPIController {

    @RequestMapping(value = "/restcall", method = RequestMethod.GET, produces = "application/json")
    public ResponseEntity<String> GetParseResume() {
        return new ResponseEntity("hello", HttpStatus.OK);
    }
}
这里是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;
        }
    }
改变

WebAppInitializer->onStartup=>

@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("/*");
}
网络配置=>

@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {


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

如果我把简单的调度程序。那么它与/*有什么不同呢?我不知道哪一个最适合哪种情况。你能解释一下吗?@VimalDhaduk,在你的情况下/or/*应该行得通。通常情况下,除非您设置了其他侦听器,否则您将使用/*。/*将覆盖其他servlet,任何请求都将在到达筛选器之前通过您的分派。但在您的应用程序中,它很好,因为它是简单的直接rest应用程序
@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {


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