springmvc 3.2 @MatrixVariable注解

 

示例

1、url 格式 /path;name=value;name=value,如

/showcase/product/category/select/single;domId=categoryId;domName=categoryName

2、控制器处理方法

 @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,

扫描二维码关注公众号,回复: 627455 查看本文章

            @MatrixVariable(value = "domName", pathVar = "selectType", required = false) String domName) {

        model.addAttribute("selectType", selectType);

 

通过@MatrixVariable可以获取到相关的参数值。

 

这个一般在传递path相关的参数时比较有用; 比如此处我是做数据参照(如树,可能在不同的模块参照,具有相同的参照值,但具有不同的名字),利用MatrixVariable 可以动态传递参照的元素id。

 

 

具体示例可参考

https://github.com/zhangkaitao/es 中的com.sishuok.es.web.showcase.product.web.controller.CategoryController

猜你喜欢

转载自jinnianshilongnian.iteye.com/blog/1830409
3.2
今日推荐