繁体   English   中英

java+spring应用程序中如何使用设计模式排列文件结构

[英]How to use a design pattern to arrange the file structure in a java+spring application

I created a web application which gets the data from the user from the console and stores the data in MongoDB and pass the data to the Angular frontend using Spring rest api.
整个系统运行良好,现在我想根据设计模式重新排列文件夹结构,如下所示,我尝试使用 MVC model 但我不确定文件重新排列是否正确我对设计模式了解不多. 所以请帮我解决这个问题,如果下面的结构有误,请帮我改正。

在此处输入图像描述

控制器

BookController - Class with rest api to pass data to angular frontend (REST Controller class)

Model

书 - 带有变量和相关方法的父 class
小说-带变量的子class及相关方法
诗歌 - 带有变量和相关方法的儿童 class
MyBookManager - BookManager 接口实现了 class ,其中包括使用 mongoDB 的 crud 操作

看法

BookManager - 与 MyBookManager 相关的接口
控制台 - Class 从控制台获取用户的输入并调用 MyBookManager 中的方法将它们保存到数据库

存储库

BookRepository - 扩展 MongoRepository 的接口

剩余课程

BookStoreApplication - Class 其中包括主要方法(运行类)
ErrorHandle - Class,其中包括验证方法

班级整体安排不错。 我可以建议的唯一调整是在 Controller package 中移动 BookManager 和 MyBookManager。 原因是因为它在视图(Console)和model(数据库)之间,它可以改变model(通过更新db),它可能包含一些关于如何正确解析用户输入的业务逻辑。

如果您想进一步将 BookManager 与 Controller 分离,则可以将其称为 BookService 并将其放置在称为 Service 的 package 中(以及 MyBookService)。

关于设计模式,MVC 是一种架构模式,而不是设计模式。 我将您链接到其他问题以获取更多信息:

暂无
暂无

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

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