英文:
What is the best way to maintain queries in Spring boot application?
问题
在我的应用程序中,使用以下技术:
- Spring Boot 2.7.x
- Cassandra
- Spring Batch 5.x
- Java 11
作为其中的一部分,我需要从Cassandra数据库中提取数据并将其写入文件。因此,在这里,我需要使用查询来获取数据,所以我只想知道如何在一个地方维护所有查询,以便将来发生查询更改时,不需要重新构建应用程序,只需修改查询即可。
英文:
In My Application, Using the below technologies
- Spring boot 2.7.x
- Cassandra
- spring batch 5. x
- java 11
As part of this, I need to extract data from the Cassandra database and need to write out the file
so here I need to use queries to fetch data so
just want to know what is the best way to maintain all queries at one place so any query changes come in the future, I shouldn't build the app rather just need to modify the query.
答案1
得分: 1
使用存储库类是必要的。如果您正在使用JPA,我建议为每个实体类使用一个存储库。对于JDBC,可以创建一个包含所有查询的单个存储库。要访问查询方法,我会使用一个服务类。这样,您的代码结构良好,易于维护以应对未来的更改。
英文:
Using a repository class is necessary. If you are using JPA i recommend using a repository for each Entity class. With JDBC it is possible to create a single repository which contains all the queries. To access the query methodes i would use a service class. In this way your code is structured well and maintainable for future changes.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论