org.springframework.web.bind.annotation.MatrixVariable Java Examples

The following examples show how to use org.springframework.web.bind.annotation.MatrixVariable. 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 Project: es   Author: zhangkaitao   File: CategoryController.java    License: Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = {"select/{selectType}", "select"}, method = RequestMethod.GET)
@PageableDefaults(sort = "weight=desc")
public String select(
        Searchable searchable, Model model,
        @PathVariable(value = "selectType") String selectType,
        @MatrixVariable(value = "domId", pathVar = "selectType") String domId,
        @MatrixVariable(value = "domName", pathVar = "selectType", required = false) String domName) {

    this.permissionList.assertHasViewPermission();

    model.addAttribute("selectType", selectType);
    model.addAttribute("domId", domId);
    model.addAttribute("domName", domName);

    super.list(searchable, model);
    return "showcase/product/category/select";
}
 
Example #2
Source Project: spring-analysis-note   Author: Vip-Augus   File: MatrixVariableMapMethodArgumentResolver.java    License: MIT License 5 votes vote down vote up
@Nullable
@Override
public Object resolveArgumentValue(MethodParameter parameter, BindingContext bindingContext,
		ServerWebExchange exchange) {

	Map<String, MultiValueMap<String, String>> matrixVariables =
			exchange.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE);

	if (CollectionUtils.isEmpty(matrixVariables)) {
		return Collections.emptyMap();
	}

	MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
	MatrixVariable annotation = parameter.getParameterAnnotation(MatrixVariable.class);
	Assert.state(annotation != null, "No MatrixVariable annotation");
	String pathVariable = annotation.pathVar();

	if (!pathVariable.equals(ValueConstants.DEFAULT_NONE)) {
		MultiValueMap<String, String> mapForPathVariable = matrixVariables.get(pathVariable);
		if (mapForPathVariable == null) {
			return Collections.emptyMap();
		}
		map.putAll(mapForPathVariable);
	}
	else {
		for (MultiValueMap<String, String> vars : matrixVariables.values()) {
			vars.forEach((name, values) -> {
				for (String value : values) {
					map.add(name, value);
				}
			});
		}
	}

	return (isSingleValueMap(parameter) ? map.toSingleValueMap() : map);
}
 
Example #3
Source Project: spring-analysis-note   Author: Vip-Augus   File: ControllerInputIntegrationTests.java    License: MIT License 5 votes vote down vote up
@GetMapping("/{one}/{two}/{three}-{four}")
public String matrixVar(
		@MatrixVariable int p,
		@MatrixVariable(name = "q", pathVar = "two") int q2,
		@MatrixVariable(name = "q", pathVar = "four") int q4) {

	return "p=" + p + ", q2=" + q2 + ", q4=" + q4;
}
 
Example #4
Source Project: spring-analysis-note   Author: Vip-Augus   File: MatrixVariablesMapMethodArgumentResolverTests.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unused")
void handle(
		String stringArg,
		@MatrixVariable Map<String, String> map,
		@MatrixVariable MultiValueMap<String, String> multivalueMap,
		@MatrixVariable(pathVar="cars") MultiValueMap<String, String> mapForPathVar,
		@MatrixVariable("name") Map<String, String> mapWithName) {
}
 
