如何正确处理具有两次相同参数且值相同的 URL?
使用 Grails 1.3.3,当请求 url 链接时:
/myapp/mycontroller/myaction?p1=v1&p2=v2&p1=v1
那么 params 注入 Grails 控制器的值将包含:
assert params.p1== ['v1','v1']
对我来说, params.p1
等于 'v1'
,不?
无论如何,有什么办法可以改变这种行为吗?
谢谢。
Using Grails 1.3.3, when requesting url link:
/myapp/mycontroller/myaction?p1=v1&p2=v2&p1=v1
then params injected value into Grails controller will contain :
assert params.p1== ['v1','v1']
It would have been logical to me that params.p1
equals to 'v1'
, no?
In any case, is there any way to change this behavior?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我同意@Andrew,但你必须
p1.unique()[0] == 'v1'
i agree with @Andrew, but of you must
p1.unique()[0] == 'v1'
这是您的应用程序中参数两次的错误吗?大多数人会认为这应该意味着它有多个值,因此它不会被视为奇怪的行为。如果您不喜欢默认行为,您可以随时获取查询字符串并自行解析。
Is this a bug in your app that the parameter is twice? Most people would think that should mean it has multiple values, hence it wouldn't be considered strange behavior. You can always grab the query string and parse it yourself if you don't like the default behavior.
我假设您不希望它拾取重复项,因为您不想在每个控制器操作中编写代码来处理这种特殊情况。我唯一能告诉你的是首先不允许重复,或者使用 过滤器拦截请求< /a> 并替换重复的参数值。
I'm assuming you don't want it to pick up the duplicates because you don't want to have to write code in every controller action to handle that special case. The only thing I can tell you is to not allow the duplicates in the first place, or intercept the request using a filter and substitute the duplicate param values.