简体   繁体   English

如何在没有注释的情况下使用 Spring 数据 JDBC?

[英]How to use Spring Data JDBC without annotations?

I'm working on a new project, using concepts like clean architecture, protecting my model and business rules from external dependencies and frameworks.我正在开发一个新项目,使用干净架构等概念,保护我的 model 和业务规则免受外部依赖项和框架的影响。 Also, I prefer not to use traditional ORM libraries (like JPA/Hibernate) and have choose to use plain jdbc (through spring jdbctemplate).另外,我不喜欢使用传统的 ORM 库(如 JPA/Hibernate)并选择使用普通的 jdbc(通过 spring jdbctemplate)。

It was going pretty well, but I'm getting tired of write 20x almost the same query for all my domain classes on a basic crud reposity.进展顺利,但我已经厌倦了在基本的 crud reposity 上为我的所有域类编写 20 倍几乎相同的查询。 So, I take a look at Spring Data JDBC, but it appears that it's necessary to add annotations on my domain classes to make it work properly.因此,我查看了 Spring 数据 JDBC,但似乎有必要在我的域类上添加注释以使其正常工作。 I really don't want to do that, first because I want to make my domain cleaner as possible from any dependencies, and second because this is one of the (many) things I really dislike on JPA.我真的不想这样做,首先是因为我想让我的域从任何依赖项中尽可能清洁,其次因为这是我在 JPA 上真正不喜欢的(许多)事情之一。

I was wondering that, the repository needs only 2 things: a rowmapper definition and the PK definition (and both could be defined at the repository itself) avoiding the complete use of annotations.我想知道,存储库只需要两件事:行映射器定义和 PK 定义(两者都可以在存储库本身定义)避免完全使用注释。

So, my question is there any way to use Spring Data JDBC without annotations?所以,我的问题是有什么方法可以在没有注释的情况下使用 Spring 数据 JDBC ?

No, there is no easy way to use Spring Data JDBC ( https://spring.io/projects/spring-data-jdbc ).不,没有简单的方法可以使用 Spring 数据 JDBC( https://spring.io/projects/spring-data-jdbc )。

What you could do is to replace those classes that do the annotation interpretation ( RelationalPersistentEntityImpl , and BasicRelationalPersistentProperty ) and replace them with something that gets the information from elsewhere.您可以做的是替换那些执行注释解释的类( RelationalPersistentEntityImplBasicRelationalPersistentProperty )并将它们替换为从其他地方获取信息的东西。

There is a different framework wich might fit the bill which is also named Spring Data JDBC ♀️ https://github.com/nurkiewicz/spring-data-jdbc-repository有一个不同的框架可能适合这个法案,它也被命名为 Spring Data JDBC ♀️ https://github.com/c-rekiewic

It seems pretty close to what you are looking for but it has its last commit 6 years ago and is archived on Github.它似乎与您要查找的内容非常接近,但它的最后一次提交是在 6 年前并存档在 Github 上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM