为了账号安全,请及时绑定邮箱和手机立即绑定

该字段的问题是其类型是另一个类

该字段的问题是其类型是另一个类

炎炎设计 2022-05-21 14:10:35
我创建了一个转换为另一个类的字段,通过它我得到了json,问题发生在哪里,但我不明白我做错了什么User班级public class User extends BaseEntity<Integer> {  private String firstName;  private String lastName;  @Column(name = "username")  private String username;  @Convert(converter = PurshasedProductConverter.class)  private PurshasedProductConverter purshasedProducts;}PurshasedProductConverter班级public class PurshasedProductConverter implements AttributeConverter<PurshasedProduct, String> {  private static final Logger LOG = (Logger) LoggerFactory.getLogger(PurshasedProductConverter.class);  private final ObjectMapper mapper = new ObjectMapper();  @Override  public String convertToDatabaseColumn(PurshasedProduct attribute) {    try {        if (attribute != null)            return mapper.writeValueAsString(attribute);        else        return null;    } catch (JsonProcessingException e) {        LOG.error(e.getMessage(), e);        throw new RuntimeException(e);    }  }  @Override  public PurshasedProduct convertToEntityAttribute(String dbData) {    TypeReference<HashMap<String, String>> typeRef            = new TypeReference<HashMap<String, String>>() {    };    try {        PurshasedProduct purshasedProduct = new PurshasedProduct();        if (dbData != null)            purshasedProduct.strings = mapper.readValue(dbData, typeRef);        return purshasedProduct;    } catch (IOException e) {        LOG.error(e.getMessage(), e);        throw new RuntimeException(e);    }  }}PurshasedProduct班级public class PurshasedProduct {  public Map<String, String> strings = new HashMap<>();  public static PurshasedProduct create(String key, String value) {    PurshasedProduct purshasedProduct = new PurshasedProduct();    purshasedProduct.set(key, value);    return purshasedProduct;  }  public void set(String lang, String text) {    if (text == null || lang == null) {        return;    }    strings.put(lang, text);  }
查看完整描述

1 回答

?
慕桂英546537

TA贡献1848条经验 获得超10个赞

看一看:


@Convert(converter = PurshasedProductConverter.class)

private PurshasedProductConverter purshasedProducts;

您也用于PurshasedProductConverter注释和字段类型。您应该将其更改为要从/转换为 in 的字段类型PurshasedProductConverter。


@Convert(converter = PurshasedProductConverter.class)

private PurshasedProduct purshasedProducts;


查看完整回答
反对 回复 2022-05-21
  • 1 回答
  • 0 关注
  • 105 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号