当前位置: 首页 > news >正文

怎么做类似美团的网站吗网站开发在线教程

怎么做类似美团的网站吗,网站开发在线教程,商丘家具网站建设,南头网站建设创建Order项目实现Clean Hexagonal架构 前言 在上一节中#xff0c;讲到了Clean Hexagonal架构的理论部分#xff0c;并且通过图形解释了从MVC架构到清洁架构到演变。下面我们通过创建项目的方式来进一步理解Clean Hexagonal架构。 1.项目创建 1. 项目…创建Order项目实现Clean Hexagonal架构 前言 在上一节中讲到了Clean Hexagonal架构的理论部分并且通过图形解释了从MVC架构到清洁架构到演变。下面我们通过创建项目的方式来进一步理解Clean Hexagonal架构。 1.项目创建 1. 项目整体结构规划 项目采用 Maven 多模块架构父模块聚合子模块依赖层级清晰。 结构说明 order-system/ # 父项目聚合所有子模块 ├── .git # Git 仓库目录 ├── .gitignore # Git 忽略规则如 target/、.DS_Store 等 ├── .idea/ # IntelliJ IDEA 配置目录自动生成 ├── order-service/ # 订单服务模块子模块 │ ├── order-application/ # 应用层接口、DTO、服务入口 │ ├── order-container/ # 容器配置Spring Boot 启动类 │ ├── order-dataccess/ # 数据访问层DAO、JPA/MyBatis 实现 │ ├── order-domain/ # 领域层领域模型、领域服务 │ ├── order-message/ # 消息处理MQ 消费者/生产者 │ └── pom.xml # 子模块的 pom 文件 └── pom.xml # 父模块的 pom 文件1.1 父项目order-system 父项目聚合了所有的子模块进行统一的依赖管理对应的pom文件如下 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion3.4.1/versionrelativePath //parentgroupIdcom.jackmouse/groupIdartifactIdorder-system/artifactIdversion1.0-SNAPSHOT/versionpackagingpom/packagingmodulesmoduleorder-service/module/modulespropertiesmaven.compiler.source17/maven.compiler.sourcemaven.compiler.target17/maven.compiler.targetproject.build.sourceEncodingUTF-8/project.build.sourceEncodingmaven-compiler-plugin.version3.13.0/maven-compiler-plugin.version/propertiesdependencyManagementdependenciesdependencygroupIdcom.jackmouse/groupIdartifactIdorder-domian-core/artifactIdversion${project.version}/version/dependencydependencygroupIdcom.jackmouse/groupIdartifactIdorder-application-service/artifactIdversion${project.version}/version/dependencydependencygroupIdcom.jackmouse/groupIdartifactIdorder-application/artifactIdversion${project.version}/version/dependencydependencygroupIdcom.jackmouse/groupIdartifactIdorder-dataaccess/artifactIdversion${project.version}/version/dependencydependencygroupIdcom.jackmouse/groupIdartifactIdorder-message/artifactIdversion${project.version}/version/dependency/dependencies/dependencyManagementdependencies/dependenciesbuildpluginsplugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-compiler-plugin/artifactIdversion${maven-compiler-plugin.version}/versionconfigurationrelease17/release/configuration/plugin/plugins/build/project1.1 order-container容器/启动模块 作用 包含 Spring Boot 的主启动类Application.java是项目的入口。负责整合所有子模块的依赖如 order-application、order-dataccess 等。配置全局属性如数据源、消息队列连接、Web 端口等。 示例代码 SpringBootApplication public class Application {public static void main(String[] args) {SpringApplication.run(Application.class, args);} }pom文件 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.jackmouse/groupIdartifactIdorder-service/artifactIdversion1.0-SNAPSHOT/version/parentartifactIdorder-container/artifactIdpropertiesmaven.compiler.source17/maven.compiler.sourcemaven.compiler.target17/maven.compiler.targetproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/propertiesdependenciesdependencygroupIdcom.jackmouse/groupIdartifactIdorder-domian-core/artifactId/dependencydependencygroupIdcom.jackmouse/groupIdartifactIdorder-application-service/artifactId/dependencydependencygroupIdcom.jackmouse/groupIdartifactIdorder-application/artifactId/dependencydependencygroupIdcom.jackmouse/groupIdartifactIdorder-message/artifactId/dependency/dependencies /project1.2 order-application应用层 作用 调用领域层order-domain。处理输入输出如接收 HTTP 请求返回 DTO 对象。 pom文件 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.jackmouse/groupIdartifactIdorder-service/artifactIdversion1.0-SNAPSHOT/version/parentartifactIdorder-application/artifactIdpropertiesmaven.compiler.source17/maven.compiler.sourcemaven.compiler.target17/maven.compiler.targetproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/propertiesdependenciesdependencygroupIdcom.jackmouse/groupIdartifactIdorder-application-service/artifactId/dependency/dependencies/project1.3 order-domain领域层 作用 核心业务逻辑和领域模型如 Order 实体、OrderStatus 值对象。定义领域服务如校验订单规则的 OrderValidator。声明仓储接口如 OrderRepository但不实现具体逻辑。 可以将domain层在细化为service层和core层service层实现具体的业务逻辑和外部接口的定义core层定义实体和值对象。 关键文件 Order.java领域实体 public class Order {private Long id;private String orderNumber;private BigDecimal totalAmount;public void cancel() {// 领域逻辑校验订单是否可取消if (this.status OrderStatus.SHIPPED) {throw new IllegalStateException(已发货订单不可取消);}this.status OrderStatus.CANCELLED;} }pom文件 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.jackmouse/groupIdartifactIdorder-service/artifactIdversion1.0-SNAPSHOT/version/parentartifactIdorder-domain/artifactIdpackagingpom/packagingmodulesmoduleorder-domian-core/modulemoduleorder-application-service/module/modulespropertiesmaven.compiler.source17/maven.compiler.sourcemaven.compiler.target17/maven.compiler.targetproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/properties/project1.4 order-dataccess数据访问层 作用 实现领域层定义的仓储接口如 OrderRepositoryImpl。集成 ORM 框架如 JPA、MyBatis操作数据库。处理数据持久化细节如分页查询、事务管理。 关键文件 OrderRepositoryImpl.java仓储实现 Repository public class OrderRepositoryImpl implements OrderRepository {Autowiredprivate JdbcTemplate jdbcTemplate;Overridepublic void save(Order order) {String sql INSERT INTO orders (...) VALUES (...);jdbcTemplate.update(sql, ...);} }pom文件 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.jackmouse/groupIdartifactIdorder-service/artifactIdversion1.0-SNAPSHOT/version/parentartifactIdorder-dataaccess/artifactIdpropertiesmaven.compiler.source17/maven.compiler.sourcemaven.compiler.target17/maven.compiler.targetproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/propertiesdependenciesdependencygroupIdcom.jackmouse/groupIdartifactIdorder-application-service/artifactId/dependency/dependencies/project1.5 order-message消息处理模块 作用 处理异步消息如订单创建后发送 Kafka 事件。定义消息生产者如 OrderEventPublisher和消费者如 PaymentEventListener。解耦系统间通信支持事件驱动架构。 关键文件 OrderEventPublisher.java消息生产者 Component public class OrderEventPublisher {Autowiredprivate KafkaTemplateString, OrderEvent kafkaTemplate;public void publishOrderCreated(Order order) {OrderEvent event new OrderEvent(order);kafkaTemplate.send(order-topic, event);} }pom文件 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.jackmouse/groupIdartifactIdorder-service/artifactIdversion1.0-SNAPSHOT/version/parentartifactIdorder-message/artifactIdpropertiesmaven.compiler.source17/maven.compiler.sourcemaven.compiler.target17/maven.compiler.targetproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/propertiesdependenciesdependencygroupIdcom.jackmouse/groupIdartifactIdorder-application-service/artifactId/dependency/dependencies/project2.生成依赖图 使用depgraph-maven-plugin插件可以生成项目的依赖关系。 首先要在系统安装graphvizhttps://www.graphviz.org/ mac使用brew安装过程中可能会因为系统版本高导致报错 使用–build-from-source命令用从源代码安装如 brew install --build-from-source graphviz安装完成后在项目的根目录执行 mvn com.github.ferstl:depgraph-maven-plugin:aggregate -DcreateImagetrue -DreduceEdgesfalse -Dscopecompile -Dincludescom.jackmouse*:*com.jackmouse为你自己的包路径执行成功后 项目的target目录下会生成png文件 可以看到domain层不依赖于其他任何外部部组件所有外部服务如数据库、消息队列、外部服务都通过接口和适配器与业务逻辑交互。核心业务逻辑保持独立易于测试和替换使得系统具有更好的扩展性和灵活性。
http://www.w-s-a.com/news/954884/

