我的Spring启动API通过mongoDB的appCode获取所有门户帐户的列表,其中某些字段返回null
(数据库中存在数据),
如何获取null
的数据?
这是我的数据库集合的一部分
{"_id":"5d927f14c61810332425ee7f","portalAccount":{"_id":"5d927f13c61810332425ee7d","name":"Codelab2","dateCreated":"2019-09-30T22:17:55.929Z","code":"CL-ACCT- 2","status":"ACTIVE","accountType":"CODELAB"},"portalUser":{"_id":"5d927f14c61810332425ee7e","username":"iyke","password":"$2a$10$29j8SONBRdqGtYUtonJ9bulmdiPhUiyB5kj9sZHK.zICnXkh3YlA6","lastName":"Ezugworie","firstName":"Ikechukwu","email":"i.ezugworie@gmail.com","resetPassword":true,"failedLoginAttemptsSinceLastSuccessful":"0","locked":false,"dateCreated":"2019-09-30T22:17:55.933Z"},"status":"ACTIVE","role":{"_id":"5d8f7a58c6181021c820afc9","name":"ADMIN","status":"ACTIVE","permissions":[{"name":"CREATE_APP","status":"ACTIVE"}]},"app":{"_id":"5d8f7a57c6181021c820afc8","name":"Codelab Account","code":"CL-001","description":"Account App for Codelab","status":"ACTIVE","apiKeys":[{"key":"2FCUSKSHFU===sfsh13Xa","status":"ACTIVE"}]},"_class":"com.codelab.accounts.domain.entity.account.Membership"}
{"_id":"5d927f3bc61810332425ee82","portalAccount":{"_id":"5d927f3ac61810332425ee80","name":"Codelab2","dateCreated":"2019-09-30T22:18:34.895Z","code":"CL-ACCT- 3","status":"ACTIVE","accountType":"CODELAB"},"portalUser":{"_id":"5d927f3bc61810332425ee81","username":"bille","password":"$2a$10$.ERPBlkPF6rPHs1aAV9rpeNodqb83T2M1eI/mweW4zrD9xYDF3NpC","lastName":"Bille","firstName":"Ibinabo","email":"ibille@gmail.com","resetPassword":true,"failedLoginAttemptsSinceLastSuccessful":"0","locked":false,"dateCreated":"2019-09-30T22:18:34.915Z"},"status":"ACTIVE","role":{"_id":"5d8f7a58c6181021c820afc9","name":"ADMIN","status":"ACTIVE","permissions":[{"name":"CREATE_APP","status":"ACTIVE"}]},"app":{"_id":"5d8f7a57c6181021c820afc8","name":"Codelab Account","code":"CL-001","description":"Account App for Codelab","status":"ACTIVE","apiKeys":[{"key":"2FCUSKSHFU===sfsh13Xa","status":"ACTIVE"}]},"_class":"com.codelab.accounts.domain.entity.account.Membership"}
这是我的控制人
public ResponseEntity<?> accounts(@RequestHeader("X-APP-CODE") String appCode,
@RequestParam("limit") int limit,
@RequestParam("offset") int offset) {
List<PortalAccountDto> portalAccount = accountService.getAllPortalAccount(appCode, limit, offset);
if ( portalAccount.isEmpty()){
throw new NotFoundException("Portal Account with app code "+appCode+ " not found" );
}
return ResponseEntity.ok(portalAccount);
}
这是我的服务
List<PortalAccountDto>
getAllPortalAccount(String appCode, int limit, int offset);
我的服务实现
@Override
public List<PortalAccountDto> getAllPortalAccount(String appCode,
int limit,
int offset) {
QPortalAccount qPortalAccount = new QPortalAccount(QPortalAccount.portalAccount);
QMembership qMembership = new QMembership(QMembership.membership);
Predicate predicate = qMembership.app.code.endsWithIgnoreCase(appCode.trim());
logger.debug("Get all Portal Accounts with limit {} and offset {}", limit, offset);
Pageable pageable = new OffsetBasedPageRequest(limit, offset);
return membershipRepository.findByAppCode(appCode, pageable);
}
还有存储库
public interface MembershipRepository extends MongoRepository<Membership, String>, QuerydslPredicateExecutor<Membership>{
List<PortalAccountDto> findByAppCode(String appCode, Pageable pageable);
}
预期结果是
[
{
"id": "5d927f13c61810332425ee7d",
"name": "Codelab2",
"dateCreated": "2019-09-30T22:17:55.929Z",
"code": "CL-ACCT- 2",
"status": "ACTIVE",
"accountType": "CODELAB"
},
{
"id": "5d927f3ac61810332425ee80",
"name": Codelab2,
"dateCreated": "2019-09-30T22:18:34.895Z",
"code": "CL-ACCT- 3",
"status": "ACTIVE",
"accountType": "CODELAB"
}
]
但是实际结果是
[
{
"id": "5d927fe0c61810332425ef03",
"name": null,
"dateCreated": null,
"code": null,
"status": "ACTIVE",
"accountType": null
},
{
"id": "5d927fe0c61810332425ef00",
"name": null,
"dateCreated": null,
"code": null,
"status": "ACTIVE",
"accountType": null
}
]