From 42187fa158255151d00bb6aea1532448cf8cfc61 Mon Sep 17 00:00:00 2001 From: Wendal Chen Date: Thu, 23 Nov 2017 14:42:14 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E6=B7=BB=E5=8A=A0starter-beetl,?= =?UTF-8?q?=E5=B9=B6=E6=B7=BB=E5=8A=A0=E5=AF=B9=E5=BA=94=E7=9A=84demo=20ch?= =?UTF-8?q?ange:=20=E6=8A=8Anutzboot-demo-simple=E7=BB=9F=E7=BB=9F?= =?UTF-8?q?=E6=94=BE=E5=88=B0=E4=B8=80=E4=B8=AA=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E5=86=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- .../io/nutz/demo/simple/MainLauncher.java | 49 ------------- .../java/io/nutz/demo/simple/bean/User.java | 51 -------------- .../nutzboot-demo-simple-beetl}/pom.xml | 21 +++--- .../io/nutz/demo/simple/MainLauncher.java | 24 +++++++ .../src/main/resources/application.properties | 0 .../src/main/resources/log4j.properties | 0 .../src/main/resources/template/index.html | 16 +++++ .../nutzboot-demo-simple-dao/pom.xml | 2 +- .../io/nutz/demo/simple/MainLauncher.java | 0 .../java/io/nutz/demo/simple/bean/User.java | 0 .../nutz/demo/simple/module/UserModule.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/log4j.properties | 0 .../src/main/resources/static/index.html | 0 .../nutzboot-demo-simple-mvc/pom.xml | 37 ++++++++++ .../io/nutz/demo/simple/MainLauncher.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/log4j.properties | 0 .../src/main/resources/static/index.html | 0 .../nutzboot-demo-simple-redis/pom.xml | 12 ++-- .../io/nutz/demo/simple/MainLauncher.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/log4j.properties | 0 .../src/main/resources/static/index.html | 0 nutzboot-demo/nutzboot-demo-simple/pom.xml | 60 +++++++--------- .../src/main/resources/static/index.html | 10 --- nutzboot-starter-beetl/pom.xml | 22 ++++++ .../starter/beetl/BeetlViewMakerStarter.java | 68 +++++++++++++++++++ .../nutz/org.nutz.boot.starter.NbStarter | 1 + pom.xml | 1 + 31 files changed, 209 insertions(+), 167 deletions(-) delete mode 100644 nutzboot-demo/nutzboot-demo-simple-weixin/src/main/java/io/nutz/demo/simple/MainLauncher.java delete mode 100644 nutzboot-demo/nutzboot-demo-simple-weixin/src/main/java/io/nutz/demo/simple/bean/User.java rename nutzboot-demo/{nutzboot-demo-simple-weixin => nutzboot-demo-simple/nutzboot-demo-simple-beetl}/pom.xml (78%) create mode 100644 nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-beetl/src/main/java/io/nutz/demo/simple/MainLauncher.java rename nutzboot-demo/{nutzboot-demo-simple-dao => nutzboot-demo-simple/nutzboot-demo-simple-beetl}/src/main/resources/application.properties (100%) rename nutzboot-demo/{nutzboot-demo-simple-redis => nutzboot-demo-simple/nutzboot-demo-simple-beetl}/src/main/resources/log4j.properties (100%) create mode 100644 nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-beetl/src/main/resources/template/index.html rename nutzboot-demo/{ => nutzboot-demo-simple}/nutzboot-demo-simple-dao/pom.xml (95%) rename nutzboot-demo/{ => nutzboot-demo-simple}/nutzboot-demo-simple-dao/src/main/java/io/nutz/demo/simple/MainLauncher.java (100%) rename nutzboot-demo/{ => nutzboot-demo-simple}/nutzboot-demo-simple-dao/src/main/java/io/nutz/demo/simple/bean/User.java (100%) rename nutzboot-demo/{ => nutzboot-demo-simple}/nutzboot-demo-simple-dao/src/main/java/io/nutz/demo/simple/module/UserModule.java (100%) rename nutzboot-demo/{nutzboot-demo-simple-redis => nutzboot-demo-simple/nutzboot-demo-simple-dao}/src/main/resources/application.properties (100%) rename nutzboot-demo/{ => nutzboot-demo-simple}/nutzboot-demo-simple-dao/src/main/resources/log4j.properties (100%) rename nutzboot-demo/{ => nutzboot-demo-simple}/nutzboot-demo-simple-dao/src/main/resources/static/index.html (100%) create mode 100644 nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-mvc/pom.xml rename nutzboot-demo/nutzboot-demo-simple/{ => nutzboot-demo-simple-mvc}/src/main/java/io/nutz/demo/simple/MainLauncher.java (100%) rename nutzboot-demo/nutzboot-demo-simple/{ => nutzboot-demo-simple-mvc}/src/main/resources/application.properties (100%) rename nutzboot-demo/{nutzboot-demo-simple-weixin => nutzboot-demo-simple/nutzboot-demo-simple-mvc}/src/main/resources/log4j.properties (100%) rename nutzboot-demo/{nutzboot-demo-simple-redis => nutzboot-demo-simple/nutzboot-demo-simple-mvc}/src/main/resources/static/index.html (100%) rename nutzboot-demo/{ => nutzboot-demo-simple}/nutzboot-demo-simple-redis/pom.xml (95%) rename nutzboot-demo/{ => nutzboot-demo-simple}/nutzboot-demo-simple-redis/src/main/java/io/nutz/demo/simple/MainLauncher.java (100%) rename nutzboot-demo/{nutzboot-demo-simple-weixin => nutzboot-demo-simple/nutzboot-demo-simple-redis}/src/main/resources/application.properties (100%) rename nutzboot-demo/nutzboot-demo-simple/{ => nutzboot-demo-simple-redis}/src/main/resources/log4j.properties (100%) rename nutzboot-demo/{nutzboot-demo-simple-weixin => nutzboot-demo-simple/nutzboot-demo-simple-redis}/src/main/resources/static/index.html (100%) delete mode 100644 nutzboot-demo/nutzboot-demo-simple/src/main/resources/static/index.html create mode 100644 nutzboot-starter-beetl/pom.xml create mode 100644 nutzboot-starter-beetl/src/main/java/org/nutz/boot/starter/beetl/BeetlViewMakerStarter.java create mode 100644 nutzboot-starter-beetl/src/main/resources/META-INF/nutz/org.nutz.boot.starter.NbStarter diff --git a/README.md b/README.md index b666ab94..efce9f92 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ public class MainLauncher { - [ ] 计划任务 - [x] [Quartz](http://www.quartz-scheduler.org) - [ ] 模板引擎 - - [ ] [Beetl](http://ibeetl.com/) + - [x] [Beetl](http://ibeetl.com/) - [ ] [jetbrick-template](https://github.com/subchen/jetbrick-template-2x) - [ ] Vecloity - [ ] FreeMarker diff --git a/nutzboot-demo/nutzboot-demo-simple-weixin/src/main/java/io/nutz/demo/simple/MainLauncher.java b/nutzboot-demo/nutzboot-demo-simple-weixin/src/main/java/io/nutz/demo/simple/MainLauncher.java deleted file mode 100644 index 83a86d1c..00000000 --- a/nutzboot-demo/nutzboot-demo-simple-weixin/src/main/java/io/nutz/demo/simple/MainLauncher.java +++ /dev/null @@ -1,49 +0,0 @@ -package io.nutz.demo.simple; - -import java.util.List; - -import org.nutz.boot.NbApp; -import org.nutz.dao.Cnd; -import org.nutz.dao.Dao; -import org.nutz.dao.pager.Pager; -import org.nutz.ioc.loader.annotation.Inject; -import org.nutz.ioc.loader.annotation.IocBean; -import org.nutz.mvc.annotation.At; -import org.nutz.mvc.annotation.Ok; -import org.nutz.mvc.annotation.Param; - -import io.nutz.demo.simple.bean.User; - -@IocBean(create="init") -public class MainLauncher { - - @Inject - Dao dao; - - @Ok("raw") - @At("/user/count") - public long count() { - return dao.count(User.class); - } - - @Ok("json:full") - @At("/user/query") - public List query(@Param("..")Pager pager) { - return dao.query(User.class, Cnd.orderBy().asc("age"), pager); - } - - public void init() { - dao.create(User.class, true); - dao.insert(new User("apple", 40, "北京")); - dao.insert(new User("ball", 30, "未知")); - dao.insert(new User("cat", 50, "温哥华")); - dao.insert(new User("fox", 51, "纽约")); - dao.insert(new User("bra", 25, "济南")); - dao.insert(new User("lina", 50, "深圳")); - } - - public static void main(String[] args) throws Exception { - new NbApp(MainLauncher.class).run(); - } - -} diff --git a/nutzboot-demo/nutzboot-demo-simple-weixin/src/main/java/io/nutz/demo/simple/bean/User.java b/nutzboot-demo/nutzboot-demo-simple-weixin/src/main/java/io/nutz/demo/simple/bean/User.java deleted file mode 100644 index a65da8bb..00000000 --- a/nutzboot-demo/nutzboot-demo-simple-weixin/src/main/java/io/nutz/demo/simple/bean/User.java +++ /dev/null @@ -1,51 +0,0 @@ -package io.nutz.demo.simple.bean; - -import org.nutz.dao.entity.annotation.Id; -import org.nutz.dao.entity.annotation.Name; -import org.nutz.dao.entity.annotation.Table; - -@Table("t_user") -public class User { - - @Id - private long id; - @Name - private String name; - private int age; - private String location; - - public User() { - } - - public User(String name, int age, String location) { - super(); - this.name = name; - this.age = age; - this.location = location; - } - - public long getId() { - return id; - } - public void setId(long id) { - this.id = id; - } - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - public int getAge() { - return age; - } - public void setAge(int age) { - this.age = age; - } - public String getLocation() { - return location; - } - public void setLocation(String location) { - this.location = location; - } -} diff --git a/nutzboot-demo/nutzboot-demo-simple-weixin/pom.xml b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-beetl/pom.xml similarity index 78% rename from nutzboot-demo/nutzboot-demo-simple-weixin/pom.xml rename to nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-beetl/pom.xml index 6894fb30..80d1ba69 100644 --- a/nutzboot-demo/nutzboot-demo-simple-weixin/pom.xml +++ b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-beetl/pom.xml @@ -3,10 +3,10 @@ 4.0.0 org.nutz - nutzboot-demo + nutzboot-demo-simple 2.0-SNAPSHOT - nutzboot-demo-simple-weixin + nutzboot-demo-simple-beetl org.nutz @@ -15,7 +15,12 @@ org.nutz - nutzboot-starter-weixin + nutzboot-starter-jetty + ${project.version} + + + org.nutz + nutzboot-starter-beetl ${project.version} @@ -28,15 +33,5 @@ slf4j-log4j12 1.7.25 - - com.h2database - h2 - 1.4.196 - - - org.nutz - nutzboot-starter-jetty - ${project.version} - \ No newline at end of file diff --git a/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-beetl/src/main/java/io/nutz/demo/simple/MainLauncher.java b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-beetl/src/main/java/io/nutz/demo/simple/MainLauncher.java new file mode 100644 index 00000000..09c3b03e --- /dev/null +++ b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-beetl/src/main/java/io/nutz/demo/simple/MainLauncher.java @@ -0,0 +1,24 @@ +package io.nutz.demo.simple; + +import org.nutz.boot.NbApp; +import org.nutz.ioc.loader.annotation.IocBean; +import org.nutz.lang.util.NutMap; +import org.nutz.mvc.annotation.At; +import org.nutz.mvc.annotation.Ok; + +@IocBean +public class MainLauncher { + + @At({"/", "/index"}) + @Ok("beetl:/index.html") + public NutMap index() { + NutMap obj = new NutMap(); + obj.setv("name", "NB").setv("age", 18); + return obj; + } + + public static void main(String[] args) throws Exception { + new NbApp(MainLauncher.class).run(); + } + +} diff --git a/nutzboot-demo/nutzboot-demo-simple-dao/src/main/resources/application.properties b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-beetl/src/main/resources/application.properties similarity index 100% rename from nutzboot-demo/nutzboot-demo-simple-dao/src/main/resources/application.properties rename to nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-beetl/src/main/resources/application.properties diff --git a/nutzboot-demo/nutzboot-demo-simple-redis/src/main/resources/log4j.properties b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-beetl/src/main/resources/log4j.properties similarity index 100% rename from nutzboot-demo/nutzboot-demo-simple-redis/src/main/resources/log4j.properties rename to nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-beetl/src/main/resources/log4j.properties diff --git a/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-beetl/src/main/resources/template/index.html b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-beetl/src/main/resources/template/index.html new file mode 100644 index 00000000..d7e4a592 --- /dev/null +++ b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-beetl/src/main/resources/template/index.html @@ -0,0 +1,16 @@ + + + + +NB demo for Beetl + + +
+

Context Path = '${base}'

+
+
+

From Action name=${obj.name}, age=${obj.age}

+
+ + + \ No newline at end of file diff --git a/nutzboot-demo/nutzboot-demo-simple-dao/pom.xml b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-dao/pom.xml similarity index 95% rename from nutzboot-demo/nutzboot-demo-simple-dao/pom.xml rename to nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-dao/pom.xml index 26dd8b56..ae9995b0 100644 --- a/nutzboot-demo/nutzboot-demo-simple-dao/pom.xml +++ b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-dao/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.nutz - nutzboot-demo + nutzboot-demo-simple 2.0-SNAPSHOT nutzboot-demo-simple-dao diff --git a/nutzboot-demo/nutzboot-demo-simple-dao/src/main/java/io/nutz/demo/simple/MainLauncher.java b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-dao/src/main/java/io/nutz/demo/simple/MainLauncher.java similarity index 100% rename from nutzboot-demo/nutzboot-demo-simple-dao/src/main/java/io/nutz/demo/simple/MainLauncher.java rename to nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-dao/src/main/java/io/nutz/demo/simple/MainLauncher.java diff --git a/nutzboot-demo/nutzboot-demo-simple-dao/src/main/java/io/nutz/demo/simple/bean/User.java b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-dao/src/main/java/io/nutz/demo/simple/bean/User.java similarity index 100% rename from nutzboot-demo/nutzboot-demo-simple-dao/src/main/java/io/nutz/demo/simple/bean/User.java rename to nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-dao/src/main/java/io/nutz/demo/simple/bean/User.java diff --git a/nutzboot-demo/nutzboot-demo-simple-dao/src/main/java/io/nutz/demo/simple/module/UserModule.java b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-dao/src/main/java/io/nutz/demo/simple/module/UserModule.java similarity index 100% rename from nutzboot-demo/nutzboot-demo-simple-dao/src/main/java/io/nutz/demo/simple/module/UserModule.java rename to nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-dao/src/main/java/io/nutz/demo/simple/module/UserModule.java diff --git a/nutzboot-demo/nutzboot-demo-simple-redis/src/main/resources/application.properties b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-dao/src/main/resources/application.properties similarity index 100% rename from nutzboot-demo/nutzboot-demo-simple-redis/src/main/resources/application.properties rename to nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-dao/src/main/resources/application.properties diff --git a/nutzboot-demo/nutzboot-demo-simple-dao/src/main/resources/log4j.properties b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-dao/src/main/resources/log4j.properties similarity index 100% rename from nutzboot-demo/nutzboot-demo-simple-dao/src/main/resources/log4j.properties rename to nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-dao/src/main/resources/log4j.properties diff --git a/nutzboot-demo/nutzboot-demo-simple-dao/src/main/resources/static/index.html b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-dao/src/main/resources/static/index.html similarity index 100% rename from nutzboot-demo/nutzboot-demo-simple-dao/src/main/resources/static/index.html rename to nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-dao/src/main/resources/static/index.html diff --git a/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-mvc/pom.xml b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-mvc/pom.xml new file mode 100644 index 00000000..a2e2c504 --- /dev/null +++ b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-mvc/pom.xml @@ -0,0 +1,37 @@ + + 4.0.0 + + org.nutz + nutzboot-demo-simple + 2.0-SNAPSHOT + + nutzboot-demo-simple-mvc + + + org.nutz + nutzboot-starter-nutz-mvc + 2.0-SNAPSHOT + + + org.nutz + nutzboot-starter-jetty + 2.0-SNAPSHOT + + + org.nutz + nutzboot-starter + 2.0-SNAPSHOT + + + log4j + log4j + 1.2.17 + + + org.slf4j + slf4j-log4j12 + 1.7.25 + + + \ No newline at end of file diff --git a/nutzboot-demo/nutzboot-demo-simple/src/main/java/io/nutz/demo/simple/MainLauncher.java b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-mvc/src/main/java/io/nutz/demo/simple/MainLauncher.java similarity index 100% rename from nutzboot-demo/nutzboot-demo-simple/src/main/java/io/nutz/demo/simple/MainLauncher.java rename to nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-mvc/src/main/java/io/nutz/demo/simple/MainLauncher.java diff --git a/nutzboot-demo/nutzboot-demo-simple/src/main/resources/application.properties b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-mvc/src/main/resources/application.properties similarity index 100% rename from nutzboot-demo/nutzboot-demo-simple/src/main/resources/application.properties rename to nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-mvc/src/main/resources/application.properties diff --git a/nutzboot-demo/nutzboot-demo-simple-weixin/src/main/resources/log4j.properties b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-mvc/src/main/resources/log4j.properties similarity index 100% rename from nutzboot-demo/nutzboot-demo-simple-weixin/src/main/resources/log4j.properties rename to nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-mvc/src/main/resources/log4j.properties diff --git a/nutzboot-demo/nutzboot-demo-simple-redis/src/main/resources/static/index.html b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-mvc/src/main/resources/static/index.html similarity index 100% rename from nutzboot-demo/nutzboot-demo-simple-redis/src/main/resources/static/index.html rename to nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-mvc/src/main/resources/static/index.html diff --git a/nutzboot-demo/nutzboot-demo-simple-redis/pom.xml b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-redis/pom.xml similarity index 95% rename from nutzboot-demo/nutzboot-demo-simple-redis/pom.xml rename to nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-redis/pom.xml index d4854984..80b4ce49 100644 --- a/nutzboot-demo/nutzboot-demo-simple-redis/pom.xml +++ b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-redis/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.nutz - nutzboot-demo + nutzboot-demo-simple 2.0-SNAPSHOT nutzboot-demo-simple-redis @@ -28,15 +28,15 @@ log4j 1.2.17 - - org.slf4j - slf4j-log4j12 - 1.7.25 - com.h2database h2 1.4.196 + + org.slf4j + slf4j-log4j12 + 1.7.25 + \ No newline at end of file diff --git a/nutzboot-demo/nutzboot-demo-simple-redis/src/main/java/io/nutz/demo/simple/MainLauncher.java b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-redis/src/main/java/io/nutz/demo/simple/MainLauncher.java similarity index 100% rename from nutzboot-demo/nutzboot-demo-simple-redis/src/main/java/io/nutz/demo/simple/MainLauncher.java rename to nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-redis/src/main/java/io/nutz/demo/simple/MainLauncher.java diff --git a/nutzboot-demo/nutzboot-demo-simple-weixin/src/main/resources/application.properties b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-redis/src/main/resources/application.properties similarity index 100% rename from nutzboot-demo/nutzboot-demo-simple-weixin/src/main/resources/application.properties rename to nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-redis/src/main/resources/application.properties diff --git a/nutzboot-demo/nutzboot-demo-simple/src/main/resources/log4j.properties b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-redis/src/main/resources/log4j.properties similarity index 100% rename from nutzboot-demo/nutzboot-demo-simple/src/main/resources/log4j.properties rename to nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-redis/src/main/resources/log4j.properties diff --git a/nutzboot-demo/nutzboot-demo-simple-weixin/src/main/resources/static/index.html b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-redis/src/main/resources/static/index.html similarity index 100% rename from nutzboot-demo/nutzboot-demo-simple-weixin/src/main/resources/static/index.html rename to nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-redis/src/main/resources/static/index.html diff --git a/nutzboot-demo/nutzboot-demo-simple/pom.xml b/nutzboot-demo/nutzboot-demo-simple/pom.xml index 2c131adb..5b9e7a75 100644 --- a/nutzboot-demo/nutzboot-demo-simple/pom.xml +++ b/nutzboot-demo/nutzboot-demo-simple/pom.xml @@ -1,37 +1,25 @@ - - 4.0.0 - - org.nutz - nutzboot-demo - 2.0-SNAPSHOT - - nutzboot-demo-simple - - - org.nutz - nutzboot-starter-nutz-mvc - 2.0-SNAPSHOT - - - org.nutz - nutzboot-starter-jetty - 2.0-SNAPSHOT - - - org.nutz - nutzboot-starter - 2.0-SNAPSHOT - - - log4j - log4j - 1.2.17 - - - org.slf4j - slf4j-log4j12 - 1.7.25 - - + + 4.0.0 + + org.nutz + nutzboot-demo + 2.0-SNAPSHOT + + nutzboot-demo-simple + pom + + nutzboot-demo-simple-mvc + nutzboot-demo-simple-dao + nutzboot-demo-simple-redis + + + + + + + org.nutz + nutzboot-starter + ${project.version} + + \ No newline at end of file diff --git a/nutzboot-demo/nutzboot-demo-simple/src/main/resources/static/index.html b/nutzboot-demo/nutzboot-demo-simple/src/main/resources/static/index.html deleted file mode 100644 index 279b8e13..00000000 --- a/nutzboot-demo/nutzboot-demo-simple/src/main/resources/static/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - -Hello, So NB! - - -Hello, So NB! - - \ No newline at end of file diff --git a/nutzboot-starter-beetl/pom.xml b/nutzboot-starter-beetl/pom.xml new file mode 100644 index 00000000..e9202e6e --- /dev/null +++ b/nutzboot-starter-beetl/pom.xml @@ -0,0 +1,22 @@ + + 4.0.0 + + org.nutz + nutzboot-parent + 2.0-SNAPSHOT + + nutzboot-starter-beetl + + + org.nutz + nutzboot-starter + ${project.version} + provided + + + com.ibeetl + beetl + 2.7.23 + + + \ No newline at end of file diff --git a/nutzboot-starter-beetl/src/main/java/org/nutz/boot/starter/beetl/BeetlViewMakerStarter.java b/nutzboot-starter-beetl/src/main/java/org/nutz/boot/starter/beetl/BeetlViewMakerStarter.java new file mode 100644 index 00000000..621eeb53 --- /dev/null +++ b/nutzboot-starter-beetl/src/main/java/org/nutz/boot/starter/beetl/BeetlViewMakerStarter.java @@ -0,0 +1,68 @@ +package org.nutz.boot.starter.beetl; + +import java.io.IOException; +import java.util.Properties; + +import org.beetl.core.Configuration; +import org.beetl.core.GroupTemplate; +import org.beetl.core.resource.ClasspathResourceLoader; +import org.beetl.ext.nutz.BeetlViewMaker; +import org.beetl.ext.nutz.LogErrorHandler; +import org.beetl.ext.web.WebRender; +import org.nutz.boot.AppContext; +import org.nutz.ioc.impl.PropertiesProxy; +import org.nutz.ioc.loader.annotation.Inject; +import org.nutz.ioc.loader.annotation.IocBean; +import org.nutz.log.Log; +import org.nutz.log.Logs; + +@IocBean(name="$views_beetl", create="init") +public class BeetlViewMakerStarter extends BeetlViewMaker { + + private static final Log log = Logs.get(); + + @Inject + protected PropertiesProxy conf; + + @Inject + protected AppContext appContext; + + public BeetlViewMakerStarter() throws IOException { + super(); + } + + public void init() throws IOException { + if (conf == null) + return; + log.debug("beetl init ...."); + Configuration cfg = Configuration.defaultConfiguration(); + Properties prop = new Properties(); + for (String key : conf.keySet()) { + if (key.startsWith("beetl.")) { + prop.put(key.substring("beetl.".length()), conf.get(key)); + } + } + if (!prop.containsKey(Configuration.DIRECT_BYTE_OUTPUT)) { + // 默认启用DIRECT_BYTE_OUTPUT,除非用户自定义, 一般不会. + log.debug("no custom DIRECT_BYTE_OUTPUT found , set to true"); + // 当DIRECT_BYTE_OUTPUT为真时, beetl渲染会通过getOutputStream获取输出流 + // 而BeetlView会使用LazyResponseWrapper代理getOutputStream方法 + // 从而实现在模板输出之前,避免真正调用getOutputStream + // 这样@Fail视图就能正常工作了 + cfg.setDirectByteOutput(true); + } + if (!prop.containsKey(Configuration.ERROR_HANDLER)) { + // 没有自定义ERROR_HANDLER,用定制的 + cfg.setErrorHandlerClass(LogErrorHandler.class.getName()); + } + groupTemplate = new GroupTemplate(cfg); + + if (!prop.containsKey(Configuration.RESOURCE_LOADER)) { + // 默认选用WebAppResourceLoader,除非用户自定义了RESOURCE_LOADER + log.debug("no custom RESOURCE_LOADER found , select ClasspathResourceLoader"); + groupTemplate.setResourceLoader(new ClasspathResourceLoader(appContext.getClassLoader(), prop.getProperty("root", "template/"))); + } + render = new WebRender(groupTemplate); + log.debug("beetl init complete"); + } +} diff --git a/nutzboot-starter-beetl/src/main/resources/META-INF/nutz/org.nutz.boot.starter.NbStarter b/nutzboot-starter-beetl/src/main/resources/META-INF/nutz/org.nutz.boot.starter.NbStarter new file mode 100644 index 00000000..06198c3c --- /dev/null +++ b/nutzboot-starter-beetl/src/main/resources/META-INF/nutz/org.nutz.boot.starter.NbStarter @@ -0,0 +1 @@ +org.nutz.boot.starter.beetl.BeetlViewMakerStarter diff --git a/pom.xml b/pom.xml index d442f58d..ae635801 100644 --- a/pom.xml +++ b/pom.xml @@ -61,6 +61,7 @@ nutzboot-starter-wkcache nutzboot-starter-redis nutzboot-starter-disque + nutzboot-starter-beetl