[英]Why isn't REST accessing existing entries in MongoDB?
我在 MongoDB 中有一個示例條目。 我按照此處找到的教程使用 Spring: https : //spring.io/guides/gs/accessing-mongodb-data-rest/
一切正常,但無論出於何種原因,它都無法識別數據庫中的該條目。
播放器類
package com.company.botmiteserver;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
public class Player {
@Id
public ObjectId _id;
public String email;
public String account_name;
public String password;
public String pin;
public String status;
public String type;
public boolean active;
public Player () { }
public Player(ObjectId _id, String email, String account_name, String password, String pin, String status, String type, Boolean active) {
this._id = _id;
this.email = email;
this.account_name = account_name;
this.password = password;
this.pin = pin;
this.status = status;
this.type = type;
this.active = active;
}
public String get_id() { return _id.toHexString(); }
public void set_id(ObjectId _id) { this._id = _id; }
public String getEmail() {
return email;
}
public String getAccountName() {
return account_name;
}
public String getPassword() {
return password;
}
public String getPin() {
return pin;
}
public String getStatus() {
return status;
}
public String getType() {
return type;
}
public String setType(String type) {
return this.type = type;
}
public Boolean getActive() {
return active;
}
public Boolean setActive(Boolean active) {
return this.active = active;
}
}
PlayerRepository.class
package com.company.botmiteserver;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import java.util.List;
@RepositoryRestResource(collectionResourceRel = "player", path = "player")
public interface PlayerRepository extends MongoRepository<Player, String> {
Player findBy_id(ObjectId _id);
// public Player findByEmail(String email);
// public List<Player> findByType(@Param("type") String account_name);
}
PlayerController.class
package com.company.botmiteserver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/player")
public class PlayerController {
@Autowired
private PlayerRepository repository;
}
結果:
{
"_embedded" : {
"player" : [ ]
},
"_links" : {
"self" : {
"href" : "http://localhost:8080/player"
},
"profile" : {
"href" : "http://localhost:8080/profile/player"
},
"search" : {
"href" : "http://localhost:8080/player/search"
}
},
"page" : {
"size" : 20,
"totalElements" : 0,
"totalPages" : 0,
"number" : 0
}
}
太明顯了。 我需要在spring.data.mongodb.database
中配置spring.data.mongodb.database
即spring.data.mongodb.database = foo
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.