Skip to content

@ReadingConverter is not work,and does R2DBC have the right way to implement one to many? #678

Closed
@wang-xiaowu

Description

@wang-xiaowu
  • AttrValueConverter
@ReadingConverter
public class AttrValueConverter implements Converter<Row, Attr> {
    @Override
    public Attr convert(Row source) {
        Attr attr = new Attr();
        attr.setAttrId(source.get("attrId",Long.class));
        attr.setShopId(source.get("shopId",Long.class));
        attr.setName(source.get("name",String.class));
        attr.setDesc(source.get("desc",String.class));
        attr.setSearchType(source.get("searchType",Integer.class));
        attr.setAttrType(source.get("attrType",Integer.class));
        attr.setCreateBy(source.get("createBy",String.class));
        attr.setUpdateBy(source.get("updateBy",String.class));
        attr.setCreateTime(source.get("createTime", LocalDateTime.class));
        attr.setUpdateTime(source.get("updateTime",LocalDateTime.class));
//        List<AttrValue> attrValues = source.get("attrValues", List.class);
//        for (AttrValue attrValue : attrValues) {
//        }
        AttrValue attrValue = new AttrValue();
        attrValue.setAttrValueId(source.get("attrValueId",Long.class));
        attrValue.setAttrId(source.get("attrId",Long.class));
        attrValue.setValue(source.get("value",String.class));
        attrValue.setCreateBy(source.get("String",String.class));
        attrValue.setUpdateBy(source.get("updateBy",String.class));
        attrValue.setCreateTime(source.get("createTime",LocalDateTime.class));
        attrValue.setUpdateTime(source.get("updateTime",LocalDateTime.class));
        attr.setAttrValues(attrValue);
        return attr;
    }
}
  • config
@Configuration
@RequiredArgsConstructor
public class MyAppConfig extends AbstractR2dbcConfiguration {

  private final ConnectionFactory connectionFactory;

  @Override
  public ConnectionFactory connectionFactory() {
    return connectionFactory;
  }

  @Override
  @Bean
  public R2dbcCustomConversions r2dbcCustomConversions() {
    List<Converter<?, ?>> converterList = new ArrayList<Converter<?, ?>>();
    converterList.add(new AttrValueConverter());
    return new R2dbcCustomConversions(getStoreConversions(), converterList);
  }
}
  • Attr
@Data
@EqualsAndHashCode(callSuper = true)
@Table
public class Attr extends BaseEntity implements Serializable{
    private static final long serialVersionUID = 1L;

	/**
     * attr id
     */
    private Long attrId;

    private AttrValue attrValues;
...

  • AttrValue
@Data
@EqualsAndHashCode(callSuper = true)
@Table
public class AttrValue extends BaseEntity implements Serializable{
    private static final long serialVersionUID = 1L;
   ...
}
  • AttrRepository
public interface AttrRepository extends R2dbcRepository<Attr, Long> {

    @Query("select a.*,av.* from attr a join attr_value av on a.attr_id = av.attr_id")
    Flux<Attr> findAttrAndValues();
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions