package com.chengjf.sparkdemo.route;

import spark.ModelAndView;
import spark.Request;
import spark.Response;

/**
 * URL的FreeMarker处理类
 * 
 * @author sharp
 * @date 2015-9-3
 *
 */
public abstract class MyFreeMarkerUrlHandler implements MyUrlHandler {

	private String url;

	public MyFreeMarkerUrlHandler(String url) {
		this.url = url;
	}

	protected ModelAndView modelAndView(Object model, String view) {
		ModelAndView mv = new ModelAndView(model, view);
		return mv;
	}

	@Override
	public final void start() {
		spark.Spark.get(new MyFreeMarkerRoute("/") {

			@Override
			public ModelAndView handle(Request req, Response res) {
				return MyFreeMarkerUrlHandler.this.get(req, res);
			}
		});

		spark.Spark.post(new MyFreeMarkerRoute("/") {

			@Override
			public ModelAndView handle(Request req, Response res) {
				return MyFreeMarkerUrlHandler.this.post(req, res);
			}
		});

		spark.Spark.put(new MyFreeMarkerRoute("/") {

			@Override
			public ModelAndView handle(Request req, Response res) {
				return MyFreeMarkerUrlHandler.this.put(req, res);
			}
		});

		spark.Spark.patch(new MyFreeMarkerRoute("/") {

			@Override
			public ModelAndView handle(Request req, Response res) {
				return MyFreeMarkerUrlHandler.this.patch(req, res);
			}
		});

		spark.Spark.delete(new MyFreeMarkerRoute("/") {

			@Override
			public ModelAndView handle(Request req, Response res) {
				return MyFreeMarkerUrlHandler.this.delete(req, res);
			}
		});

		spark.Spark.head(new MyFreeMarkerRoute("/") {

			@Override
			public ModelAndView handle(Request req, Response res) {
				return MyFreeMarkerUrlHandler.this.head(req, res);
			}
		});

		spark.Spark.connect(new MyFreeMarkerRoute("/") {

			@Override
			public ModelAndView handle(Request req, Response res) {
				return MyFreeMarkerUrlHandler.this.connect(req, res);
			}
		});

		spark.Spark.options(new MyFreeMarkerRoute("/") {

			@Override
			public ModelAndView handle(Request req, Response res) {
				return MyFreeMarkerUrlHandler.this.options(req, res);
			}
		});
	}

	public ModelAndView get(Request req, Response res) {
		return null;
	};

	public ModelAndView post(Request req, Response res) {
		return null;
	};

	public ModelAndView put(Request req, Response res) {
		return null;
	};

	public ModelAndView patch(Request req, Response res) {
		return null;
	};

	public ModelAndView delete(Request req, Response res) {
		return null;
	};

	public ModelAndView head(Request req, Response res) {
		return null;
	};

	public ModelAndView trace(Request req, Response res) {
		return null;
	};

	public ModelAndView connect(Request req, Response res) {
		return null;
	};

	public ModelAndView options(Request req, Response res) {
		return null;
	};

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

}

@@ -510,16 +510,19 @@
 art() %7B%0A
+%09%09%0A
 %09%09spark.
@@ -545,35 +545,40 @@
 FreeMarkerRoute(
-%22/%22
+this.url
 ) %7B%0A%0A%09%09%09@Overrid
@@ -737,35 +737,40 @@
 FreeMarkerRoute(
-%22/%22
+this.url
 ) %7B%0A%0A%09%09%09@Overrid
@@ -929,35 +929,40 @@
 FreeMarkerRoute(
-%22/%22
+this.url
 ) %7B%0A%0A%09%09%09@Overrid
@@ -1122,35 +1122,40 @@
 FreeMarkerRoute(
-%22/%22
+this.url
 ) %7B%0A%0A%09%09%09@Overrid
@@ -1318,35 +1318,40 @@
 FreeMarkerRoute(
-%22/%22
+this.url
 ) %7B%0A%0A%09%09%09@Overrid
@@ -1513,35 +1513,40 @@
 FreeMarkerRoute(
-%22/%22
+this.url
 ) %7B%0A%0A%09%09%09@Overrid
@@ -1709,35 +1709,40 @@
 FreeMarkerRoute(
-%22/%22
+this.url
 ) %7B%0A%0A%09%09%09@Overrid
@@ -1920,11 +1920,16 @@
 ute(
-%22/%22
+this.url
 ) %7B%0A

修改URL为类的url，而不是"/"。