From b6d5c69d76c507f20f46a2d51581188acdf9741a Mon Sep 17 00:00:00 2001 From: "Yangkai.Shen" <237497819@qq.com> Date: Thu, 26 Apr 2018 17:31:08 +0800 Subject: [PATCH] =?UTF-8?q?spring=20boot=20=E9=9B=86=E6=88=90=20Beetl=20?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E5=BC=95=E6=93=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spring-boot-demo-parent/pom.xml | 1 + spring-boot-demo-template-beetl/README.md | 145 ++++++++++++++++++ spring-boot-demo-template-beetl/pom.xml | 32 ++++ ...pringBootDemoTemplateBeetlApplication.java | 12 ++ .../controller/HomeController.java | 37 +++++ .../model/User.java | 30 ++++ .../src/main/resources/application.yml | 5 + .../src/main/resources/templates/index.btl | 62 ++++++++ ...BootDemoTemplateBeetlApplicationTests.java | 16 ++ 9 files changed, 340 insertions(+) create mode 100644 spring-boot-demo-template-beetl/README.md create mode 100644 spring-boot-demo-template-beetl/pom.xml create mode 100644 spring-boot-demo-template-beetl/src/main/java/com/xkcoding/springbootdemotemplatebeetl/SpringBootDemoTemplateBeetlApplication.java create mode 100644 spring-boot-demo-template-beetl/src/main/java/com/xkcoding/springbootdemotemplatebeetl/controller/HomeController.java create mode 100644 spring-boot-demo-template-beetl/src/main/java/com/xkcoding/springbootdemotemplatebeetl/model/User.java create mode 100644 spring-boot-demo-template-beetl/src/main/resources/application.yml create mode 100644 spring-boot-demo-template-beetl/src/main/resources/templates/index.btl create mode 100644 spring-boot-demo-template-beetl/src/test/java/com/xkcoding/springbootdemotemplatebeetl/SpringBootDemoTemplateBeetlApplicationTests.java diff --git a/spring-boot-demo-parent/pom.xml b/spring-boot-demo-parent/pom.xml index 987d8c7..898e09a 100644 --- a/spring-boot-demo-parent/pom.xml +++ b/spring-boot-demo-parent/pom.xml @@ -30,6 +30,7 @@ ../spring-boot-demo-war ../spring-boot-demo-util ../spring-boot-demo-elasticsearch + ../spring-boot-demo-template-beetl diff --git a/spring-boot-demo-template-beetl/README.md b/spring-boot-demo-template-beetl/README.md new file mode 100644 index 0000000..a47829e --- /dev/null +++ b/spring-boot-demo-template-beetl/README.md @@ -0,0 +1,145 @@ +# spring-boot-demo-template-beetl + +依赖 [spring-boot-demo-parent](../spring-boot-demo-parent) 、`beetl-framework-starter` + +## pom.xml + +```xml + + + 4.0.0 + + spring-boot-demo-template-beetl + 0.0.1-SNAPSHOT + jar + + spring-boot-demo-template-beetl + Demo project for Spring Boot + + + com.xkcoding + spring-boot-demo-parent + 0.0.1-SNAPSHOT + ../spring-boot-demo-parent/pom.xml + + + + + com.ibeetl + beetl-framework-starter + 1.1.46.RELEASE + + + + + spring-boot-demo-template-beetl + + + +``` + +## HomeController.java + +```java +/** + *

+ * 首页 Controller + *