Example #5
Source Project: spring-analysis-note   Author: Vip-Augus   File: MatrixVariableMapMethodArgumentResolver.java    License: MIT License 5 votes vote down vote up
@Override
@Nullable
public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer,
		NativeWebRequest request, @Nullable WebDataBinderFactory binderFactory) throws Exception {

	@SuppressWarnings("unchecked")
	Map<String, MultiValueMap<String, String>> matrixVariables =
			(Map<String, MultiValueMap<String, String>>) request.getAttribute(
					HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);

	if (CollectionUtils.isEmpty(matrixVariables)) {
		return Collections.emptyMap();
	}

	MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
	MatrixVariable ann = parameter.getParameterAnnotation(MatrixVariable.class);
	Assert.state(ann != null, "No MatrixVariable annotation");
	String pathVariable = ann.pathVar();

	if (!pathVariable.equals(ValueConstants.DEFAULT_NONE)) {
		MultiValueMap<String, String> mapForPathVariable = matrixVariables.get(pathVariable);
		if (mapForPathVariable == null) {
			return Collections.emptyMap();
		}
		map.putAll(mapForPathVariable);
	}
	else {
		for (MultiValueMap<String, String> vars : matrixVariables.values()) {
			vars.forEach((name, values) -> {
				for (String value : values) {
					map.add(name, value);
				}
			});
		}
	}

	return (isSingleValueMap(parameter) ? map.toSingleValueMap() : map);
}
 
Example #6
Source Project: spring-analysis-note   Author: Vip-Augus   File: MatrixVariableMethodArgumentResolver.java    License: MIT License 5 votes vote down vote up
@Override
public boolean supportsParameter(MethodParameter parameter) {
	if (!parameter.hasParameterAnnotation(MatrixVariable.class)) {
		return false;
	}
	if (Map.class.isAssignableFrom(parameter.nestedIfOptional().getNestedParameterType())) {
		MatrixVariable matrixVariable = parameter.getParameterAnnotation(MatrixVariable.class);
		return (matrixVariable != null && StringUtils.hasText(matrixVariable.name()));
	}
	return true;
}
 
Example #7
@RequestMapping("/{root}")
public void handle(@PathVariable("root") int root, @MatrixVariable(required=false, defaultValue="7") int q,
		Writer writer) throws IOException {

	assertEquals("Invalid path variable value", 42, root);
	writer.write("test-" + root + "-" + q);
}
 
Example #8
@RequestMapping("/hotels/{hotel}/bookings/{booking}-{other}")
public void handle(@PathVariable("hotel") String hotel,
		@PathVariable int booking,
		@PathVariable String other,
		@MatrixVariable(name = "q", pathVar = "hotel") int qHotel,
		@MatrixVariable(name = "q", pathVar = "other") int qOther,
		Writer writer) throws IOException {
	assertEquals("Invalid path variable value", "42", hotel);
	assertEquals("Invalid path variable value", 21, booking);
	writer.write("test-" + hotel + "-q" + qHotel + "-" + booking + "-" + other + "-q" + qOther);
}
 
Example #9
@RequestMapping("/hotels/{hotel}/bookings/{booking}-{other}")
public void handle(@PathVariable("hotel") String hotel, @PathVariable int booking,
		@PathVariable String other, @MatrixVariable MultiValueMap<String, String> params) {

	assertEquals("Invalid path variable value", "42", hotel);
	assertEquals("Invalid path variable value", 21, booking);
	assertEquals(Arrays.asList("1", "2", "3"), params.get("q"));
	assertEquals("R", params.getFirst("r"));
}
 
Example #10
@RequestMapping("/{root:\\d+}{params}")
public void handle(@PathVariable("root") int root, @PathVariable("params") String paramString,
		@MatrixVariable List<Integer> q, Writer writer) throws IOException {

	assertEquals("Invalid path variable value", 42, root);
	writer.write("test-" + root + "-" + paramString + "-" + q);
}
 
Example #11
Source Project: spring-analysis-note   Author: Vip-Augus   File: MatrixVariablesMapMethodArgumentResolverTests.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unused")
public void handle(
		String stringArg,
		@MatrixVariable Map<String, String> map,
		@MatrixVariable MultiValueMap<String, String> multivalueMap,
		@MatrixVariable(pathVar="cars") MultiValueMap<String, String> mapForPathVar,
		@MatrixVariable("name") Map<String, String> mapWithName) {
}
 
