yuehoiwai 2019-08-23 05:48 采纳率: 16.7%
浏览 301
已采纳

jpaRepository 的繼承

正在學習spring boot。

請先看以下代碼:

public abstract class Thing
{
......
}

public class Person extends Thing
{
......
}

public interface Thing_Repository extends JpaRepository
{ }

public interface Person_Repository extends Thing_Repository
{ }

但是以上黑體“Thing_Repository”下有紅划綫報錯“The type Thing_Repository is not generic; it cannot be parameterized with arguments ”

我希望做到當運行以下代碼:

Thing_Repository.save(Thing)

如果Thing是Person的話,它會自動調:

Person_Repository.save(Person)

可以做到嗎?

  • 写回答

4条回答 默认 最新

  • threenewbee 2019-08-23 09:22
    关注

    Thing_Repository不是泛型类,你是不是加上尖括号了。这里代码贴得看不清楚。

    如果Thing是Person的話,它會自動調:
    Person_Repository.save(Person)

    这个本来就是这样

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 已采纳回答 8月23日