Spring @MatrixVariable in a map

This tutorial will show you how we use @MatrixVariable annotation in Spring Web MVC. This tutorial will show you how to obtain matrix variable in a map from the URL segment. The URI has the possibility of including name-value pairs within path segments. The general “URI path parameters” could be applied although the more unique “Matrix URIs”, originating from an old post by Tim Berners-Lee, is also frequently used and fairly well known. Within Spring MVC these are referred to as matrix variables.

Matrix variables can appear in any path segment, each matrix variable separated with a “;” (semicolon). For example: “/cars;color=red;year=2012”. Multiple values may be either “,” (comma) separated “color=red,green,blue” or the variable name may be repeated “color=red;color=green;color=blue”.

If a URL is expected to contain matrix variables, the request mapping pattern must represent them with a URI template. This ensures the request can be matched correctly regardless of whether matrix variables are present or not and in what order they are provided. Continue reading “Spring @MatrixVariable in a map”

Spring optional @MatrixVariable with default value

This tutorial will show you how we use @MatrixVariable annotation in Spring Web MVC. This tutorial will show you how to set default value to matrix variable to make it optional in the URL segment. The URI has the possibility of including name-value pairs within path segments. The general “URI path parameters” could be applied although the more unique “Matrix URIs”, originating from an old post by Tim Berners-Lee, is also frequently used and fairly well known. Within Spring MVC these are referred to as matrix variables.

Matrix variables can appear in any path segment, each matrix variable separated with a “;” (semicolon). For example: “/cars;color=red;year=2012”. Multiple values may be either “,” (comma) separated “color=red,green,blue” or the variable name may be repeated “color=red;color=green;color=blue”.

If a URL is expected to contain matrix variables, the request mapping pattern must represent them with a URI template. This ensures the request can be matched correctly regardless of whether matrix variables are present or not and in what order they are provided.

A matrix variable may be defined as optional and a default value specified:

// GET /pets/42

@RequestMapping(value = "/pets/{petId}", method = RequestMethod.GET)
public void findPet(@MatrixVariable(required=true, defaultValue="1") int q) {
    // q == 1
}

 

Continue reading “Spring optional @MatrixVariable with default value”

Spring @MatrixVariable at specific position in a URL

This tutorial will show you how we use @MatrixVariable annotation in Spring Web MVC. The URI has the possibility of including name-value pairs within path segments. The general “URI path parameters” could be applied although the more unique “Matrix URIs”, originating from an old post by Tim Berners-Lee, is also frequently used and fairly well known. Within Spring MVC these are referred to as matrix variables.

Matrix variables can appear in any path segment, each matrix variable separated with a “;” (semicolon). For example: “/cars;color=red;year=2012”. Multiple values may be either “,” (comma) separated “color=red,green,blue” or the variable name may be repeated “color=red;color=green;color=blue”.

If a URL is expected to contain matrix variables, the request mapping pattern must represent them with a URI template. This ensures the request can be matched correctly regardless of whether matrix variables are present or not and in what order they are provided. Continue reading “Spring @MatrixVariable at specific position in a URL”

Spring @MatrixVariable

This tutorial will show you how we use @MatrixVariable annotation in Spring Web MVC. The URI has the possibility of including name-value pairs within path segments. The general “URI path parameters” could be applied although the more unique “Matrix URIs”, originating from an old post by Tim Berners-Lee, is also frequently used and fairly well known. Within Spring MVC these are referred to as matrix variables.

Matrix variables can appear in any path segment, each matrix variable separated with a “;” (semicolon). For example: “/cars;color=red;year=2012”. Multiple values may be either “,” (comma) separated “color=red,green,blue” or the variable name may be repeated “color=red;color=green;color=blue”.

If a URL is expected to contain matrix variables, the request mapping pattern must represent them with a URI template. This ensures the request can be matched correctly regardless of whether matrix variables are present or not and in what order they are provided. Continue reading “Spring @MatrixVariable”

Spring Web MVC @PathVariable with Regular Expressions

This tutorial will show you how we use @PathVariable annotation with Regular Expressions in Spring Web MVC. Sometimes we need more precision in defining URI template variables. The @RequestMapping annotation supports the use of regular expressions in URI template variables. The syntax is {varName:regex} where the first part defines the variable name and the second – the regular expression.

For example:

@RequestMapping("/spring-web/{fileName:[a-z-]+}-{version:\d\.\d\.\d}{extension:\.[a-z]+}")
    public void handle(@PathVariable String fileName, @PathVariable String version, @PathVariable String extension) {
        // ...
    }
}

For this tutorial we will create maven based web project in Eclipse.

If you already have an idea on how to create a maven project in Eclipse will be great otherwise I will tell you here how to create a maven project in Eclipse. Continue reading “Spring Web MVC @PathVariable with Regular Expressions”

Spring Web MVC @PathVariable

This tutorial will show you how we use @PathVariable annotation in Spring MVC. The @PathVariable annotation is used on a method argument to bind it to the value of a URI template variable.

For this tutorial we will create maven based web project in Eclipse.

If you already have an idea on how to create a maven project in Eclipse will be great otherwise I will tell you here how to create a maven project in Eclipse. Continue reading “Spring Web MVC @PathVariable”

Spring Web MVC

This tutorial will show you how we configure Spring MVC, maven and Tomcat 7. For this tutorial we will create maven based web project in Eclipse.

If you already have an idea on how to create a maven project in Eclipse will be great otherwise I will tell you here how to create a maven project in Eclipse. Continue reading “Spring Web MVC”

Deploy Web Application in Jetty Container in Embedded Mode

What is this tutorial all about ?

This tutorial is all about to deploy an web application in embedded Jetty web container. You do not need to deploy it manually into the web server.

Why do we need to deploy it in embedded mode ?

We sometimes need to deploy it in embedded mode, because during unit testing or integration testing we have to deploy the web application manually every time before we start the testing; so we want to deploy the application into embedded mode so that it starts up automatically and we perform unit testing or integration testing without taking care of deployment. Continue reading “Deploy Web Application in Jetty Container in Embedded Mode”