标签:public logo 需要 tom lock 完成 null str manager
<!--配置openmanager--> <filter> <filter-name>openEntity</filter-name> <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>openEntity</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
在完成上面的配置后会报第二个错误
1 @ManyToOne(fetch = FetchType.LAZY) 2 @JoinColumn(name="department_id") 3 @JsonIgnoreProperties(value = {"hibernateLazyInitializer","handler","fieldHandler"}) 4 private Department department;
1 public class CustomMapper extends ObjectMapper { 2 public CustomMapper() { 3 this.setSerializationInclusion(JsonInclude.Include.NON_NULL); 4 // 设置 SerializationFeature.FAIL_ON_EMPTY_BEANS 为 false 5 this.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); 6 } 7 }
第二步:配置spring-mvc.xml
1 <!--注解支持--> 2 <mvc:annotation-driven> 3 <mvc:message-converters> 4 <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> 5 <property name="supportedMediaTypes"> 6 <list> 7 <value>application/json; charset=UTF-8</value> 8 <value>application/x-www-form-urlencoded; charset=UTF-8</value> 9 </list> 10 </property> 11 <!-- No serializer:配置 objectMapper 为我们自定义扩展后的 CustomMapper,解决了返回对象有关系对象的报错问题 --> 12 <property name="objectMapper"> 13 <bean class="com.logo.aisell.util.CustomMapper"></bean> 14 </property> 15 </bean> 16 </mvc:message-converters> 17 </mvc:annotation-driven>
标签:public logo 需要 tom lock 完成 null str manager
原文地址:https://www.cnblogs.com/logoman/p/11693268.html