我正在使用Spring Data JPA。我有一个....
import { SpeechToText } from 'react-native-watson';
type Props = {};
export default class App extends Component<Props> {
componentWillMount(){
SpeechToText.initialize("username", "password");
}
watsonTest(){
SpeechToText.startStreaming((error,text)=>{
console.log(text);
console.log(error);
})
}
render() {
return (
<View style={styles.container}>
<TouchableOpacity onPress={this.watsonTest()}>
<Text>Start Recording</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
.....
});
实体和一个Recipe
枚举,其属性分别为Difficulty
,EASY
,MEDIUM
。
我的HARD
类由Recipe
组成,如下所示:
Difficulty
我的代码可以按预期工作,并且我能够轻松保存食谱。
我的问题从这里开始。如果我想向一个数据库列添加多个枚举怎么办?例如,所以我希望食谱可以说出其中两个困难。
答案 0 :(得分:1)
使用自定义AttributeConverter
:
@Convert(converter = DifficultiesConverter::class)
private List<Difficulty> difficulties;
import javax.persistence.AttributeConverter
@Converter(autoApply = true)
public class DifficultiesConverter implements AttributeConverter<List<Difficulty>, String> {
public String convertToDatabaseColumn(List<Difficulty> attribute) {
// convert List to String, such as [EASY, MEDIUM, ...] to "EASY,MEDIUM,..."
return ...
}
public List<Difficulty> convertToEntityAttribute(String dbData) {
// convert String to List, such as "EASY,MEDIUM,..." to [EASY, MEDIUM, ...]
return ...
}
}