为什么实体无法映射列 table?

why the entity can't map the columns table?

我有一个 mysql table “国家”如下

| id | name | name2 | code | area | currency | language | population |
----------------------------------------------------------------------
| .. | ..   |   ... |   ...|  ....|  ...     |   ...    |   ...      |

这个实体“customCountry”:

@Entity
@Table(name="countries")
public class customCountry {
    @Id
    @Column(name = "id",table ="countries")
     private Long id;

    @Column(name = "code",table ="countries")
     private Long code;

    @Column(name = "language",table ="countries")
     private String language;

   //constructors + getters/setters
}

我有这个存储库:

@Repository
public interface customCountryRepository extends JpaRepository<customCountry,Long>{

    
    List<customCountry> findAll();
}

和此服务 class :

@Service
@ComponentScan(basePackages="repository")
public class countriesService {

    @Autowired
    customCountryRepository customcountry_repo;
    
    public List<customCountry> loadcustomcountries()
    {
        List<customCountry> validcustomcountries = customcountry_repo.findAll();
        System.out.println("size: "+validcustomcountries.size());
        return validcustomcountries;
    }
}

问题是当我在我的控制器中调用此服务方法时,我发现大小 = 0,但我不明白为什么,我认为我很好地管理了属性和列之间的映射。 谢谢

您可以从存储库 class.

中删除 List<customCountry> findAll();

因为你已经扩展了JpaRepository<customCountry,Long>,它有这个方法。

因为您在存储库中提供了该方法而不是实现它。 这导致了一个问题。

只需删除它即可。