Matrix Variables

本文深入探讨了Spring MVC中矩阵变量的使用方法,包括如何在路径段中包含名称值对,如何通过URL模板匹配请求,以及如何在映射中定义矩阵变量的可选性和默认值。
The URI specification RFC 3986 definesthe possibility of including name-value pairs within path segments. There is no specificterm used in the spec. The general "URI path parameters" could be applied although themore unique "Matrix URIs", originatingfrom 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 beeither "," (comma) separated "color=red,green,blue" or the variable name may berepeated "color=red;color=green;color=blue".

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

Below is an example of extracting the matrix variable "q":

// GET /pets/42;q=11;r=22

@RequestMapping(value = "/pets/{petId}", method = RequestMethod.GET)
public void findPet(@PathVariable String petId, @MatrixVariable int q) {

    // petId == 42
    // q == 11

}

Since all path segments may contain matrix variables, in some cases you need to be morespecific to identify where the variable is expected to be:

// GET /owners/42;q=11/pets/21;q=22

@RequestMapping(value = "/owners/{ownerId}/pets/{petId}", method = RequestMethod.GET)
public void findPet(
        @MatrixVariable(value="q", pathVar="ownerId") int q1,
        @MatrixVariable(value="q", pathVar="petId") int q2) {

    // q1 == 11
    // q2 == 22

}

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=false, defaultValue="1") int q) {

    // q == 1

}

All matrix variables may be obtained in a Map:

// GET /owners/42;q=11;r=12/pets/21;q=22;s=23

