Browse Source

merge changes

yingp 8 years ago
parent
commit
40f883bf0a

+ 13 - 18
pom.xml

@@ -9,7 +9,6 @@
         <groupId>com.uas.platform</groupId>
         <artifactId>platform</artifactId>
         <version>0.0.1-SNAPSHOT</version>
-        <relativePath>../platform</relativePath>
     </parent>
     <profiles>
         <profile>
@@ -30,9 +29,6 @@
                 <!-- static plugin -->
                 <static-path>static</static-path>
             </properties>
-            <activation>
-                <activeByDefault>true</activeByDefault>
-            </activation>
         </profile>
         <profile>
             <!-- 生产环境 -->
@@ -43,7 +39,9 @@
                 <static-path>http://static.ubtob.com</static-path>
             </properties>
             <!-- 默认 -->
-
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
         </profile>
     </profiles>
     <dependencies>
@@ -338,7 +336,7 @@
         </resources>
         <!-- 在maven生命周期validate阶段生成timestamp -->
         <plugins>
-            <!--<plugin>
+            <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>buildnumber-maven-plugin</artifactId>
                 <version>1.3</version>
@@ -351,12 +349,10 @@
                     </execution>
                 </executions>
                 <configuration>
-                    <configuration>
-                        <format>{0,date,yyyy-MM-dd HH:mm:ss}</format>
-                        <items>
-                            <item>timestamp</item>
-                        </items>
-                    </configuration>
+                    <format>{0,date,yyyy-MM-dd HH:mm:ss}</format>
+                    <items>
+                        <item>timestamp</item>
+                    </items>
                 </configuration>
             </plugin>
             <plugin>
@@ -371,7 +367,7 @@
                 <groupId>com.samaxes.maven</groupId>
                 <artifactId>minify-maven-plugin</artifactId>
                 <version>1.7.4</version>
-                &lt;!&ndash; 静态文件压缩  &ndash;&gt;
+                <!-- 静态文件压缩  -->
                 <executions>
                     <execution>
                         <id>default-minify</id>
@@ -432,7 +428,7 @@
                 <groupId>com.uas.plugins</groupId>
                 <artifactId>static-maven-plugin</artifactId>
                 <version>0.0.2-SNAPSHOT</version>
-                &lt;!&ndash; 静态资源分离  &ndash;&gt;
+                <!-- 静态资源分离  -->
                 <executions>
                     <execution>
                         <id>default-static</id>
@@ -450,7 +446,6 @@
                                 <sourceInclude>resources/tpl/**/*.html</sourceInclude>
                                 <sourceInclude>WEB-INF/views/**/*.html</sourceInclude>
                             </sourceIncludes>
-                            http://static.ubtob.com/css/index.css?_v=1450321871828
                             <versionSuffix>
                                 <suffix>?_v=${timestamp}</suffix>
                                 <exclude>*/require.js,*.min.js,*.min.css</exclude>
@@ -476,7 +471,7 @@
                         </resource>
                     </webResources>
                 </configuration>
-            </plugin>-->
+            </plugin>
             <plugin>
                 <groupId>org.apache.tomcat.maven</groupId>
                 <artifactId>tomcat7-maven-plugin</artifactId>
@@ -488,7 +483,7 @@
                 </configuration>
             </plugin>
         </plugins>
-        <!--<pluginManagement>
+        <pluginManagement>
             <plugins>
                 <plugin>
                     <groupId>org.eclipse.m2e</groupId>
@@ -523,7 +518,7 @@
                     </configuration>
                 </plugin>
             </plugins>
-        </pluginManagement>-->
+        </pluginManagement>
     </build>
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

+ 34 - 0
src/main/java/com/uas/platform/b2b/core/serializer/LazyPropertyFilter.java

@@ -0,0 +1,34 @@
+package com.uas.platform.b2b.core.serializer;
+
+import com.alibaba.fastjson.serializer.PropertyFilter;
+import org.hibernate.collection.spi.PersistentCollection;
+import org.hibernate.proxy.HibernateProxy;
+import org.hibernate.proxy.LazyInitializer;
+
+/**
+ * Created by Pro1 on 2017/11/13.
+ *
+ * JSON序列化时,过滤Hibernate代理对象或者延迟加载的对象FetchType.LAZY
+ */
+public class LazyPropertyFilter implements PropertyFilter{
+
+    @Override
+    public boolean apply(Object object, String name, Object value) {
+        if (value instanceof HibernateProxy) {//hibernate代理对象
+            LazyInitializer initializer = ((HibernateProxy) value).getHibernateLazyInitializer();
+            if (initializer.isUninitialized()) {
+                return false;
+            }
+        } else if (value instanceof PersistentCollection) {//实体关联集合一对多等
+            PersistentCollection collection = (PersistentCollection) value;
+            if (!collection.wasInitialized()) {
+                return false;
+            }
+            Object val = collection.getValue();
+            if (val == null) {
+                return false;
+            }
+        }
+        return true;
+    }
+}

+ 16 - 5
src/main/webapp/WEB-INF/spring/webmvc.xml

@@ -7,6 +7,21 @@
 	<!-- 开启@AspectJ AOP代理 -->
 	<aop:aspectj-autoproxy />
 
+	<bean id="lazyPropertyFilter" class="com.uas.platform.b2b.core.serializer.LazyPropertyFilter"></bean>
+
+	<bean id="fastJsonConfig" class="com.alibaba.fastjson.support.config.FastJsonConfig">
+		<property name="serializerFeatures">
+			<list>
+				<value>DisableCircularReferenceDetect</value>
+			</list>
+		</property>
+		<property name="serializeFilters">
+			<list>
+				<ref bean="lazyPropertyFilter"/>
+			</list>
+		</property>
+	</bean>
+
 	<mvc:annotation-driven>
 		<mvc:message-converters register-defaults="true">
 			<!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
@@ -17,11 +32,7 @@
 						<value>application/json;charset=UTF-8</value>
 					</list>
 				</property>
-				<property name="features">
-					<list>
-						<value>DisableCircularReferenceDetect</value>
-					</list>
-				</property>
+				<property name="fastJsonConfig" ref="fastJsonConfig" />
 			</bean>
 		</mvc:message-converters>
 	</mvc:annotation-driven>