添加兜底的JsonObject数据类型处理
This commit is contained in:
parent
fac5f16155
commit
7b938909ed
@ -1,7 +1,15 @@
|
|||||||
package cn.axzo.msg.center.notices.client.config;
|
package cn.axzo.msg.center.notices.client.config;
|
||||||
|
|
||||||
|
import cn.axzo.msg.center.domain.utils.IgnorePropsJsonTypeHandler;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
|
import org.apache.ibatis.type.TypeHandlerRegistry;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mybatis Plus Config
|
* Mybatis Plus Config
|
||||||
@ -18,4 +26,20 @@ public class MybatisPlusConfig {
|
|||||||
return new EntityMetaObjectHandler();
|
return new EntityMetaObjectHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public static class JsonObjectTypeHandlerRegister implements BeanPostProcessor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object postProcessAfterInitialization(@NotNull Object bean, @NotNull String beanName) throws BeansException {
|
||||||
|
if (!(bean instanceof SqlSessionFactory))
|
||||||
|
return bean;
|
||||||
|
org.apache.ibatis.session.Configuration configuration = ((SqlSessionFactory) bean).getConfiguration();
|
||||||
|
TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry();
|
||||||
|
if(!typeHandlerRegistry.hasTypeHandler(JSONObject.class)) {
|
||||||
|
typeHandlerRegistry.register(JSONObject.class, IgnorePropsJsonTypeHandler.class);
|
||||||
|
}
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
package cn.axzo.msg.center.dal;
|
||||||
|
|
||||||
|
import cn.axzo.msg.center.MsgCenterApplication;
|
||||||
|
import cn.axzo.msg.center.domain.entity.TodoBusiness;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.annotation.Commit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yanglin
|
||||||
|
*/
|
||||||
|
@SpringBootTest(classes = MsgCenterApplication.class)
|
||||||
|
@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
||||||
|
class TodoBusinessDaoTest {
|
||||||
|
|
||||||
|
private final TodoBusinessDao todoBusinessDao;
|
||||||
|
|
||||||
|
@Test @Commit
|
||||||
|
void foo() {
|
||||||
|
JSONObject bizExtParam = JSON.parseObject("{\"taskName\": \"万科1号楼 20层 2单元\"}");
|
||||||
|
bizExtParam.put("1", "1");
|
||||||
|
bizExtParam.put("2", "1");
|
||||||
|
todoBusinessDao.lambdaUpdate()
|
||||||
|
.eq(TodoBusiness::getId, 110944L)
|
||||||
|
.set(TodoBusiness::getBizExtParam, bizExtParam)
|
||||||
|
.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user