Spring 3.0 URL 模式验证 [英] Spring 3.0 URL pattern validation

查看:41
本文介绍了Spring 3.0 URL 模式验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加像 /user/foo 这样的端点,其中 foo 是在运行时确定的一组值之一.我想知道在 Spring 中执行此操作的最佳方法是什么,或者实际上是否应该在 Spring 中完成而不是在控制器级别进行处理.

I'm wanting to to add an endpoint like /user/foo where foo is one of a set of values determined at runtime. I'm wondering what the best way is to do this in Spring, or indeed if it should even been done in Spring an not handled at the controller level.

我目前正在使用 Springs 安全过滤器链,所以我确实考虑在 /user/* 前面放置一个过滤器来进行此验证.这是一个合理的解决方案还是我错过了更理想的解决方案?

I'm currently using Springs security filter chain, so I did think about putting a filter in front of /user/* to do this validation. Is this a reasonable solution or is there a more desirable solution I have missed?

推荐答案

您可以在方法参数上使用 @PathVariable 注解.如果您需要验证变量的结构,@PathVariable 还允许使用正则表达式.

You can use @PathVariable annotation on a method argument. @PathVariable also allows regex if you need to validate the structure of the varible.

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping

http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/bind/annotation/PathVariable.html

对于正则表达式

http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/bind/annotation/RequestMapping.html

这篇关于Spring 3.0 URL 模式验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