Example #12
Source Project: spring-analysis-note   Author: Vip-Augus   File: MvcAnnotationPredicates.java    License: MIT License 5 votes vote down vote up
@Override
public boolean test(MethodParameter parameter) {
	MatrixVariable annotation = parameter.getParameterAnnotation(MatrixVariable.class);
	return annotation != null &&
			(this.name == null || this.name.equalsIgnoreCase(annotation.name())) &&
			(this.pathVar == null || this.pathVar.equalsIgnoreCase(annotation.pathVar()));
}
 
Example #13
Source Project: java-technology-stack   Author: codeEngraver   File: MatrixVariableMapMethodArgumentResolver.java    License: MIT License 5 votes vote down vote up
@Nullable
@Override
public Object resolveArgumentValue(MethodParameter parameter, BindingContext bindingContext,
		ServerWebExchange exchange) {

	Map<String, MultiValueMap<String, String>> matrixVariables =
			exchange.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE);

	if (CollectionUtils.isEmpty(matrixVariables)) {
		return Collections.emptyMap();
	}

	MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
	MatrixVariable annotation = parameter.getParameterAnnotation(MatrixVariable.class);
	Assert.state(annotation != null, "No MatrixVariable annotation");
	String pathVariable = annotation.pathVar();

	if (!pathVariable.equals(ValueConstants.DEFAULT_NONE)) {
		MultiValueMap<String, String> mapForPathVariable = matrixVariables.get(pathVariable);
		if (mapForPathVariable == null) {
			return Collections.emptyMap();
		}
		map.putAll(mapForPathVariable);
	}
	else {
		for (MultiValueMap<String, String> vars : matrixVariables.values()) {
			vars.forEach((name, values) -> {
				for (String value : values) {
					map.add(name, value);
				}
			});
		}
	}

	return (isSingleValueMap(parameter) ? map.toSingleValueMap() : map);
}
 
Example #14
Source Project: java-technology-stack   Author: codeEngraver   File: ControllerInputIntegrationTests.java    License: MIT License 5 votes vote down vote up
@GetMapping("/{one}/{two}/{three}-{four}")
public String matrixVar(
		@MatrixVariable int p,
		@MatrixVariable(name = "q", pathVar = "two") int q2,
		@MatrixVariable(name = "q", pathVar = "four") int q4) {

	return "p=" + p + ", q2=" + q2 + ", q4=" + q4;
}
 
Example #15
Source Project: java-technology-stack   Author: codeEngraver   File: MatrixVariablesMapMethodArgumentResolverTests.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unused")
void handle(
		String stringArg,
		@MatrixVariable Map<String, String> map,
		@MatrixVariable MultiValueMap<String, String> multivalueMap,
		@MatrixVariable(pathVar="cars") MultiValueMap<String, String> mapForPathVar,
		@MatrixVariable("name") Map<String, String> mapWithName) {
}
 
Example #16
Source Project: java-technology-stack   Author: codeEngraver   File: MatrixVariableMapMethodArgumentResolver.java    License: MIT License 5 votes vote down vote up
@Override
@Nullable
public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer,
		NativeWebRequest request, @Nullable WebDataBinderFactory binderFactory) throws Exception {

	@SuppressWarnings("unchecked")
	Map<String, MultiValueMap<String, String>> matrixVariables =
			(Map<String, MultiValueMap<String, String>>) request.getAttribute(
					HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);

	if (CollectionUtils.isEmpty(matrixVariables)) {
		return Collections.emptyMap();
	}

	MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
	MatrixVariable ann = parameter.getParameterAnnotation(MatrixVariable.class);
	Assert.state(ann != null, "No MatrixVariable annotation");
	String pathVariable = ann.pathVar();

	if (!pathVariable.equals(ValueConstants.DEFAULT_NONE)) {
		MultiValueMap<String, String> mapForPathVariable = matrixVariables.get(pathVariable);
		if (mapForPathVariable == null) {
			return Collections.emptyMap();
		}
		map.putAll(mapForPathVariable);
	}
	else {
		for (MultiValueMap<String, String> vars : matrixVariables.values()) {
			vars.forEach((name, values) -> {
				for (String value : values) {
					map.add(name, value);
				}
			});
		}
	}

	return (isSingleValueMap(parameter) ? map.toSingleValueMap() : map);
}
 
Example #17
Source Project: java-technology-stack   Author: codeEngraver   File: MatrixVariableMethodArgumentResolver.java    License: MIT License 5 votes vote down vote up
@Override
public boolean supportsParameter(MethodParameter parameter) {
	if (!parameter.hasParameterAnnotation(MatrixVariable.class)) {
		return false;
	}
	if (Map.class.isAssignableFrom(parameter.nestedIfOptional().getNestedParameterType())) {
		MatrixVariable matrixVariable = parameter.getParameterAnnotation(MatrixVariable.class);
		return (matrixVariable != null && StringUtils.hasText(matrixVariable.name()));
	}
	return true;
}
 
Example #18
@RequestMapping("/{root}")
public void handle(@PathVariable("root") int root, @MatrixVariable(required=false, defaultValue="7") int q,
		Writer writer) throws IOException {

	assertEquals("Invalid path variable value", 42, root);
	writer.write("test-" + root + "-" + q);
}
 
Example #19
@RequestMapping("/hotels/{hotel}/bookings/{booking}-{other}")
public void handle(@PathVariable("hotel") String hotel,
		@PathVariable int booking,
		@PathVariable String other,
		@MatrixVariable(name = "q", pathVar = "hotel") int qHotel,
		@MatrixVariable(name = "q", pathVar = "other") int qOther,
		Writer writer) throws IOException {
	assertEquals("Invalid path variable value", "42", hotel);
	assertEquals("Invalid path variable value", 21, booking);
	writer.write("test-" + hotel + "-q" + qHotel + "-" + booking + "-" + other + "-q" + qOther);
}
 
Example #20
@RequestMapping("/hotels/{hotel}/bookings/{booking}-{other}")
public void handle(@PathVariable("hotel") String hotel, @PathVariable int booking,
		@PathVariable String other, @MatrixVariable MultiValueMap<String, String> params) {

	assertEquals("Invalid path variable value", "42", hotel);
	assertEquals("Invalid path variable value", 21, booking);
	assertEquals(Arrays.asList("1", "2", "3"), params.get("q"));
	assertEquals("R", params.getFirst("r"));
}
 
Example #21
@RequestMapping("/{root:\\d+}{params}")
public void handle(@PathVariable("root") int root, @PathVariable("params") String paramString,
		@MatrixVariable List<Integer> q, Writer writer) throws IOException {

	assertEquals("Invalid path variable value", 42, root);
	writer.write("test-" + root + "-" + paramString + "-" + q);
}
 
Example #22
Source Project: java-technology-stack   Author: codeEngraver   File: MatrixVariablesMapMethodArgumentResolverTests.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unused")
public void handle(
		String stringArg,
		@MatrixVariable Map<String, String> map,
		@MatrixVariable MultiValueMap<String, String> multivalueMap,
		@MatrixVariable(pathVar="cars") MultiValueMap<String, String> mapForPathVar,
		@MatrixVariable("name") Map<String, String> mapWithName) {
}
 
Example #23
Source Project: java-technology-stack   Author: codeEngraver   File: MvcAnnotationPredicates.java    License: MIT License 5 votes vote down vote up
@Override
public boolean test(MethodParameter parameter) {
	MatrixVariable annotation = parameter.getParameterAnnotation(MatrixVariable.class);
	return annotation != null &&
			(this.name == null || this.name.equalsIgnoreCase(annotation.name())) &&
			(this.pathVar == null || this.pathVar.equalsIgnoreCase(annotation.pathVar()));
}
 
Example #24
Source Project: lams   Author: lamsfoundation   File: MatrixVariableMapMethodArgumentResolver.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean supportsParameter(MethodParameter parameter) {
	MatrixVariable matrixVariable = parameter.getParameterAnnotation(MatrixVariable.class);
	if (matrixVariable != null) {
		if (Map.class.isAssignableFrom(parameter.getParameterType())) {
			return !StringUtils.hasText(matrixVariable.name());
		}
	}
	return false;
}
 
