Java 如何在SpringBoot上创建定制的findBy?

Java 如何在SpringBoot上创建定制的findBy?,java,spring-boot,Java,Spring Boot,我是一名新的SpringBoot开发人员。我希望在我的respository类中使用findByCountry,而不是SpringBoot上的常规findById: CentralBankRepository: @Repository public interface CentralBankRepository extends MongoRepository<CentralBank, String> { Optional<CentralBank> findByCountr

我是一名新的SpringBoot开发人员。我希望在我的respository类中使用findByCountry,而不是SpringBoot上的常规findById:

CentralBankRepository:

@Repository
public interface CentralBankRepository extends MongoRepository<CentralBank, String> {
Optional<CentralBank> findByCountry(String country);
当我去http://localhost:8080/Canada,消息错误为:

The character encoding of the plain text document was not declared.
The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range.
The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature.
虽然我希望收到这封信:

    {
    "Country": "Canada",
    "GDP": 1740,
    "GDP YoY": "-0.90%",
    "GDP QoQ": "-2.10%",
    "Interest rate": "0.25%",
    "Inflation rate": "-0.40%",
    "Jobless rate": "13.70%",
    "Gov. Budget": "-0.70%",
    "Debt/GDP": "89.70%",
    "Current Account": -2.1,
    "Population": 37.78
}

这似乎是一个编码错误

你试过这个吗

@GetMapping(value = "/{country}", produces = MediaType.APPLICATION_JSON_VALUE)
    {
    "Country": "Canada",
    "GDP": 1740,
    "GDP YoY": "-0.90%",
    "GDP QoQ": "-2.10%",
    "Interest rate": "0.25%",
    "Inflation rate": "-0.40%",
    "Jobless rate": "13.70%",
    "Gov. Budget": "-0.70%",
    "Debt/GDP": "89.70%",
    "Current Account": -2.1,
    "Population": 37.78
}
@GetMapping(value = "/{country}", produces = MediaType.APPLICATION_JSON_VALUE)