1

下面详述的路线设置会导致错误:Wrong number of args (0) passed to: PersistentArrayMap谁能帮我理解这个错误以及如何解决它?

(defn sign-in [req]
  ({:status 200 :body "hello world" :headers {"content-type" "text/plain"}})) 

(defroutes paths
  (GET "/connect" {} connect-socket)
  (POST "/sign-in" {} sign-in)
  (route/resources "/")
  (route/not-found "Resource not found."))

(def app
  (-> (defaults/wrap-defaults #'paths defaults/api-defaults)
      wrap-json-params))
4

1 回答 1

7

通过展开响应映射来修复您的登录功能

(defn sign-in [req]
  {:status 200 :body "hello world" :headers {"content-type" "text/plain"}}) 

问题是,您将地图放在函数位置(列表的第一个元素)并且它需要一个参数。

(
  {:status 200 :body "hello world" :headers {"content-type" "text/plain"}} ;; function
  ???      ;; argument
 )

在 clojure 中,map 可以作为一个以键为参数的函数并返回该键的值,例如

({:a 1 :b 2 :c 3} :a)
=> 1
于 2015-04-16T17:13:38.587 回答