![]() |
In this article, we will learn about Spring MVC Matrix Variables. Matrix Variable is used to parse and bind name-value pairs inside a path segment to method parameters. A semicolon separates many pairs. Matrix variables must first be enabled. XML Matrix VariableBelow are the necessary dependencies and maven plugins added to the pom.xml file. XML
Matrix Variables in Spring MVCThese variables can exist anywhere along the route. Each matrix variable is delimited by a semicolon (‘;’) and values are provided using the character equals (“=”). We may either repeat the name of the variable or use the comma (‘,’) to distinguish various values on the same route. http://localhost:8080/spring-mvc-java-2/authorArea/workingArea=rh,informatics,admin
Using annotation @MatrixVariableThe @MatrixVariable annotation should be used in Spring MVC when referring to these variables. public class Author { Handle Matrix Variable PropertiesFor the variable, we may set required or default properties. The contact number is necessary in the example below. The following procedure will be used to handle the request. Java
Complement Path VariablesWe can look for an employee by name, but we can also get the contact number starting with that person’s name.The following should be the request for this search:Following is how the request will be handled. Java
Binding Matrix VariablesWe can connect variables to a map if, for whatever reason, we wish to get every variable that is accessible on the path. Java
We should use the following as an input parameter as we only want to retrieve all the variables that are a part of authorData: Java
Partial BindingMatrix variables have the benefit of versatility in addition to simplicity, since they may be applied in several contexts. Using the following as an input parameter is appropriate if all we want to know is the name of the companyData segment’s matrix variable: @MatrixVariable(value="name", pathVar="organization") String name
|
Reffered: https://www.geeksforgeeks.org
Advance Java |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |