多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

时间:2023-03-09 22:59:01
多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

上篇用了单工程创建了SSM整合的web工程(http://www.cnblogs.com/yuanjava/p/6748956.html),这次我们把上篇的单工程改造成为多模块工程

一:创建对应的多工程

首先原工程有对应的包如下

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

因为原单工程是 contoller 调用 service ,service 调用 mapper ,mapper 调用pojo

因此把对应的 service  mapper  pojo 分别拆分出去当做模块  然后把utils公用的抽出去当做common模块

最后创建出来的工程关系如下:

lxs-parent (父工程 pom)

----------lxs-common (子工程 jar 对应原工程里的utils)

--------- lxs-web-parent  (子工程  聚合工程  pom)

----------lxs-pojo (子模块  jar 对应原工程 pojo包)

----------lxs-mapper (子模块  jar 对应原工程 dao包)

----------lxs-service (子模块  jar 对应原工程 service 接口和实现类)

----------lxs-web (子模块 war )

还有另一种创建方式  把lxs-common,lxs-pojo,lxs-mapper,lxs-service lxs-web直接聚合到lxs-parent父工程里。

1.创建项目父工程 lxs-parent

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

2.创建common工程lxs-common    jar供其他工程使用,继承父工程

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

3.创建web 工程的父工程 lxs_web_parent,继承父工程

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

在lxs_web_parent创建聚合工程 点lxs_web_parent 右键创建个

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

Pojo模块  专门用于存放 pojo 类

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

同理创建mapper 模块 和 service模块

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

最后创建 web工程

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

把lxs-web变成 web工程

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

至此,所有工程创建完成,结构如下

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

二:导入对应的jar包和对应的依赖包

把原工程里的pom.xml 里的依赖拷贝到父工程  lxs-parent里

然后理清对应的依赖关系

lxs-parent (父工程 pom)

----------lxs-common

--------- lxs-web-parent  (依赖lxs-common)

----------lxs-pojo (不依赖任何)

----------lxs-mapper (依赖lxs-pojo)

----------lxs-service (依赖lxs-pojo和lxs-mapper )

----------lxs-web (依赖lxs-service )

lxs-common修改 pom.xml ,为了过滤包,暂时先把 lxs-parent 的内容移过去,以后直接慢慢去除不需要的。

去除版本号

lxs-web-parent 依赖lxs-common

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

lxs-pojo不依赖其他 ,Pom.xml 不修改

lxs-mapper模块 依赖lxs-pojo

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

lxs-Service 依赖lxs-pojo和 lxs-mapper

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

lxs-Web 依赖lxs-service

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

依赖传递完成

三:把原工程对应的模块和代码移动到多模块工程里

1. SSM 工程里webapp等内容全拷贝到 lxs-web工程里

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

把resources里的内容也拷贝过去

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

2. 然后开始把原SSM 里的各个包里的内容分别拷到各自的模块中

a. Bean 包对应 pojo

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

拷贝到

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

b.Controller包拷贝到lxs-web里

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

c. Dao包对应mapper模块 拷贝到此模块

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

d.Service 接口和实现类拷贝到  service模块

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

至此,所有步骤完成。

接下来验证结果,启动tomcat

多工程:基于Maven的SSM(Spring,SpringMvc,Mybatis)整合的web工程(中)

多工程创建成功。

下篇: 可以把 service jar 单独拿出来当做一个war 当做服务提供者,然后用前端contoller当做消费者调用,下篇接着改造