spring REST RequestMethod如何映射一个http LOCK和UNLOCK RequestMapping?
spring REST RequestMethod how to Map a http LOCK and UNLOCK RequestMapping?
好像和
一样
我需要使用 http 方法 LOCK 和 UNLOCK 实现调用。
目前spring的requestMethod只支持
public enum RequestMethod {
GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE
}
如果使用 LOCK 和 UNLOCK http 指令调用 spring 应用程序,我如何实现调用的 @RestController
方法?
您可以使用支持的方法(GET、HEAD、POST、PUT、PATCH、DELETE、OPTIONS、TRACE)调用来完成。下面是内部调用post方法的方法:
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
@Override
@Bean
public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
final RequestMappingHandlerAdapter requestMappingHandlerAdapter = super.requestMappingHandlerAdapter();
requestMappingHandlerAdapter.setSupportedMethods(
"LOCK", "GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "TRACE"
); //here supported method
return requestMappingHandlerAdapter;
}
@Bean
DispatcherServlet dispatcherServlet() {
return new CustomHttpMethods();
}
}
自定义方法处理程序class。这里在内部调用post方法:
public class CustomHttpMethods extends DispatcherServlet {
@Override
protected void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
if ("LOCK".equals(request.getMethod())) {
super.doPost(request, response);
} else {
super.service(request, response);
}
}
}
现在您可以通过以下方式进行请求映射:
@RequestMapping(value = "/custom")
ResponseEntity customHttpMethod(){
return ResponseEntity.ok().build();
}
好像和
我需要使用 http 方法 LOCK 和 UNLOCK 实现调用。
目前spring的requestMethod只支持
public enum RequestMethod {
GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE
}
如果使用 LOCK 和 UNLOCK http 指令调用 spring 应用程序,我如何实现调用的 @RestController
方法?
您可以使用支持的方法(GET、HEAD、POST、PUT、PATCH、DELETE、OPTIONS、TRACE)调用来完成。下面是内部调用post方法的方法:
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
@Override
@Bean
public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
final RequestMappingHandlerAdapter requestMappingHandlerAdapter = super.requestMappingHandlerAdapter();
requestMappingHandlerAdapter.setSupportedMethods(
"LOCK", "GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "TRACE"
); //here supported method
return requestMappingHandlerAdapter;
}
@Bean
DispatcherServlet dispatcherServlet() {
return new CustomHttpMethods();
}
}
自定义方法处理程序class。这里在内部调用post方法:
public class CustomHttpMethods extends DispatcherServlet {
@Override
protected void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
if ("LOCK".equals(request.getMethod())) {
super.doPost(request, response);
} else {
super.service(request, response);
}
}
}
现在您可以通过以下方式进行请求映射:
@RequestMapping(value = "/custom")
ResponseEntity customHttpMethod(){
return ResponseEntity.ok().build();
}