我使用springboot和hibernamte5.0.x。有用!
1. pom.xml
<dependency> <groupId>com.fasterxml.jackson.datatype</groupId> <artifactId>jackson-datatype-hibernate5</artifactId> <version>2.8.4</version></dependency>
2. Webconfig
@Configurationpublic class WebConfig implements WebMvcConfigurer { public void extendMessageConverters(List<HttpMessageConverter<?>> converters) { for (HttpMessageConverter converter : converters) { if (converter instanceof org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) { ObjectMapper mapper = ((MappingJackson2HttpMessageConverter) converter).getObjectMapper(); mapper.registerModule(new Hibernate5Module()); // replace Hibernate4Module() with the proper class for your hibernate version. } } }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)