Есть ли метод findBy, который я могу использовать, чтобы он возвращал список всех строк, где один из элементов массива равен переданному параметру.
Я имею в виду что-то вроде:
Код: Выделить всё
List childrenAccountsList = Arrays.asList("A","B","C");
List retList = findBy_{whatGoesHere} (String childValue);
List retList = findBy_{whatGoesHere} ("A");
Вот определения моих классов
UserREF.java
Код: Выделить всё
package test;
import com.microsoft.azure.spring.data.documentdb.core.mapping.Document;
import com.microsoft.azure.spring.data.documentdb.core.mapping.PartitionKey;
import org.springframework.data.annotation.Id;
import java.util.List;
@Document(collection = "user-management")
public class UserREF{
@Id
private String id;
private String userId;
private String role;
private String primaryAccountId;
@PartitionKey
private String partition;
private String shipTo;
// @ElementCollection
private List childShipToAccounts;
public String getUserId(){
return userId;
}
public void setUserId(String userId){
this.userId = userId;
}
public String getRole(){
return role;
}
public void setRole(String role){
this.role = role;
}
public String getPrimaryAccountId(){
return primaryAccountId;
}
public void setPrimaryAccountId(String primaryAccountId) {
this.partition = primaryAccountId;
this.primaryAccountId = primaryAccountId;
}
public String getPartition() {
this.partition = this.primaryAccountId;
return this.partition;
}
public void setPartition(String partition) {
this.partition = this.primaryAccountId;
}
public String getShipTo(){
return shipTo;
}
public void setShipTo(String shipTo){
this.shipTo = shipTo;
}
public List getChildShipToAccounts(){
return childShipToAccounts;
}
public void setChildShipToAccounts(List shipToAccounts){
for (ShipToAccounts shipToAccount : shipToAccounts) {
shipToAccount.setPrimaryAccountId(this.primaryAccountId);
}
this.childShipToAccounts = shipToAccounts;
}
public String getId(){
return id;
}
public void setId(String id){
this.id = id;
}
}
Код: Выделить всё
package test;
public class ShipToAccounts{
private String primaryAccountId;
private String accountId;
public String getPrimaryAccountId() {
return primaryAccountId;
}
public void setPrimaryAccountId(String primaryAccountId) {
this.primaryAccountId = primaryAccountId;
}
public String getAccountId(){
return accountId;
}
public void setAccountId(String input){
this.accountId = input;
}
}
Код: Выделить всё
package test;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import com.microsoft.azure.spring.data.documentdb.core.DocumentDbOperations;
import com.microsoft.azure.spring.data.documentdb.repository.DocumentDbRepository;
import java.util.List;
@Repository
@ConditionalOnBean(DocumentDbOperations.class)
public interface UserREFRepository extends DocumentDbRepository {
@Override
@Cacheable("test_users")
UserREF findOne(String id, String partitionKeyValue);
List findByRole(String role);
List findByChildShipToAccounts_PrimaryAccountId (@Param("primaryAccountId") String primaryAccountId);
List findAllByChildShipToAccounts_PrimaryAccountId(String s);
}
Код: Выделить всё
package test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
@Service
public class UserRefService {
private static final Logger log = LoggerFactory.getLogger(UserRefService.class);
@Autowired
private UserREFRepository userREFRepository;
public UserREF save(UserREF inUser) {
List adminUsersList = userREFRepository.findAllByChildShipToAccounts_PrimaryAccountId("123456");
System.out.println("users " + adminUsersList);
UserREF newUser = userREFRepository.save(inUser);
return newUser;
}
}
Код: Выделить всё
{
"role": "admin",
"partition": "123456",
"primaryAccountId": "123456",
"childShipToAccounts": [
{
"accountId": "1111",
"primaryAccountId": "123456"
},
{
"accountId": "2222",
"primaryAccountId": "123456"
},
{
"accountId": "3333",
"primaryAccountId": "123456"
}
],
"id": "1b6d8497-1aca-4cab-9e3d-f8be3ba4f71c",
"userId": "22",
"shipTo": "2222"
}
Код: Выделить всё
java.lang.IllegalStateException: com.microsoft.azure.documentdb.DocumentClientException:
Message: {"Errors":["Invalid query. Specified parameter name '@childShipToAccounts.primaryAccountId' is invalid.
Parameter names should be in the format of symbol '@' followed by a valid identifier. E.g. @param1"]}
ActivityId: fd188aac-f99c-4983-b442-713c529dc930, Microsoft.Azure.Documents.Common/2.1.0.0, StatusCode: BadRequest
Спасибо
Подробнее здесь: https://stackoverflow.com/questions/546 ... repository
Мобильная версия