Mat*_*att 5 java enums cassandra spring-data
我正在尝试使用Springdata框架将枚举存储到Cassandra中.这可能吗?我已经定义了我的枚举:
public enum Currency {
GBP,
USD,
EUR
}
Run Code Online (Sandbox Code Playgroud)
然后我在字段上使用"@Enumerated"注释定义我的类:
@Table
public class BondStatic {
@PrimaryKey
private String id;
private String isin;
private String ticker;
private Date maturity;
private Double coupon;
@Enumerated(EnumType.STRING)
private Currency currency;
...
}
Run Code Online (Sandbox Code Playgroud)
这些是我的进口:
import com.datastax.driver.mapping.EnumType;
import com.datastax.driver.mapping.annotations.Enumerated;
Run Code Online (Sandbox Code Playgroud)
然后我有Spring的Component类:
@Component
class CassandraDataCLR implements CommandLineRunner {
@Autowired
public BondStaticCassandraRepository bondStaticRepository;
...
}
Run Code Online (Sandbox Code Playgroud)
哪个是自动装配的:
@RepositoryRestResource(path = "/bond-static")
interface BondStaticCassandraRepository extends CassandraRepository<BondStatic> { }
Run Code Online (Sandbox Code Playgroud)
这些是我的进口:
import org.springframework.data.cassandra.repository.CassandraRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
Run Code Online (Sandbox Code Playgroud)
但是当我尝试运行以下内容时:
bondStaticRepository.save(bondStatics);
Run Code Online (Sandbox Code Playgroud)
我明白了:
public enum Currency {
GBP,
USD,
EUR
}
Run Code Online (Sandbox Code Playgroud)
有什么建议?简单的解决方案是将我的字段设置为String并在getter和setter中使用枚举,但是如果我可以让它工作,那么看起来有一个带注释的枚举是一个更清晰的解决方案.
| 归档时间: |
|
| 查看次数: |
2063 次 |
| 最近记录: |