相关文章:

  • 鲜花网站建设的利息分析企业网站建设方案书
  • 深圳网站平台石家庄做商城网站的公司
  • 微网站营销是什么私人订制网站有哪些
  • 浙江建设工程合同备案网站新手做网站教程
  • 网站优化关键词排名自己怎么做wordpress安装主题失败
  • 成都建设银行招聘网站网站的切换语言都是怎么做的
  • 网站网业设计wordpress 很差
  • 网站开发软件著作权归谁网站悬浮窗广告
  • 如何提升网站alexa排名货运网站源码
  • 如何看自己网站流量梧州网站设计理念
  • 商城网站建设特点有哪些信息门户
  • 弄一个网站临沂有哪几家做网站的
  • 广州个人网站制作公司网站建设公司价
  • 免费建设网站赚钱小程序开发文档pdf
  • ucenter 整合两个数据库网站网店推广技巧
  • 网站优化排名提升百度wap
  • 八里河风景区网站建设内容摘要网站开发基础学习
  • 上海做外贸网站的公司智慧团建网站登陆平台
  • 上海商务网站建设如何做的网站手机可以用吗
  • 产品推广营销方案seo推广员招聘
  • 做水利网站需要多少钱山东市网站建设
  • 做网站找哪里如何修改wordpress颜色
  • 招商加盟网站系统站长工具 seo查询
  • 工商局网站清算组备案怎么做电商培训机构
  • 做好门户网站建设做本地团购网站怎么样
  • wordpress主题和预览不同20条优化防疫措施方案
  • 艾奇视觉网站建设网站推广需要几个人做
  • 2008 iis 添加网站wordpress固定链接标签加上页面
  • 宁波企业网站制作推荐网站优化人员
  • 大型资讯门户网站怎么做排名沈阳建设工程有限公司