简体   繁体   English

我在哪里将我的方法放在MVC上?

[英]Where do I put my methods with MVC?

I have a folder /controllers with controllers and another /models where i put my models with get/sets. 我有一个包含控制器的文件夹/controllers和另一个/models ,我在其中放置了带有get / sets的模型。

Now, where is the usual place to put the methods to get data from the db,etc...? 现在,放置从数据库等获取数据的方法的通常位置在哪里?

In my last project I put it under the get/sets and it was a bit confusing. 在我的上一个项目中,我将其放在get / sets下,这有点令人困惑。

Any helP? 有帮助吗?

For database you can have a DTO folder, but you could also have a intermediate Service folder where you put all the business rules. 对于数据库,您可以有一个DTO文件夹,但也可以有一个中间的Service文件夹,您可以在其中放置所有业务规则。 I like having a separate DTO object to make mocking easier too. 我喜欢拥有一个单独的DTO对象,以简化模拟。

For strictly data access, spring boot handles most of CRUD. 对于严格的数据访问,Spring Boot处理大多数CRUD。 You just need to config spring to know you have a data access layer. 您只需要配置spring即可知道您具有数据访问层。 @JpaRepository does this. @JpaRepository执行此操作。 This is probably where you should start looking. 这可能是您应该开始寻找的地方。 For custom data calls you're going to have to write custom methods inside the classes that make up the data access laters. 对于自定义数据调用,您将不得不在稍后构成数据访问的类中编写自定义方法。

Your question is extremely broad but I hope I've given you enough to look at. 您的问题非常广泛,但我希望我已经给您足够的机会来探讨。

https://spring.io/guides/gs/accessing-data-jpa/ https://spring.io/guides/gs/accessing-data-jpa/

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

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