目前我是响应式编程的新手,我已经在 2 个文档中添加了数据,所以目前我要做的是只将那些数据返回给两个文档中 tokenIdentifier 相同的客户端。
请参考以下代码:
我有 2 个收藏
package com.mainApp;
import java.util.Date;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
@Document(value = "Token")
public class TokenData {
@Id
private String id;
private String tokenIdentifier;
private Date todayDate;
public TokenData(String id, String tokenIdentifier, Date todayDate) {
super();
this.id = id;
this.tokenIdentifier = tokenIdentifier;
this.todayDate = todayDate;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTokenIdentifier() {
return tokenIdentifier;
}
public void setTokenIdentifier(String tokenIdentifier) {
this.tokenIdentifier = tokenIdentifier;
}
public Date getTodayDate() {
return todayDate;
}
public void setTodayDate(Date todayDate) {
this.todayDate = todayDate;
}
}
package com.mainApp;
import java.util.Date;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
@Document(value = "TURCollection")
public class TURCollection {
@Id
private String id;
private String turIdentifier;
private String tokenIdentifier;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTurIdentifier() {
return turIdentifier;
}
public void setTurIdentifier(String turIdentifier) {
this.turIdentifier = turIdentifier;
}
public String getTokenIdentifier() {
return tokenIdentifier;
}
public void setTokenIdentifier(String tokenIdentifier) {
this.tokenIdentifier = tokenIdentifier;
}
}
我有一个控制器,它将只返回 tokenData.getTokenIdentifier() == TURCollection.getTokenIdentifier() 的那些 tokenData。
所以
@GetMapping(value = "/getAllToken")
public Flux<TokenData> getToken(){
/*List<TokenData> returnData = new ArrayList<TokenData>();
List<TokenData> tokenData = tokenDataRepository.findAll().collectList().block();
List<TURCollection> turCollection = turRepository.findAll().collectList().block();
turCollection.forEach(tur -> {
for(TokenData data : tokenData) {
if(tur.getTokenIdentifier().equals(data.getTokenIdentifier())) {
returnData.add(data);
}
}
});*/
但是 block() 代码在反应式编程中不起作用任何人都可以帮助我如何以反应方式比较两个通量的值吗?