本文主要是介绍SSM框架下Java 8 date/time type `java.time.LocalDateTime` not supported by default,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Java 8 date/time type java.time.LocalDateTime
not supported by default: add Module “com.fasterxml.jackson.datatype:jackson-datatype-jsr310”
解决方案:
<dependency><groupId>com.fasterxml.jackson.datatype</groupId><artifactId>jackson-datatype-jsr310</artifactId><version>2.13.0</version> <!-- 按需调整版本 -->
</dependency>
注入如下配置类(如何注入?直接放到controller、dao、service包即可,会 自动注入spring容器即可)
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class JacksonConfig {@Beanpublic ObjectMapper objectMapper() {ObjectMapper mapper = new ObjectMapper();mapper.registerModule(new JavaTimeModule()); // 注册JSR 310模块return mapper;}
}
这篇关于SSM框架下Java 8 date/time type `java.time.LocalDateTime` not supported by default的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!