对于JSON类型的字段,如果SQL XML中的接收对象中没有定义
@TableField(typeHandler = JacksonTypeHandler.class)
package com.cityos.civilization.city.config; import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.type.TypeHandlerRegistry; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; import java.util.List; import java.util.Map; /** * 对于List和Map类型,使用JacksonTypeHandler来处理,主要用来解决json类型的字段 */ @Component public class CustomTypeHandlerParser implements ApplicationContextAware { @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { //从spring容器获取sqlSessionFactory SqlSessionFactory sqlSessionFactory = applicationContext.getBean(SqlSessionFactory.class); //获取typeHandler注册器 TypeHandlerRegistry typeHandlerRegistry = sqlSessionFactory.getConfiguration().getTypeHandlerRegistry(); //注册List的typeHandler typeHandlerRegistry.register(List.class, JacksonTypeHandler.class); typeHandlerRegistry.register(Map.class, JacksonTypeHandler.class); } }