揭秘 Compojure - Part2
第一部分我介绍了即将做为例子的地址簿(Address Book)应用程序。
在这一部分中我们将使用Compojure建立这个程序的主要骨架。
1) 安装 Leiningen
http://github.com/technomancy/leiningen/blob/master/README.md
2) 使用Leiningen创建项目
a) 编辑 project.clj
(defproject address_book "1.0.0-SNAPSHOT" :description "Address Book" :dependencies [[org.clojure/clojure "1.1.0"] [org.clojure/clojure-contrib "1.1.0"] [compojure "0.4.1"] [ring/ring-jetty-adapter "0.2.3"]])
b) 安装依赖,也就是项目需要的库
lein deps将会安装
compojure 和complojure的所以依赖。
c) 测试安装是否正常
编辑 src/address_book/core.clj
(ns address_book.core (:use [compojure.core] [ring.adapter.jetty]) (:require [compojure.route :as route])) (defroutes example (GET "/" [] "My Address Book!") (route/not-found "Page not found")) (run-jetty example {:port 8080})
运行服务器:
lein repl src/address_book/core.clj
打开浏览器输入地址 http://localhost:8080 将会看到 “My Address Book!”。
下一部分我们将开始实现需要的功能。
原文链接:http://techbehindtech.com/2010/08/15/compojure-demystified-with-an-example-part-2/