提交 8c97eaa9 编写于 作者: ibizdev's avatar ibizdev

ibizdev提交

上级 de68b5be
......@@ -97,7 +97,7 @@ public class IBZDict extends EntityMP implements Serializable {
*/
@JSONField(name = "items")
@JsonProperty("items")
@TableField(value = "cfg" , typeHandler = com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class)
@TableField(value = "cfg" , typeHandler = cn.ibizlab.core.dict.domain.handlers.IBZDictItemTypeHandler.class)
private List<cn.ibizlab.core.dict.domain.IBZDictItem> items;
/**
......
package cn.ibizlab.core.dict.domain.handlers;
import cn.ibizlab.core.dict.domain.IBZDictItem;
import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@MappedTypes({List.class})
@MappedJdbcTypes(JdbcType.VARCHAR)
public class IBZDictItemTypeHandler extends AbstractJsonTypeHandler<List>
{
private static ObjectMapper objectMapper = new ObjectMapper();
private JavaType type;
public IBZDictItemTypeHandler(Class<List> type) {
this.type = objectMapper.getTypeFactory().constructParametricType(ArrayList.class, IBZDictItem.class);
}
@Override
protected List parse(String json) {
try {
return objectMapper.readValue(json, type);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
protected String toJson(List obj) {
try {
return objectMapper.writeValueAsString(obj);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
public static void setObjectMapper(ObjectMapper objectMapper) {
IBZDictItemTypeHandler.objectMapper = objectMapper;
}
}
......@@ -13,8 +13,7 @@
<id property="dictid" column="ibzdictid" /><!--主键字段映射-->
<result property="dictname" column="ibzdictname" />
<result property="items" column="cfg" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" />
<!--通过mybatis自动注入关系属性[关系实体],fetchType="lazy"为懒加载配置 -->
<result property="items" column="cfg" typeHandler="cn.ibizlab.core.dict.domain.handlers.IBZDictItemTypeHandler" />
</resultMap>
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册