Skip to content

Commit

Permalink
jsp -> 使用thymeleaf模版
Browse files Browse the repository at this point in the history
  • Loading branch information
zhitom committed Sep 10, 2018
1 parent 023d65f commit e4fcb1d
Show file tree
Hide file tree
Showing 540 changed files with 142 additions and 186 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ yasenagat-zkweb svn: [http://code.taobao.org/svn/zkweb/](http://code.taobao.org/
- Front-end web add i18n Internationalization plugin,Support english and zh_CN,and server-end data don't added this.
- Upgrade to use spring boot 2
- Add favicon.ico
- Todo: jsp -> Thymeleaf
- jsp -> Thymeleaf

## zkWeb-zh_CN
zookeeper web管理和监控界面,使用内置的H2数据库,此版本基于淘宝大神yasenagat的zkWeb源码基础之上进行了大幅升级和修改,有两种运行方式:
Expand All @@ -43,7 +43,7 @@ yasenagat-zkweb svn: [http://code.taobao.org/svn/zkweb/](http://code.taobao.org/
- 前端web增加i18n国际化插件,支持界面英文展示,注:服务端数据未支持国际化。
- 使用spring boot 2升级改造,可以不依赖tomcat
- 增加了浏览器图标favicon.ico
- Todo: jsp -> Thymeleaf
- jsp -> Thymeleaf

### screen snapshot

Expand All @@ -59,3 +59,8 @@ disconnected: [https://user-images.githubusercontent.com/2204457/41921099-a9d536

- 打war包,webapp/resources被默认打包到根目录下导致无法访问,需要打包到WEB-INF/classes/resources

- 改造为使用Thymeleaf模版后,目前已经将webapp目录移除了
- pom-jar.xml for jar,pom-tomcat.xml for tomcat



43 changes: 7 additions & 36 deletions pom-jar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,6 @@
</properties>

<build>
<resources>
<resource>
<directory>${basedir}/src/main/webapp</directory>
<!--注意此次必须要放在此目录下才能被访问到-->
<targetPath>META-INF/resources/webapp</targetPath>
<excludes>
<exclude>WEB-INF/**</exclude>
</excludes>
<includes>
<include>**/**</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
<!--注意此次必须要放在此目录下才能被访问到jsp-->
<targetPath>/WEB-INF/</targetPath>
<includes>
<include>**/**</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>**/**</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand All @@ -72,6 +45,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.springframework.boot</groupId> -->
<!-- <artifactId>spring-boot-starter-data-jpa</artifactId> -->
Expand Down Expand Up @@ -134,17 +111,11 @@
<groupId>com.fasterxml.jackson.jr</groupId>
<artifactId>jackson-jr-all</artifactId>
</dependency>

<!-- JSP依赖 必需使用,内置的tomcat不支持jsp-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<!-- <scope>provided</scope> -->
</dependency>
<dependency>

<!-- <dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
</dependency> -->

<!-- Zookeeper -->
<dependency>
Expand Down
44 changes: 24 additions & 20 deletions pom-tomcat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<!-- 从target打成war包时的过滤,基准目录是target/zkWeb-v1.1 下面已经过滤了,这里无需再次过滤-->
<!-- <packagingExcludes>resources/**</packagingExcludes> -->
<!-- 从target打成war包时的过滤 ,基准目录是${basedir}/src/main/webapp -->
<warSourceExcludes>resources/**</warSourceExcludes>
<webResources>
<!-- <configuration> -->
<!-- 从target打成war包时的过滤,基准目录是target/zkWeb-v1.1 下面已经过滤了,这里无需再次过滤 -->
<!-- <packagingExcludes>resources/**</packagingExcludes> -->
<!-- 从target打成war包时的过滤 ,基准目录是${basedir}/src/main/webapp -->
<!-- <warSourceExcludes>resources/**</warSourceExcludes> -->
<!-- <webResources> -->
<!-- <resource> -->
<!-- <directory>src/main/resources/config/${package.environment}</directory> -->
<!-- <targetPath>WEB-INF/classes/config</targetPath> -->
<!-- <filtering>true</filtering> -->
<!-- </resource> -->
<resource>
<directory>${basedir}/src/main/webapp/resources</directory>
<!--注意此次必须要放在此目录下才能被访问到jsp-->
<targetPath>WEB-INF/classes/resources/</targetPath>
<includes>
<include>**/**</include>
</includes>
</resource>
</webResources>
</configuration>
<!-- <resource> -->
<!-- <directory>${basedir}/src/main/webapp/resources</directory> -->
<!-- 注意此次必须要放在此目录下才能被访问到jsp -->
<!-- <targetPath>WEB-INF/classes/resources/</targetPath> -->
<!-- <includes> -->
<!-- <include>**/**</include> -->
<!-- </includes> -->
<!-- </resource> -->
<!-- </webResources> -->
<!-- </configuration> -->
</plugin>
</plugins>
</build>
Expand All @@ -63,6 +63,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.springframework.boot</groupId> -->
<!-- <artifactId>spring-boot-starter-data-jpa</artifactId> -->
Expand Down Expand Up @@ -127,23 +131,23 @@
<artifactId>jackson-jr-all</artifactId>
</dependency>
<!-- servlet -->
<dependency>
<!-- <dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0-alpha-1</version>
<scope>provided</scope>
</dependency>
</dependency> -->

<!-- JSP依赖 -->
<dependency>
<!-- <dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
</dependency> -->

<!-- Zookeeper -->
<dependency>
Expand Down
43 changes: 7 additions & 36 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,6 @@
</properties>

<build>
<resources>
<resource>
<directory>${basedir}/src/main/webapp</directory>
<!--注意此次必须要放在此目录下才能被访问到-->
<targetPath>META-INF/resources/webapp</targetPath>
<excludes>
<exclude>WEB-INF/**</exclude>
</excludes>
<includes>
<include>**/**</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
<!--注意此次必须要放在此目录下才能被访问到jsp-->
<targetPath>/WEB-INF/</targetPath>
<includes>
<include>**/**</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>**/**</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand All @@ -72,6 +45,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.springframework.boot</groupId> -->
<!-- <artifactId>spring-boot-starter-data-jpa</artifactId> -->
Expand Down Expand Up @@ -134,17 +111,11 @@
<groupId>com.fasterxml.jackson.jr</groupId>
<artifactId>jackson-jr-all</artifactId>
</dependency>

<!-- JSP依赖 必需使用,内置的tomcat不支持jsp-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<!-- <scope>provided</scope> -->
</dependency>
<dependency>

<!-- <dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
</dependency> -->

<!-- Zookeeper -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ public DataSource getDataSource(){

@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("/home");
registry.addViewController("/").setViewName("home");
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("classpath:/resources/",
"classpath:/META-INF/resources/webapp/resources/");//,"classpath:/resources/webapp/WEB-INF/views/");
registry.addResourceHandler("/resources/**").addResourceLocations("classpath:/resources/");//,"classpath:/resources/webapp/WEB-INF/views/");
//registry.addResourceHandler("/**");
//registry.addResourceHandler("/resources/**").addResourceLocations("classpath:/static/");
}

@Bean
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/yasenagat/zkweb/web/ZkController.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,23 @@ public String queryzNodeInfo(
String data=ZkCache.get(cacheId).getData(path);
if(data==null) {
model.addAttribute("data", "");
model.addAttribute("acls", "");
model.addAttribute("acls", Collections.emptyList());
return "info";
}
model.addAttribute("data", ZkCache.get(cacheId).getData(path).trim());
model.mergeAttributes(ZkCache.get(cacheId).getNodeMeta(path));
model.addAttribute("acls", ZkCache.get(cacheId).getACLs(path));
}
log.info("model : " + model);

} catch (Exception e) {
e.printStackTrace();
model.addAttribute("zkpath", path);
model.addAttribute("path",path);
model.addAttribute("cacheId", cacheId);
model.addAttribute("data", "");
model.addAttribute("acls", Collections.emptyList());
}
log.info("model : " + model);
return "info";
}
@RequestMapping(value="/queryZKOk")
Expand Down
32 changes: 28 additions & 4 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,32 @@ spring:
encoding:
force: true
thymeleaf:
enabled: false
# THYMELEAF (ThymeleafAutoConfiguration)
#开启模板缓存(默认值:true)
cache: false
#Check that the template exists before rendering it.
check-template: true
#检查模板位置是否正确(默认值:true)
check-template-location: true
#Content-Type的值(默认值:text/html)
servlet:
content-type: text/html
#开启MVC Thymeleaf视图解析(默认值:true)
enabled: true
#模板编码
encoding: UTF-8
#要被排除在解析之外的视图名称列表,用逗号分隔
excluded-view-names:
#要运用于模板之上的模板模式。另见StandardTemplate-ModeHandlers(默认值:HTML5)
mode: HTML
#在构建URL时添加到视图名称前的前缀(默认值:classpath:/templates/)
prefix: classpath:/templates/
#在构建URL时添加到视图名称后的后缀(默认值:.html)
suffix: .html
#Thymeleaf模板解析器在解析器链中的顺序。默认情况下,它排第一位。顺序从1开始,只有在定义了额外的TemplateResolver Bean时才需要设置这个属性。
#template-resolver-order:
#可解析的视图名称列表,用逗号分隔
#view-names:
datasource:
platform: h2
type: com.mchange.v2.c3p0.ComboPooledDataSource
Expand Down Expand Up @@ -48,9 +72,9 @@ spring:
mvc:
servlet:
load-on-startup: 1
view:
prefix: /WEB-INF/views/
suffix: .jsp
#view:
# prefix: /WEB-INF/views/
# suffix: .jsp
session:
store-type: NONE
cache:
Expand Down
Loading

0 comments on commit e4fcb1d

Please sign in to comment.