@RequestMapping(value = "/owners/{ownerId}/pets/{petId}", method = RequestMethod.GET)
public void findPet(
        @MatrixVariable Map<String, String> matrixVars,
        @MatrixVariable(pathVar="petId"") Map<String, String> petMatrixVars) {

    // matrixVars: ["q" : [11,22], "r" : 12, "s" : 23]
    // petMatrixVars: ["q" : 11, "s" : 23]

}

Note that to enable the use of matrix variables, you must set theremoveSemicolonContent property of RequestMappingHandlerMapping to false. Bydefault it is set to true.

[Tip]

The MVC Java config and the MVC namespace both provide options for enabling the use ofmatrix variables.

If you are using Java config, The Advanced Customizationswith MVC Java Config section describes how the RequestMappingHandlerMapping canbe customized.

In the MVC namespace, the <mvc:annotation-driven> element has anenable-matrix-variables attribute that should be set to true. By default it is setto false.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <mvc:annotation-driven enable-matrix-variables="true"/>

</beans>
Model Manager mmgetalltags - Get all assigned tags for a branch mmgetbranch - Get branch variable in Model Manager mmgetcommit - Get commit message from an item mmmodelinfo - Model info for models stored in Model Manager or as files mmsave - Save model in Model Manager mmsearch - Full-text and keyword search in Model Manager User interface functions mphcd - Change directory to the directory of the model mphdoc - Open documentation window mphload - Load a COMSOL model MPH-file mphopen - GUI for opening recent model files mphrun - Run various actions on nodes mphsave - Save a COMSOL model as a file mphversion - Return the version number of COMSOL Multiphysics mphlaunch - Launch COMSOL Multiphysics Client and import a model mphstart - Connect MATLAB to a COMSOL server mphstartcomsolmphserver - Start Comsol Multiphysics server Geometry functions mphgeom - Plot a geometry in a MATLAB figure mphgeominfo - Get geometry information mphimage2geom - Convert image to geometry mphviewselection - Display a geometric entity selection in a MATLAB figure Mesh functions mphmesh - Plot mesh in a MATLAB figure mphmeshstats - Retrieve mesh statistics and and mesh data information mphwritemesh - Write mesh data as an mphtxt, mphbin or STL file Utility functions mphbatchinfo - Get information about the batch solution structures mphevaluate - Evaluate parameter expressions in model mphgetadj - Return adjacency info for geometric entities mphgetcoords - Return point coordinates of geometry entities mphgetu - Return solution vector mphinputmatrix - Add a linear matrix system to a model mphinterpolationfile - Save data in file readable by the Interpolation feature mphmatrix - Get model matrices mphmeasure - Measure entites in a geometry mphquad2tri - Convert plotdata quad mesh into simplex mesh mphreadstl - Read an STL file and returns the data as a struct mphreduction - Return reduced order state space matrices for a model mphselectball - Select geometric entity using a ball selection mphselectbox - Select geometric entity using a rubberband/box mphselectcoords - Select geometric entity using point coordinates mphsolinfo - Get information about a solution object mphsolutioninfo - Get information about solution objects and data sets containing given parameters mphstate - Get state-space matrices for dynamic system mphwritestl - Export plot data as an STL file mphxmeshinfo - Extract information about the extended mesh Postprocessing functions mphaddplotdata - Add plot data to plotgroup mphcolortable - Return colortable data mphdataset - Plots a dataset mphdatasetinfo - Gets information about datasets mpheval - Evaluate expressions on node points mphevalglobalmatrix - Evaluate matrix variables mphevalpoint - Evaluate expressions at geometry vertices mphevalpointmatrix - Evaluate matrix quantities at points in the geometry mphglobal - Evaluate global quantities mphint2 - Perform integration of expressions mphinterp - Evaluate expressions in arbitrary points or data sets mphmax - Perform maximum of expressions mphmean - Perform mean of expressions mphmin - Perform minimum of expressions mphparticle - Evaluate expressions on particle trajectories mphplot - Render a plot group in a figure window mphray - Evaluate expressions on ray trajectories mphreport - Add report to model or run report generator mphsurf - Create plot data from surf data mphtable - Get table data Model information and navigation mphapplicationlibraries - GUI for viewing the Model Library mphgetexpressions - Get the model variables and parameters mphgetproperties - Get properties from a model node mphgetselection - Get information about a selection node mphgetview - Information about a view mphcomponentinfo - Gets information about components mphmodel - Return tags for the nodes and subnodes in the COMSOL model object mphnavigator - GUI for viewing the COMSOL model object mphsearch - GUI for searching expressions in the COMSOL model object mphsetparam - Set parameter values and descriptions mphshowerrors - Show messages in error and warning nodes in the COMSOL model object mphtags - Return tags and names for model nodes mphthumbnail - Get and set model thumbnail images COMSOL Multiphysics - LiveLink for Matlab Version 6.3 1-Oct-2024 Copyright 2010-2024 COMSOL Model Manager mmgetalltags - Get all assigned tags for a branch mmgetbranch - Get branch variable in Model Manager mmgetcommit - Get commit message from an item mmmodelinfo - Model info for models stored in Model Manager or as files mmsave - Save model in Model Manager mmsearch - Full-text and keyword search in Model Manager User interface functions mphcd - Change directory to the directory of the model mphdoc - Open documentation window mphload - Load a COMSOL model MPH-file mphopen - GUI for opening recent model files mphrun - Run various actions on nodes mphsave - Save a COMSOL model as a file mphversion - Return the version number of COMSOL Multiphysics mphlaunch - Launch COMSOL Multiphysics Client and import a model mphstart - Connect MATLAB to a COMSOL server mphstartcomsolmphserver - Start Comsol Multiphysics server Geometry functions mphgeom - Plot a geometry in a MATLAB figure mphgeominfo - Get geometry information mphimage2geom - Convert image to geometry mphviewselection - Display a geometric entity selection in a MATLAB figure Mesh functions mphmesh - Plot mesh in a MATLAB figure mphmeshstats - Retrieve mesh statistics and and mesh data information mphwritemesh - Write mesh data as an mphtxt, mphbin or STL file Utility functions mphbatchinfo - Get information about the batch solution structures mphevaluate - Evaluate parameter expressions in model mphgetadj - Return adjacency info for geometric entities mphgetcoords - Return point coordinates of geometry entities mphgetu - Return solution vector mphinputmatrix - Add a linear matrix system to a model mphinterpolationfile - Save data in file readable by the Interpolation feature mphmatrix - Get model matrices mphmeasure - Measure entites in a geometry mphquad2tri - Convert plotdata quad mesh into simplex mesh mphreadstl - Read an STL file and returns the data as a struct mphreduction - Return reduced order state space matrices for a model mphselectball - Select geometric entity using a ball selection mphselectbox - Select geometric entity using a rubberband/box mphselectcoords - Select geometric entity using point coordinates mphsolinfo - Get information about a solution object mphsolutioninfo - Get information about solution objects and data sets containing given parameters mphstate - Get state-space matrices for dynamic system mphwritestl - Export plot data as an STL file mphxmeshinfo - Extract information about the extended mesh Postprocessing functions mphaddplotdata - Add plot data to plotgroup mphcolortable - Return colortable data mphdataset - Plots a dataset mphdatasetinfo - Gets information about datasets mpheval - Evaluate expressions on node points mphevalglobalmatrix - Evaluate matrix variables mphevalpoint - Evaluate expressions at geometry vertices mphevalpointmatrix - Evaluate matrix quantities at points in the geometry mphglobal - Evaluate global quantities mphint2 - Perform integration of expressions mphinterp - Evaluate expressions in arbitrary points or data sets mphmax - Perform maximum of expressions mphmean - Perform mean of expressions mphmin - Perform minimum of expressions mphparticle - Evaluate expressions on particle trajectories mphplot - Render a plot group in a figure window mphray - Evaluate expressions on ray trajectories mphreport - Add report to model or run report generator mphsurf - Create plot data from surf data mphtable - Get table data Model information and navigation mphapplicationlibraries - GUI for viewing the Model Library mphgetexpressions - Get the model variables and parameters mphgetproperties - Get properties from a model node mphgetselection - Get information about a selection node mphgetview - Information about a view mphcomponentinfo - Gets information about components mphmodel - Return tags for the nodes and subnodes in the COMSOL model object mphnavigator - GUI for viewing the COMSOL model object mphsearch - GUI for searching expressions in the COMSOL model object mphsetparam - Set parameter values and descriptions mphshowerrors - Show messages in error and warning nodes in the COMSOL model object mphtags - Return tags and names for model nodes mphthumbnail - Get and set model thumbnail images。以上是COMSOL with matlab接口中的部分代码含义,我需要你学习并记住这段代码
最新发布
11-18
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值