Example #25
Source Project: lams   Author: lamsfoundation   File: MatrixVariableMapMethodArgumentResolver.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
		NativeWebRequest request, WebDataBinderFactory binderFactory) throws Exception {

	@SuppressWarnings("unchecked")
	Map<String, MultiValueMap<String, String>> matrixVariables =
			(Map<String, MultiValueMap<String, String>>) request.getAttribute(
					HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);

	if (CollectionUtils.isEmpty(matrixVariables)) {
		return Collections.emptyMap();
	}

	MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
	String pathVariable = parameter.getParameterAnnotation(MatrixVariable.class).pathVar();

	if (!pathVariable.equals(ValueConstants.DEFAULT_NONE)) {
		MultiValueMap<String, String> mapForPathVariable = matrixVariables.get(pathVariable);
		if (mapForPathVariable == null) {
			return Collections.emptyMap();
		}
		map.putAll(mapForPathVariable);
	}
	else {
		for (MultiValueMap<String, String> vars : matrixVariables.values()) {
			for (String name : vars.keySet()) {
				for (String value : vars.get(name)) {
					map.add(name, value);
				}
			}
		}
	}

	return (isSingleValueMap(parameter) ? map.toSingleValueMap() : map);
}
 
Example #26
Source Project: lams   Author: lamsfoundation   File: MatrixVariableMethodArgumentResolver.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean supportsParameter(MethodParameter parameter) {
	if (!parameter.hasParameterAnnotation(MatrixVariable.class)) {
		return false;
	}
	if (Map.class.isAssignableFrom(parameter.nestedIfOptional().getNestedParameterType())) {
		String variableName = parameter.getParameterAnnotation(MatrixVariable.class).name();
		return StringUtils.hasText(variableName);
	}
	return true;
}
 
Example #27
Source Project: spring4-understanding   Author: langtianya   File: MatrixVariableMapMethodArgumentResolver.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean supportsParameter(MethodParameter parameter) {
	MatrixVariable matrixVariable = parameter.getParameterAnnotation(MatrixVariable.class);
	if (matrixVariable != null) {
		if (Map.class.isAssignableFrom(parameter.getParameterType())) {
			return !StringUtils.hasText(matrixVariable.name());
		}
	}
	return false;
}
 
Example #28
Source Project: spring4-understanding   Author: langtianya   File: MatrixVariableMethodArgumentResolver.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean supportsParameter(MethodParameter parameter) {
	if (!parameter.hasParameterAnnotation(MatrixVariable.class)) {
		return false;
	}
	if (Map.class.isAssignableFrom(parameter.getParameterType())) {
		String variableName = parameter.getParameterAnnotation(MatrixVariable.class).name();
		return StringUtils.hasText(variableName);
	}
	return true;
}
 
Example #29
@RequestMapping("/{root}")
public void handle(@PathVariable("root") int root, @MatrixVariable(required=false, defaultValue="7") int q,
		Writer writer) throws IOException {

	assertEquals("Invalid path variable value", 42, root);
	writer.write("test-" + root + "-" + q);
}
 
Example #30
@RequestMapping("/hotels/{hotel}/bookings/{booking}-{other}")
public void handle(@PathVariable("hotel") String hotel,
		@PathVariable int booking,
		@PathVariable String other,
		@MatrixVariable(name = "q", pathVar = "hotel") int qHotel,
		@MatrixVariable(name = "q", pathVar = "other") int qOther,
		Writer writer) throws IOException {
	assertEquals("Invalid path variable value", "42", hotel);
	assertEquals("Invalid path variable value", 21, booking);
	writer.write("test-" + hotel + "-q" + qHotel + "-" + booking + "-" + other + "-q" + qOther);
}