+ * + * @package: com.xkcoding.springbootdemotemplatebeetl.controller + * @description: 首页 Controller + * @author: yangkai.shen + * @date: Created in 2018/4/26 下午4:36 + * @copyright: Copyright (c) 2018 + * @version: V1.0 + * @modified: yangkai.shen + */ +@Controller +public class HomeController { + + @GetMapping({"", "/", "/index"}) + public ModelAndView index() { + ModelAndView view = new ModelAndView("/index.btl"); + User admin = new User(0, "admin", "phone0",true); + List userList = Lists.newArrayList(new User(1, "user1", "phone1",false), new User(2, "user2", "phone2",true), new User(3, "user3", "phone3",true),new User(4, "user4", "phone4",false)); + + view.addObject("admin",admin); + view.addObject("userList",userList); + return view; + } +} +``` + +## index.btl + +```html + + + + + + + Beetl demo + + +this is index.btl to show some beetl demos!
+ + +<% +/* demo01 */ +var a = 1; +var b = 2; +var result = a + b; +%> +1+2=${result}
+ + +<% +/* demo02 */ +print(111); +%> + + +欢迎登录,${admin.admin?"管理员":"员工"} ${admin.name}
+ + + + + + + + + + + + + + + <%for(u in userList){%> + + + + + + + <%if(uLP.even){%> + + <%}else{%> + + <%}%> + + <%}%> + +
序号编号姓名手机职位注册日期
${uLP.index}${u.id}${u.name}${u.tel}${u.admin?"管理员":"员工"}<%var today = date();%> ${today,dateFormat="yyyy-MM-dd HH:mm:ss"}<%var today = date();%> ${today,dateFormat="yyyy-MM-dd"}
+ + + +``` + +## Beetl 语法 + +请查看 Beetl 官网: + +http://ibeetl.com/guide/#beetl \ No newline at end of file diff --git a/spring-boot-demo-template-beetl/pom.xml b/spring-boot-demo-template-beetl/pom.xml new file mode 100644 index 0000000..f6601b1 --- /dev/null +++ b/spring-boot-demo-template-beetl/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + spring-boot-demo-template-beetl + 0.0.1-SNAPSHOT + jar + + spring-boot-demo-template-beetl + Demo project for Spring Boot + + + com.xkcoding + spring-boot-demo-parent + 0.0.1-SNAPSHOT + ../spring-boot-demo-parent/pom.xml + + + + + com.ibeetl + beetl-framework-starter + 1.1.46.RELEASE + + + + + spring-boot-demo-template-beetl + + + \ No newline at end of file diff --git a/spring-boot-demo-template-beetl/src/main/java/com/xkcoding/springbootdemotemplatebeetl/SpringBootDemoTemplateBeetlApplication.java b/spring-boot-demo-template-beetl/src/main/java/com/xkcoding/springbootdemotemplatebeetl/SpringBootDemoTemplateBeetlApplication.java new file mode 100644 index 0000000..59424b5 --- /dev/null +++ b/spring-boot-demo-template-beetl/src/main/java/com/xkcoding/springbootdemotemplatebeetl/SpringBootDemoTemplateBeetlApplication.java @@ -0,0 +1,12 @@ +package com.xkcoding.springbootdemotemplatebeetl; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringBootDemoTemplateBeetlApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringBootDemoTemplateBeetlApplication.class, args); + } +} diff --git a/spring-boot-demo-template-beetl/src/main/java/com/xkcoding/springbootdemotemplatebeetl/controller/HomeController.java b/spring-boot-demo-template-beetl/src/main/java/com/xkcoding/springbootdemotemplatebeetl/controller/HomeController.java new file mode 100644 index 0000000..0680ddc --- /dev/null +++ b/spring-boot-demo-template-beetl/src/main/java/com/xkcoding/springbootdemotemplatebeetl/controller/HomeController.java @@ -0,0 +1,37 @@ +package com.xkcoding.springbootdemotemplatebeetl.controller; + +import com.google.common.collect.Lists; +import com.xkcoding.springbootdemotemplatebeetl.model.User; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.servlet.ModelAndView; + +import java.util.List; + +/** + *

+ * 首页 Controller + *

+ * + * @package: com.xkcoding.springbootdemotemplatebeetl.controller + * @description: 首页 Controller + * @author: yangkai.shen + * @date: Created in 2018/4/26 下午4:36 + * @copyright: Copyright (c) 2018 + * @version: V1.0 + * @modified: yangkai.shen + */ +@Controller +public class HomeController { + + @GetMapping({"", "/", "/index"}) + public ModelAndView index() { + ModelAndView view = new ModelAndView("/index.btl"); + User admin = new User(0, "admin", "phone0",true); + List userList = Lists.newArrayList(new User(1, "user1", "phone1",false), new User(2, "user2", "phone2",true), new User(3, "user3", "phone3",true),new User(4, "user4", "phone4",false)); + + view.addObject("admin",admin); + view.addObject("userList",userList); + return view; + } +} diff --git a/spring-boot-demo-template-beetl/src/main/java/com/xkcoding/springbootdemotemplatebeetl/model/User.java b/spring-boot-demo-template-beetl/src/main/java/com/xkcoding/springbootdemotemplatebeetl/model/User.java new file mode 100644 index 0000000..d832972 --- /dev/null +++ b/spring-boot-demo-template-beetl/src/main/java/com/xkcoding/springbootdemotemplatebeetl/model/User.java @@ -0,0 +1,30 @@ +package com.xkcoding.springbootdemotemplatebeetl.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + *

+ * 用户实体类 + *

+ * + * @package: com.xkcoding.springbootdemotemplatebeetl.model + * @description: 用户实体类 + * @author: yangkai.shen + * @date: Created in 2018/4/26 下午4:46 + * @copyright: Copyright (c) 2018 + * @version: V1.0 + * @modified: yangkai.shen + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class User implements Serializable { + private Integer id; + private String name; + private String tel; + private Boolean admin; +} diff --git a/spring-boot-demo-template-beetl/src/main/resources/application.yml b/spring-boot-demo-template-beetl/src/main/resources/application.yml new file mode 100644 index 0000000..172dc29 --- /dev/null +++ b/spring-boot-demo-template-beetl/src/main/resources/application.yml @@ -0,0 +1,5 @@ +server: + port: 8080 + context-path: /demo +beetlSql: + enabled: false diff --git a/spring-boot-demo-template-beetl/src/main/resources/templates/index.btl b/spring-boot-demo-template-beetl/src/main/resources/templates/index.btl new file mode 100644 index 0000000..0017df3 --- /dev/null +++ b/spring-boot-demo-template-beetl/src/main/resources/templates/index.btl @@ -0,0 +1,62 @@ + + + + + + + Beetl demo + + +this is index.btl to show some beetl demos!
+ + +<% +/* demo01 */ +var a = 1; +var b = 2; +var result = a + b; +%> +1+2=${result}
+ + +<% +/* demo02 */ +print(111); +%> + + +欢迎登录,${admin.admin?"管理员":"员工"} ${admin.name}
+ + + + + + + + + + + + + + + <%for(u in userList){%> + + + + + + + <%if(uLP.even){%> + + <%}else{%> + + <%}%> + + <%}%> + +
序号编号姓名手机职位注册日期
${uLP.index}${u.id}${u.name}${u.tel}${u.admin?"管理员":"员工"}<%var today = date();%> ${today,dateFormat="yyyy-MM-dd HH:mm:ss"}<%var today = date();%> ${today,dateFormat="yyyy-MM-dd"}
+ + + \ No newline at end of file diff --git a/spring-boot-demo-template-beetl/src/test/java/com/xkcoding/springbootdemotemplatebeetl/SpringBootDemoTemplateBeetlApplicationTests.java b/spring-boot-demo-template-beetl/src/test/java/com/xkcoding/springbootdemotemplatebeetl/SpringBootDemoTemplateBeetlApplicationTests.java new file mode 100644 index 0000000..5e453dc --- /dev/null +++ b/spring-boot-demo-template-beetl/src/test/java/com/xkcoding/springbootdemotemplatebeetl/SpringBootDemoTemplateBeetlApplicationTests.java @@ -0,0 +1,16 @@ +package com.xkcoding.springbootdemotemplatebeetl; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class SpringBootDemoTemplateBeetlApplicationTests { + + @Test + public void contextLoads() { + } + +}