Spring Boot Jpa如何封装一个BaseDao?

Jackie_GP 2017-07-24 05:15:55
怎么把springboot的jpa封装一个basedao,
public interface BaseDao<T, ID extends Serializable> extends JpaRepository<T, ID>, JpaSpecificationExecutor<T>
其他的dao,都继承这个BaseDao就可以呢?

而不是每一个Dao都继承JpaRepository这个。
比如:
public interface DepartmentDao extends JpaRepository<Department, Integer>, JpaSpecificationExecutor<Department>

这样正确
但是,如果public interface DepartmentDao extends BaseDao<Department, Integer>
就错误。
错误如下:
Error creating bean with name 'departmentDao': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property createObject found for type Department!
应该怎么写呢?
请大神帮忙!
...全文
881 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jackie_GP 2017-08-04
  • 打赏
  • 举报
回复
引用 5 楼 xing317521 的回复:
我测试了可以添加自定义方法
你的student.dao是怎么定义的?
浮云_骑士 2017-07-26
  • 打赏
  • 举报
回复



我测试了可以添加自定义方法
Jackie_GP 2017-07-24
  • 打赏
  • 举报
回复
引用 2 楼 xing317521 的回复:
基类加@NoRepositoryBean注解
加了,但是,发现在这里不能定义任何方法。
Jackie_GP 2017-07-24
  • 打赏
  • 举报
回复
引用 1 楼 wdd668 的回复:
BaseDao<Department, Integer> 这个类有继承吗?有加注解吗?
希望别的dao来继承它。但是,发现在这里不能定义任何方法。
浮云_骑士 2017-07-24
  • 打赏
  • 举报
回复
基类加@NoRepositoryBean注解
wdd668 2017-07-24
  • 打赏
  • 举报
回复
BaseDao<Department, Integer> 这个类有继承吗?有加注解吗?

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