Java Code Examples for org.springframework.web.servlet.mvc.method.RequestMappingInfo#Builder

The following examples show how to use org.springframework.web.servlet.mvc.method.RequestMappingInfo#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CodelessAutoGenerateHandlerMapping.java    From sca-best-practice with Apache License 2.0 6 votes vote down vote up
private RequestMappingInfo createRequestMappingInfo(String codelessName, String action) {
    RequestMappingInfo.Builder builder = RequestMappingInfo
        .paths(resolveEmbeddedValuesInPatterns(new String[] {"/" + codelessName + "/" + action}));
    if ("add".equals(action)) {
        builder.methods(RequestMethod.POST);
    }
    if ("modify".equals(action)) {
        builder.methods(RequestMethod.PUT);
    }
    if ("delete".equals(action)) {
        builder.methods(RequestMethod.DELETE);
    }
    if ("get".equals(action) || Pattern.matches("list.*", action)) {
        builder.methods(RequestMethod.GET);
    }
    builder.mappingName("[" + codelessEntityMetadataMap.get(codelessName).getEntityClass().getSimpleName() + "] "
        + action
        + " mapping");
    return builder.options(this.config).build();
}
 
Example 2
Source File: RequestMappingHandlerMapping.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Create a {@link RequestMappingInfo} from the supplied
 * {@link RequestMapping @RequestMapping} annotation, which is either
 * a directly declared annotation, a meta-annotation, or the synthesized
 * result of merging annotation attributes within an annotation hierarchy.
 */
protected RequestMappingInfo createRequestMappingInfo(
		RequestMapping requestMapping, @Nullable RequestCondition<?> customCondition) {

	RequestMappingInfo.Builder builder = RequestMappingInfo
			.paths(resolveEmbeddedValuesInPatterns(requestMapping.path()))
			.methods(requestMapping.method())
			.params(requestMapping.params())
			.headers(requestMapping.headers())
			.consumes(requestMapping.consumes())
			.produces(requestMapping.produces())
			.mappingName(requestMapping.name());
	if (customCondition != null) {
		builder.customCondition(customCondition);
	}
	return builder.options(this.config).build();
}
 
Example 3
Source File: RequestMappingHandlerMapping.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Create a {@link RequestMappingInfo} from the supplied
 * {@link RequestMapping @RequestMapping} annotation, which is either
 * a directly declared annotation, a meta-annotation, or the synthesized
 * result of merging annotation attributes within an annotation hierarchy.
 */
protected RequestMappingInfo createRequestMappingInfo(
		RequestMapping requestMapping, @Nullable RequestCondition<?> customCondition) {

	RequestMappingInfo.Builder builder = RequestMappingInfo
			.paths(resolveEmbeddedValuesInPatterns(requestMapping.path()))
			.methods(requestMapping.method())
			.params(requestMapping.params())
			.headers(requestMapping.headers())
			.consumes(requestMapping.consumes())
			.produces(requestMapping.produces())
			.mappingName(requestMapping.name());
	if (customCondition != null) {
		builder.customCondition(customCondition);
	}
	return builder.options(this.config).build();
}
 
Example 4
Source File: BladeRequestMappingHandlerMapping.java    From blade-tool with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nullable
private RequestMappingInfo getApiVersionMappingInfo(Method method, Class<?> handlerType) {
	// url 上的版本,优先获取方法上的版本
	UrlVersion urlVersion = AnnotatedElementUtils.findMergedAnnotation(method, UrlVersion.class);
	// 再次尝试类上的版本
	if (urlVersion == null || StringUtil.isBlank(urlVersion.value())) {
		urlVersion = AnnotatedElementUtils.findMergedAnnotation(handlerType, UrlVersion.class);
	}
	// Media Types 版本信息
	ApiVersion apiVersion = AnnotatedElementUtils.findMergedAnnotation(method, ApiVersion.class);
	// 再次尝试类上的版本
	if (apiVersion == null || StringUtil.isBlank(apiVersion.value())) {
		apiVersion = AnnotatedElementUtils.findMergedAnnotation(handlerType, ApiVersion.class);
	}
	boolean nonUrlVersion = urlVersion == null || StringUtil.isBlank(urlVersion.value());
	boolean nonApiVersion = apiVersion == null || StringUtil.isBlank(apiVersion.value());
	// 先判断同时不纯在
	if (nonUrlVersion && nonApiVersion) {
		return null;
	}
	// 如果 header 版本不存在
	RequestMappingInfo.Builder mappingInfoBuilder = null;
	if (nonApiVersion) {
		mappingInfoBuilder = RequestMappingInfo.paths(urlVersion.value());
	} else {
		mappingInfoBuilder = RequestMappingInfo.paths(StringPool.EMPTY);
	}
	// 如果url版本不存在
	if (nonUrlVersion) {
		String vsersionMediaTypes = new BladeMediaType(apiVersion.value()).toString();
		mappingInfoBuilder.produces(vsersionMediaTypes);
	}
	return mappingInfoBuilder.build();
}