问题描述
我可以很容易地得到请求参数:
(:foo params)
但是,当我有这样的请求时:
code> / api?foo = 1& foo = 2& foo = 3
回到
3
,而我希望数组[1,2,3]
。
我不知道为什么会发生这种情况,因为当我看下面的代码:
a href =https://github.com/ring-clojure/ring-codec/blob/master/src/ring/util/codec.clj#L128> https://github.com/ring-clojure/ring -codec / blob / master / src / ring / util / codec.clj#L128
似乎是调用
assoc-conj
它应该把同名的多个params变成一个包含值的向量。
我缺少这里的东西, ?
解决方案使用标准的Clojure解构形式:
(GET/ api{{:strs [foo]}:query-params}(str foo))
curlhttp:// localhost:3000 / api ?foo = 1& foo = 2& foo = 3
==> [123]
doc:
I can get to the request parameters easily with:
(:foo params)
However, when I have a request like this:
/api?foo=1&foo=2&foo=3
I only get back
"3"
while I would expect an array["1","2","3"]
.I'm not sure why this is happening because when I look at the code in:
https://github.com/ring-clojure/ring-codec/blob/master/src/ring/util/codec.clj#L128
It seems to call
assoc-conj
which is supposed to turn multiple params of the same name into a vector containing the values.Am I missing something here or is this a bug?
解决方案use a standard Clojure destructuring form:
(GET "/api" {{:strs [foo]} :query-params} (str foo)) curl "http://localhost:3000/api?foo=1&foo=2&foo=3" ==> ["1" "2" "3"]
doc: https://github.com/weavejester/compojure/wiki/Destructuring-Syntax
这篇关于如何在Compojure中获取重复的请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!