Просмотр исходного кода

zheng-demo增加thymeleaf视图,并增加调用远程zheng-ui静态资源作为视图,实动静分离分离

shuzheng 9 лет назад
Родитель
Сommit
4a52900bec

+ 1 - 1
zheng-demo/src/main/java/com/zheng/demo/controller/IndexController.java

@@ -50,7 +50,7 @@ public class IndexController extends BaseController {
 		user.setName("lisi");
 		user.setName("lisi");
 		users.add(user);
 		users.add(user);
 		model.addAttribute("users", users);
 		model.addAttribute("users", users);
-		return "/index";
+		return "/zheng-demo/index";
 	}
 	}
 
 
 }
 }

+ 2 - 1
zheng-demo/src/main/resources/config.properties

@@ -1,2 +1,3 @@
 env=${profile.env}
 env=${profile.env}
-zheng-ui.version=${zheng-ui.version}
+zheng-ui.version=${zheng-ui.version}
+zheng-ui.path=${zheng-ui.path}

+ 2 - 1
zheng-demo/src/main/resources/profiles/dev.properties

@@ -1,2 +1,3 @@
 profile.env=dev
 profile.env=dev
-zheng-ui.version=1.0.0
+zheng-ui.version=1.0.0
+zheng-ui.path=http://ui.zhangshuzheng.cn:1000/

+ 2 - 1
zheng-demo/src/main/resources/profiles/pre.properties

@@ -1,2 +1,3 @@
 profile.env=pre
 profile.env=pre
-zheng-ui.version=1.0.0
+zheng-ui.version=1.0.0
+zheng-ui.path=http://ui.zhangshuzheng.cn:1000/

+ 2 - 1
zheng-demo/src/main/resources/profiles/prod.properties

@@ -1,2 +1,3 @@
 profile.env=prod
 profile.env=prod
-zheng-ui.version=1.0.0
+zheng-ui.version=1.0.0
+zheng-ui.path=http://ui.zhangshuzheng.cn:1000/

+ 2 - 1
zheng-demo/src/main/resources/profiles/test.properties

@@ -1,2 +1,3 @@
 profile.env=test
 profile.env=test
-zheng-ui.version=1.0.0
+zheng-ui.version=1.0.0
+zheng-ui.path=http://ui.zhangshuzheng.cn:1000/

+ 20 - 1
zheng-demo/src/main/resources/springMVC-servlet.xml

@@ -1,7 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
 <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        xsi:schemaLocation="http://www.springframework.org/schema/beans
-        http://www.springframework.org/schema/beans/spring-beans.xsd">
+        http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
+
+    <context:property-placeholder location="classpath:config.properties"/>
+
+    <!-- 使用thymeleaf视图 -->
+    <bean id="templateResolver" class="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver">
+        <property name="order" value="0"/>
+        <property name="prefix" value="${zheng-ui.path}"/>
+        <property name="suffix" value=".html"/>
+        <property name="templateMode" value="HTML"/>
+        <property name="cacheable" value="false"/>
+    </bean>
+    <bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
+        <property name="templateResolver" ref="templateResolver"/>
+        <property name="enableSpringELCompiler" value="true"/>
+    </bean>
+    <bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
+        <property name="templateEngine" ref="templateEngine"/>
+    </bean>
 
 
 </beans>
 </beans>

+ 17 - 0
zheng-ui/src/zheng-demo/index.html

@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html xmlns:th="http://www.thymeleaf.org"
+      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
+<head>
+    <meta charset="UTF-8"/>
+    <title></title>
+</head>
+<body>
+<h1 th:text="${host}">Hello World</h1>
+<ul  th:each="user : ${users}">
+    <li th:text="${user.id}">1</li>
+    <li th:text="${user.age}">2</li>
+    <li th:text="${user.name}">3</li>
+</ul>
+<img src="http://ui.zhangshuzheng.cn:1000/images/avatar.jpg"/>
+</body>
+</html>