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

The following examples show how to use org.springframework.web.bind.annotation.MatrixVariable. These examples are extracted from open source projects. 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   Source 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
@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
@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
@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
@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
@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
@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   Source 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
@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
@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
@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
@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
@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
@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   Source 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
@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
@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
@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
@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
@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);
}