我在以下 Compojure 示例中获取表单参数时遇到问题:
(ns hello-world
(:use compojure.core, ring.adapter.jetty)
(:require [compojure.route :as route]))
(defn view-form []
(str "<html><head></head><body>"
"<form method=\"post\">"
"Title <input type=\"text\" name=\"title\"/>"
"<input type=\"submit\"/>"
"</form></body></html>"))
(defroutes main-routes
(GET "/" [] "Hello World")
(GET "/new" [] (view-form))
(POST "/new" {params :params} (prn "params:" params))
(route/not-found "Not Found"))
(run-jetty main-routes {:port 8088})
提交表单时,输出始终为
params: {}
而且我无法弄清楚为什么 title 参数不在 params 映射中。
我正在使用 Compojure 0.6.2。