我有一个Java类,其中@Document对象来自elasticsearch包
import org.springframework.data.elasticsearch.annotations.Document;
@Data
@AllArgsConstructor
@Document(indexName = "user_data_index", type = "user_data")
public class User {
@Id
private String id;
private String name;
public User() {};
}
我想对Spring Data Mongo使用相同的对象。
示例:-
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
@Data
@AllArgsConstructor
//@Document(indexName = "user_data_index", type = "user_data")
@Document(collection="user")
public class User {
@Id
private String id;
private String name;
public User() {};
}
这是为了使我可以在数据摄取期间将数据同时发送到mongo和elasticsearch。我怎样才能做到这一点?
答案 0 :(得分:0)
您至少需要对struct ContentView: View {
var itemIds: [String]
var body: some View {
VStack {
ForEach(self.itemIds, id: \.self) { itemId in
ItemView(itemId: itemId)
}
}
}
}
struct ItemView: View {
var itemId: String
@State var seconds: Int
@State var timerPublisher = Timer.publish(every: 1, tolerance: 0.5, on: .main, in: .common).autoconnect()
var body: some View {
VStack {
Button("StartTimer") {
// Call startTimer in SingletonTimerManager....
self.timerPublisher = SingletonTimerManager.publishers[itemId]!
self.timerPublisher.connect()
}
Button("StopTimer") {
self.timerPublisher.connect().cancel()
// Call stopTimer in SingletonTimerManager....
}
Text("\(self.seconds)")
.onAppear {
// function that checks if the timer with this itemId is running
if(SingletonTimerManager.isTimerValid(itemId)) {
self.timerPublisher = SingletonTimerManager.publishers[itemId]!
self.timerPublisher.connect()
}
}.onReceive($timerPublisher) { _ in
self.seconds = SingletonTimerManager.secondsPassed[itemId] ?? 0
}
}
}
}
注释之一使用完整的合格路径:
@Document