日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

181. maven项目ssm(父工程 子工程)

發(fā)布時間:2023/12/20 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 181. maven项目ssm(父工程 子工程) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>

前面的ssm只是將項目的jar使用了maven管理,擴(kuò)展性很差(準(zhǔn)備將項目進(jìn)行SOA結(jié)構(gòu))

1.效果

?

2. 準(zhǔn)備項目搭建環(huán)境

2.1 maven 環(huán)境

參考:https://my.oschina.net/springMVCAndspring/blog/1817609

2.2 eclipse(mars2版本)

參考:https://my.oschina.net/springMVCAndspring/blog/1817609

3. 搭建項目

3.1 總父工程

3.1.1 建立父工程

、

3.1.2 導(dǎo)入jar及插件

?<!--?
??? ? ? 集成的內(nèi)容:
? ?? ??? ?(1) 導(dǎo)入各個系統(tǒng)所需要的jar
? ?? ??? ??? ??? ?(1.1) 工具類
? ?? ??? ??? ??? ?(1.2)mybaties
? ?? ??? ??? ??? ?(1.3) spring
? ?? ??? ??? ??? ?(1.4)springmvc
? ?? ??? ??? ??? ?(1.5)其他
? ?? ??? ?(2) 插件
? ?? ??? ??? ??? ?(2.1) ?資源文件拷貝插件
? ?? ??? ??? ??? ?(2.2) ?java編譯版本
? ?? ??? ??? ??? ?(2.3) ?Tomcat版本
? ?-->
? ?<!-- 1.導(dǎo)入jar -->
? <!-- 集中定義依賴版本號 -->
<properties>
?? ?<junit.version>4.12</junit.version>
?? ?<spring.version>4.1.3.RELEASE</spring.version>
?? ?<mybatis.version>3.2.8</mybatis.version>
?? ?<mybatis.spring.version>1.2.2</mybatis.spring.version>
?? ?<mybatis.paginator.version>1.2.15</mybatis.paginator.version>
?? ?<mysql.version>5.1.32</mysql.version>
?? ?<slf4j.version>1.6.4</slf4j.version>
?? ?<jackson.version>2.4.2</jackson.version>
?? ?<druid.version>1.0.9</druid.version>
?? ?<httpclient.version>4.3.5</httpclient.version>?
?? ?<jstl.version>1.2</jstl.version>
?? ?<servlet-api.version>2.5</servlet-api.version>
?? ?<jsp-api.version>2.0</jsp-api.version>
?? ?<joda-time.version>2.5</joda-time.version>
?? ?<commons-lang3.version>3.3.2</commons-lang3.version>
?? ?<commons-io.version>1.3.2</commons-io.version>
?? ?<commons-net.version>3.3</commons-net.version>
?? ?<pagehelper.version>3.4.2</pagehelper.version>
?? ?<jsqlparser.version>0.9.1</jsqlparser.version>
?? ?<commons-fileupload.version>1.3.1</commons-fileupload.version>
?? ?<jedis.version>2.7.2</jedis.version>
?? ?<solrj.version>4.10.3</solrj.version>
?? ?<dubbo.version>2.5.3</dubbo.version>
?? ?<zookeeper.version>3.4.7</zookeeper.version>
?? ?<zkclient.version>0.1</zkclient.version>
?? ?<activemq.version>5.11.2</activemq.version>
?? ?<freemarker.version>2.3.23</freemarker.version>
?? ?<quartz.version>2.2.2</quartz.version>
?? ?<fastjson.version>1.2.47</fastjson.version>
</properties>
<dependencyManagement>
?? ?<dependencies>
?? ? ? ?<!-- ?1.1 ?工具類..................................................................................開始......-->
?? ??? ?<!-- (1)時間操作組件 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>joda-time</groupId>
?? ??? ??? ?<artifactId>joda-time</artifactId>
?? ??? ??? ?<version>${joda-time.version}</version>
?? ??? ?</dependency>
?? ??? ?<!-- (2)Apache工具組件 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.apache.commons</groupId>
?? ??? ??? ?<artifactId>commons-lang3</artifactId>
?? ??? ??? ?<version>${commons-lang3.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.apache.commons</groupId>
?? ??? ??? ?<artifactId>commons-io</artifactId>
?? ??? ??? ?<version>${commons-io.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>commons-net</groupId>
?? ??? ??? ?<artifactId>commons-net</artifactId>
?? ??? ??? ?<version>${commons-net.version}</version>
?? ??? ?</dependency>
?? ??? ?<!-- (3)Jackson Json處理工具包 -->?
?? ??? ?<dependency>
?? ??? ??? ?<groupId>com.fasterxml.jackson.core</groupId>
?? ??? ??? ?<artifactId>jackson-databind</artifactId>
?? ??? ??? ?<version>${jackson.version}</version>
?? ??? ?</dependency>
?? ??? ?<!-- (4)httpclient -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.apache.httpcomponents</groupId>
?? ??? ??? ?<artifactId>httpclient</artifactId>
?? ??? ??? ?<version>${httpclient.version}</version>
?? ??? ?</dependency>
?? ??? ?<!-- (5)quartz任務(wù)調(diào)度框架 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.quartz-scheduler</groupId>
?? ??? ??? ?<artifactId>quartz</artifactId>
?? ??? ??? ?<version>${quartz.version}</version>
?? ??? ?</dependency>
?? ??? ?<!-- (6)單元測試 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>junit</groupId>
?? ??? ??? ?<artifactId>junit</artifactId>
?? ??? ??? ?<version>${junit.version}</version>
?? ??? ??? ?<scope>test</scope>
?? ??? ?</dependency>
?? ??? ?<!-- (7)日志處理 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.slf4j</groupId>
?? ??? ??? ?<artifactId>slf4j-log4j12</artifactId>
?? ??? ??? ?<version>${slf4j.version}</version>
?? ??? ?</dependency>
?? ??? ? <!-- (8)fastjson -->
? ? ? ? ? ? <dependency>
? ? ? ? ? ? ? ? <groupId>com.alibaba</groupId>
? ? ? ? ? ? ? ? <artifactId>fastjson</artifactId>
? ? ? ? ? ? ? ? <version>${fastjson.version}</version>
? ? ? ? ? ? </dependency>
? ? ? ? ? ? <!-- ?1.1 ?工具類..................................................................................結(jié)束......-->
? ? ? ? ? ? <!-- ?1.2 ?Mybatis..................................................................................開始......-->
?? ??? ?<!--(1) Mybatis -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.mybatis</groupId>
?? ??? ??? ?<artifactId>mybatis</artifactId>
?? ??? ??? ?<version>${mybatis.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.mybatis</groupId>
?? ??? ??? ?<artifactId>mybatis-spring</artifactId>
?? ??? ??? ?<version>${mybatis.spring.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>com.github.miemiedev</groupId>
?? ??? ??? ?<artifactId>mybatis-paginator</artifactId>?
?? ??? ??? ?<version>${mybatis.paginator.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>com.github.pagehelper</groupId>
?? ??? ??? ?<artifactId>pagehelper</artifactId>
?? ??? ??? ?<version>${pagehelper.version}</version>
?? ??? ?</dependency>
?? ??? ?<!-- (2)MySql -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>mysql</groupId>
?? ??? ??? ?<artifactId>mysql-connector-java</artifactId>
?? ??? ??? ?<version>${mysql.version}</version>
?? ??? ?</dependency>
?? ??? ?<!-- (3)連接池 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>com.alibaba</groupId>
?? ??? ??? ?<artifactId>druid</artifactId>
?? ??? ??? ?<version>${druid.version}</version>
?? ??? ?</dependency>
?? ??? ? <!-- ?1.2 ?Mybatis..................................................................................結(jié)束......-->
?? ??? ? <!-- ?1.3 ?Spring...................................................................................開始......-->
?? ??? ?<!-- (1)Spring -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-context</artifactId>
?? ??? ??? ?<version>${spring.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-beans</artifactId>
?? ??? ??? ?<version>${spring.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-webmvc</artifactId>
?? ??? ??? ?<version>${spring.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-jdbc</artifactId>
?? ??? ??? ?<version>${spring.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-aspects</artifactId>
?? ??? ??? ?<version>${spring.version}</version>?
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-jms</artifactId>
?? ??? ??? ?<version>${spring.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-context-support</artifactId>
?? ??? ??? ?<version>${spring.version}</version>
?? ??? ?</dependency>
?? ??? ? <!-- ?1.3 ?Spring..................................................................................結(jié)束......-->
?? ??? ? ?<!-- ?1.4 ?SpringMVC..................................................................................開始......-->
?? ??? ?<!-- (1)JSP相關(guān) -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>jstl</groupId>
?? ??? ??? ?<artifactId>jstl</artifactId>
?? ??? ??? ?<version>${jstl.version}</version>
?? ??? ?</dependency>
?? ??? ?<!-- (2)servlet -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>javax.servlet</groupId>
?? ??? ??? ?<artifactId>servlet-api</artifactId>
?? ??? ??? ?<version>${servlet-api.version}</version>
?? ??? ??? ?<scope>provided</scope>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>javax.servlet</groupId>
?? ??? ??? ?<artifactId>jsp-api</artifactId>
?? ??? ??? ?<version>${jsp-api.version}</version>
?? ??? ??? ?<scope>provided</scope>
?? ??? ?</dependency>
?? ??? ? <!-- ?1.4 ?SpringMVC..................................................................................結(jié)束......-->
?? ??? ?<!-- 文件上傳組件 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>commons-fileupload</groupId>
?? ??? ??? ?<artifactId>commons-fileupload</artifactId>
?? ??? ??? ?<version>${commons-fileupload.version}</version>
?? ??? ?</dependency>
?? ??? ?<!-- Redis客戶端 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>redis.clients</groupId>
?? ??? ??? ?<artifactId>jedis</artifactId>
?? ??? ??? ?<version>${jedis.version}</version>
?? ??? ?</dependency>
?? ??? ?<!-- solr客戶端 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.apache.solr</groupId>?
?? ??? ??? ?<artifactId>solr-solrj</artifactId>
?? ??? ??? ?<version>${solrj.version}</version>
?? ??? ?</dependency>
?? ??? ?<!-- dubbo相關(guān) -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>com.alibaba</groupId>
?? ??? ??? ?<artifactId>dubbo</artifactId>
?? ??? ??? ?<version>${dubbo.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.apache.zookeeper</groupId>
?? ??? ??? ?<artifactId>zookeeper</artifactId>
?? ??? ??? ?<version>${zookeeper.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>com.github.sgroschupf</groupId>
?? ??? ??? ?<artifactId>zkclient</artifactId>
?? ??? ??? ?<version>${zkclient.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.apache.activemq</groupId>
?? ??? ??? ?<artifactId>activemq-all</artifactId>
?? ??? ??? ?<version>${activemq.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.freemarker</groupId>
?? ??? ??? ?<artifactId>freemarker</artifactId>
?? ??? ??? ?<version>${freemarker.version}</version>
?? ??? ?</dependency>
?? ?</dependencies>
</dependencyManagement>
<!-- 2.插件 ?..........................................................................開始 -->
<build>
?? ?<finalName>${project.artifactId}</finalName>
?? ?<plugins>
?? ??? ?<!-- 資源文件拷貝插件 -->
?? ??? ?<plugin>
?? ??? ??? ?<groupId>org.apache.maven.plugins</groupId>
?? ??? ??? ?<artifactId>maven-resources-plugin</artifactId>
?? ??? ??? ?<version>2.7</version>
?? ??? ??? ?<configuration>
?? ??? ??? ?<encoding>UTF-8</encoding>
?? ??? ??? ?</configuration>?
?? ??? ?</plugin>
?? ??? ?<!-- java編譯插件 -->
?? ??? ?<plugin>
?? ??? ??? ?<groupId>org.apache.maven.plugins</groupId>
?? ??? ??? ?<artifactId>maven-compiler-plugin</artifactId>
?? ??? ??? ?<version>3.2</version>
?? ??? ??? ?<configuration>
?? ??? ??? ??? ?<source>1.8</source>
?? ??? ??? ??? ?<target>1.8</target>
?? ??? ??? ??? ?<encoding>UTF-8</encoding>
?? ??? ??? ?</configuration>
?? ??? ?</plugin>
?? ?</plugins>
?? ?<pluginManagement>
?? ??? ?<plugins>
?? ??? ??? ?<!-- 配置Tomcat插件 -->
?? ??? ??? ?<plugin>
?? ??? ??? ??? ?<groupId>org.apache.tomcat.maven</groupId>
?? ??? ??? ??? ?<artifactId>tomcat7-maven-plugin</artifactId>
?? ??? ??? ??? ?<version>2.2</version>
?? ??? ??? ?</plugin>
?? ??? ?</plugins>
?? ?</pluginManagement>
</build>
<!-- 2.插件 ?..........................................................................結(jié)束 -->

3.2 工具工程項目

3.2.1 搭建common項目

3.2.2 編寫pom文件

?<!-- 工具工程jar -->
? <dependencies>
? ?? ??? ? ? <!-- ?1.1 ?工具類..................................................................................開始......-->
?? ??? ?<!-- (1)時間操作組件 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>joda-time</groupId>
?? ??? ??? ?<artifactId>joda-time</artifactId>
?? ??? ??? ?<version>${joda-time.version}</version>
?? ??? ?</dependency>
?? ??? ?<!-- (2)Apache工具組件 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.apache.commons</groupId>
?? ??? ??? ?<artifactId>commons-lang3</artifactId>
?? ??? ??? ?<version>${commons-lang3.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.apache.commons</groupId>
?? ??? ??? ?<artifactId>commons-io</artifactId>
?? ??? ??? ?<version>${commons-io.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>commons-net</groupId>
?? ??? ??? ?<artifactId>commons-net</artifactId>
?? ??? ??? ?<version>${commons-net.version}</version>
?? ??? ?</dependency>
?? ??? ?<!-- (3)Jackson Json處理工具包 -->?
?? ??? ?<dependency>
?? ??? ??? ?<groupId>com.fasterxml.jackson.core</groupId>
?? ??? ??? ?<artifactId>jackson-databind</artifactId>
?? ??? ??? ?<version>${jackson.version}</version>
?? ??? ?</dependency>
?? ??? ?<!-- (4)httpclient -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.apache.httpcomponents</groupId>
?? ??? ??? ?<artifactId>httpclient</artifactId>
?? ??? ??? ?<version>${httpclient.version}</version>
?? ??? ?</dependency>
?? ??? ?<!-- (5)quartz任務(wù)調(diào)度框架 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.quartz-scheduler</groupId>
?? ??? ??? ?<artifactId>quartz</artifactId>
?? ??? ??? ?<version>${quartz.version}</version>
?? ??? ?</dependency>
?? ??? ?<!-- (6)單元測試 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>junit</groupId>
?? ??? ??? ?<artifactId>junit</artifactId>
?? ??? ??? ?<version>${junit.version}</version>
?? ??? ??? ?<scope>test</scope>
?? ??? ?</dependency>
?? ??? ?<!-- (7)日志處理 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.slf4j</groupId>
?? ??? ??? ?<artifactId>slf4j-log4j12</artifactId>
?? ??? ??? ?<version>${slf4j.version}</version>
?? ??? ?</dependency>
?? ??? ? <!-- (8)fastjson -->
? ? ? ? ? ? <dependency>
? ? ? ? ? ? ? ? <groupId>com.alibaba</groupId>
? ? ? ? ? ? ? ? <artifactId>fastjson</artifactId>
? ? ? ? ? ? ? ? <version>${fastjson.version}</version>
? ? ? ? ? ? </dependency>
? ? ? ? ? ? <!-- ?1.1 ?工具類..................................................................................結(jié)束......-->
? ?? ?
? </dependencies>

3.3 后臺管理系統(tǒng) 工程

? ?3.3.1 搭建工程

3.3.2 pom配置

? ?<!--?
? ?? ??? ?后臺管理系統(tǒng)父工程
? ?? ??? ??? ?(1)、抽取公共的坐標(biāo)進(jìn)行管理(被聚合的子系統(tǒng)自動依賴父工程坐標(biāo))
? ?? ??? ??? ?(2)、聚合管理子工程(同一打包,統(tǒng)一啟動)
? ?? ??? ??? ?(3)、抽取公共插件
? ?-->
? ? <dependencies>
? ??? ?<!-- ?1.公共的工具類-->
? ??? ??? ?<dependency>
? ??? ??? ??? ?<groupId>cn.guang</groupId>
? ??? ??? ??? ?<artifactId>shopping-common</artifactId>
? ??? ??? ??? ?<version>0.0.1-SNAPSHOT</version>
? ??? ??? ?</dependency>
? ?</dependencies>
? ?
? ?<!-- ?2.抽取公共插件-->
? ?<build>
? ??? ??? ?<plugins>
?? ??? ??? ?<!-- 2.1 配置Tomcat插件 -->
?? ??? ??? ?<plugin>
?? ??? ??? ??? ?<groupId>org.apache.tomcat.maven</groupId>
?? ??? ??? ??? ?<artifactId>tomcat7-maven-plugin</artifactId>
?? ??? ??? ??? ?<version>2.2</version><!--$NO-MVN-MAN-VER$-->
?? ??? ??? ??? ?<!-- 配置項目發(fā)布路徑及端口 -->
?? ??? ??? ??? ?<configuration>
?? ??? ??? ??? ??? ?<path>/</path><!--將項目發(fā)布到根目錄下面 ?-->
?? ??? ??? ??? ??? ?<port>8082</port><!-- 發(fā)布的端口 -->
?? ??? ??? ??? ?</configuration>
?? ??? ??? ?</plugin>
?? ??? ?</plugins>
? ?</build>

3.3.3 搭建后臺管理系統(tǒng)的 3層架構(gòu)

3.3.3.1 pojo層

搭建項目:

配置后臺管理系統(tǒng)的pojo 的 pom

3.3.3.2 dao層

搭建項目:

編寫pom

? <!--?
? ?? ?項目dao分層 拆分:dao訪問數(shù)據(jù)
? ?? ? (1)mysql驅(qū)動 、數(shù)據(jù)源、 mybatis(持久層框架)
? ?? ? (2) 依賴自己的 pojo
? ?? ? (3) 放行xml文件,讓xml文件在src/main/java也能被編譯
? ?-->
? ?<dependencies>
? ??? ??? ? <!-- ?1.2 ?Mybatis..................................................................................開始......-->
?? ??? ?<!--(1) Mybatis -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.mybatis</groupId>
?? ??? ??? ?<artifactId>mybatis</artifactId>
?? ??? ??? ?<version>${mybatis.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.mybatis</groupId>
?? ??? ??? ?<artifactId>mybatis-spring</artifactId>
?? ??? ??? ?<version>${mybatis.spring.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>com.github.miemiedev</groupId>
?? ??? ??? ?<artifactId>mybatis-paginator</artifactId>?
?? ??? ??? ?<version>${mybatis.paginator.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>com.github.pagehelper</groupId>
?? ??? ??? ?<artifactId>pagehelper</artifactId>
?? ??? ??? ?<version>${pagehelper.version}</version>
?? ??? ?</dependency>
?? ??? ?<!-- (2)MySql -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>mysql</groupId>
?? ??? ??? ?<artifactId>mysql-connector-java</artifactId>
?? ??? ??? ?<version>${mysql.version}</version>
?? ??? ?</dependency>
?? ??? ?<!-- (3)連接池 -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>com.alibaba</groupId>
?? ??? ??? ?<artifactId>druid</artifactId>
?? ??? ??? ?<version>${druid.version}</version>
?? ??? ?</dependency>
?? ??? ? <!-- ?1.2 ?Mybatis..................................................................................結(jié)束......-->

?? ??? ? <!-- 2.依賴自己的 pojo-->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>cn.guang</groupId>
?? ??? ??? ?<artifactId>shopping-manager-pojo</artifactId>
?? ??? ??? ?<version>0.0.1-SNAPSHOT</version>
?? ??? ?</dependency>

? ?</dependencies>
? ?
? ?
? ? ? <!--
? ? ? 3.放行xml文件,讓xml文件在src/main/java也能被編譯
? ? ??
?? ??? ?maven項目目錄約定:
?? ??? ?src/main/java:只能編譯java代碼
?? ??? ?src/main/resources:編譯配置文件
?? ??? ?為了滿足Mybatis接口開發(fā)規(guī)范:接口和映射文件必須在同一個目錄
?? ??? ?放行xml文件,讓xml文件在src/main/java也能被編譯
?? ??? ?-->
?? ??? ?<build>
?? ??? ??? ?<resources>
?? ??? ??? ?<resource>
?? ??? ??? ?<directory>src/main/java</directory>
?? ??? ??? ?<includes>
?? ??? ??? ?<include>**/*.properties</include>
?? ??? ??? ?<include>**/*.xml</include>
?? ??? ??? ?</includes>
?? ??? ??? ?<filtering>false</filtering>
?? ??? ??? ?</resource>
?? ??? ??? ?<resource>
?? ??? ??? ?<directory>src/main/resources</directory>
?? ??? ??? ?<includes>
?? ??? ??? ?<include>**/*.properties</include>
?? ??? ??? ?<include>**/*.xml</include>
?? ??? ??? ?</includes>
?? ??? ??? ?<filtering>false</filtering>
?? ??? ??? ?</resource>
?? ??? ??? ?</resources>
?? ??? ?</build>

3.3.3.3? service層

搭建工程:

pom文件配置:

<!--
? ?? ?service分層拆分
? ?? ??? ?(1)、spring框架
? ?? ??? ?(2)、依賴dao
? ? -->
? ? <dependencies>
? ? ?? ? <!-- ?1.3 ?Spring...................................................................................開始......-->
?? ??? ?<!-- (1)Spring -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-context</artifactId>
?? ??? ??? ?<version>${spring.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-beans</artifactId>
?? ??? ??? ?<version>${spring.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-webmvc</artifactId>
?? ??? ??? ?<version>${spring.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-jdbc</artifactId>
?? ??? ??? ?<version>${spring.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-aspects</artifactId>
?? ??? ??? ?<version>${spring.version}</version>?
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-jms</artifactId>
?? ??? ??? ?<version>${spring.version}</version>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework</groupId>
?? ??? ??? ?<artifactId>spring-context-support</artifactId>
?? ??? ??? ?<version>${spring.version}</version>
?? ??? ?</dependency>
?? ??? ? <!-- ?1.3 ?Spring..................................................................................結(jié)束......-->
?? ??? ? ?? ?<!-- 2. 自己的dao -->
?? ??? ??? ?<dependency>
?? ??? ??? ?<groupId>cn.guang</groupId>
?? ??? ??? ?<artifactId>shopping-manager-dao</artifactId>
?? ??? ??? ?<version>0.0.1-SNAPSHOT</version>
?? ??? ?</dependency>

? ? </dependencies>

3.3.3.4? ?controller層

搭建工程:

配置pom

? <!--?
? ?? ?web拆分分析:
? ?? ??? ?(1)jsp、jstl、servlet
? ?? ??? ?(2) 依賴service(spring是從service間接依賴過來的)
? ?-->
? <dependencies>
? ? <!-- ?1.4 ?SpringMVC..................................................................................開始......-->
?? ??? ?<!-- (1)JSP相關(guān) -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>jstl</groupId>
?? ??? ??? ?<artifactId>jstl</artifactId>
?? ??? ??? ?<version>${jstl.version}</version>
?? ??? ?</dependency>
?? ??? ?<!-- (2)servlet -->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>javax.servlet</groupId>
?? ??? ??? ?<artifactId>servlet-api</artifactId>
?? ??? ??? ?<version>${servlet-api.version}</version>
?? ??? ??? ?<scope>provided</scope>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>javax.servlet</groupId>
?? ??? ??? ?<artifactId>jsp-api</artifactId>
?? ??? ??? ?<version>${jsp-api.version}</version>
?? ??? ??? ?<scope>provided</scope>
?? ??? ?</dependency>
?? ??? ? <!-- ?1.4 ?SpringMVC..................................................................................結(jié)束......-->
?? ??? ? <!-- 2.依賴service -->
?? ??? ??? ?<dependency>
?? ??? ??? ?<groupId>cn.guang</groupId>
?? ??? ??? ?<artifactId>shopping-manager-service</artifactId>
?? ??? ??? ?<version>0.0.1-SNAPSHOT</version>
?? ??? ?</dependency>

? </dependencies>

3.3.3.5 配置三層及web.xml文件

(1)web.xml?

?<!--?
? ?? ?(1) 編碼過濾器
? ?? ?(2)加載spring配置文件
? ?? ?(3)前端控制器
? ?-->
? ?<!-- 1.編碼過濾 -->
?? ?<filter>
?? ??? ?<filter-name>characterEncoding</filter-name>
?? ??? ?<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
?? ??? ?<init-param>
?? ??? ?<param-name>encoding</param-name>
?? ??? ?<param-value>UTF-8</param-value>
?? ??? ?</init-param>
?? ?</filter>
?? ?<filter-mapping>
?? ??? ?<filter-name>characterEncoding</filter-name>
?? ??? ?<url-pattern>/*</url-pattern>
?? ?</filter-mapping>
?? ?<!-- 2.加載spring配置文件
?? ??? ?(1).如果加載jar包配置文件,需要如下加載方式: classpath*:applicatonContext-*.xml
?? ??? ?(2).把配置文件全部放入web項目。
?? ??? ?加載方式: classpath: applicationContext-*.xml(使用MAVEN內(nèi)置tomcat插件)
?? ?-->

?? ?<listener>
?? ??? ?<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
?? ?</listener>
?? ?<context-param>
?? ??? ?<param-name>contextConfigLocation</param-name>
?? ??? ?<param-value>classpath:applicationContext-*.xml</param-value>
?? ?</context-param>
?? ?<!-- 3.前端控制器 ?-->
?? ?<servlet>
?? ??? ?<servlet-name>springmvc</servlet-name>
?? ??? ?<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
?? ??? ?<init-param>
?? ??? ?<param-name>contextConfigLocation</param-name>
?? ??? ?<param-value>classpath:springmvc.xml</param-value>
?? ??? ?</init-param>
?? ?</servlet>
?? ?<servlet-mapping>
?? ??? ?<servlet-name>springmvc</servlet-name>
?? ??? ?<url-pattern>/</url-pattern>
?? ?</servlet-mapping>

(2) 持久層的配置文件

4個文件,全部作為模板(注意存放的位置:看下圖

applicationContext-dao.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-4.0.xsd">
?? ?<!--?
?? ??? ?配置的內(nèi)容
?? ??? ?1.數(shù)據(jù)源
?? ??? ?2.sqlSessionFactory:生成sqlSession?
?? ??? ?3.接口代理開發(fā) 配置
?? ? -->
?? ? <!-- ?1.數(shù)據(jù)源 -->
?? ? ?? ?<context:property-placeholder location="classpath:jdbc.properties"/>
?? ??? ?<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
?? ??? ??? ?<property name="url" value="${jdbc.url}"></property>
?? ??? ??? ?<property name="driverClassName" value="${jdbc.driver}"></property>
?? ??? ??? ?<property name="username" value="${jdbc.username}"></property>
?? ??? ??? ?<property name="password" value="${jdbc.password}"></property>
?? ??? ?</bean>
?? ?<!-- 2.sqlSessionFactory:生成sqlSession ?-->
?? ??? ?<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
?? ??? ??? ?<property name="dataSource" ref="dataSource"></property>
?? ??? ??? ?<!-- 加載mybatis配置文件 -->
?? ??? ??? ?<property name="configLocation"
?? ??? ??? ?value="classpath:sqlMapConfig.xml"></property>
?? ??? ?</bean>
?? ??? ?<!--3. 接口代理開發(fā):掃描接口
?? ??? ??? ?* 接口和映射文件必須在同一個目錄,且必須同名
?? ??? ??? ?* 接口方法名必須和Statement的Id一致
?? ??? ??? ?* 映射文件namespace必須是接口全類路徑名
?? ??? ??? ?
?? ??? ??? ?更改:包路徑
?? ??? ??? ?-->
?? ??? ?<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
?? ??? ??? ?<property name="basePackage" value="cn.guang.shopping.manager.mapper"></property>
?? ??? ??? ?<property name="sqlSessionFactoryBeanName"
?? ??? ??? ?value="sqlSessionFactory"></property>
?? ??? ?</bean>
?? ??? ?
?? ??? ?
?? ??? ?
</beans>

?

jdbc.properties

jdbc.url=jdbc:mysql://localhost:3306/e3mall?characterEncoding=utf-8
jdbc.driver = com.mysql.jdbc.Driver
jdbc.username= root
jdbc.password= root

log4j.properties

log4j.rootLogger=DEBUG, Console
#Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n
log4j.logger.java.sql.ResultSet=INFO
log4j.logger.org.apache=INFO
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG

sqlMapConfig.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
?? ??? ?PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
?? ??? ?"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>

</configuration>

?

(3) service的配置文件

applicationContext-service.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-4.0.xsd">
<!-- ?0. 掃描包-->
<context:component-scan base-package="cn.guang.shopping.manager.service"></context:component-scan>
?? ?<!-- 業(yè)務(wù)層:
?? ??? ??? ?(1) 配置事務(wù)
?? ? -->
?? ? ?<!-- 事務(wù)通知 -->
?? ? ??? ?<!-- 1.1 管理事務(wù)平臺 -->
?? ?<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
?? ??? ?<property name="dataSource" ref="dataSource"></property>
?? ?</bean>
?? ?<!-- 1.2 事務(wù)通知 -->
?? ??? ?<tx:advice id="txAdvice" transaction-manager="transactionManager">
?? ??? ??? ?<tx:attributes>
?? ??? ??? ??? ?<!-- 傳播行為 -->
?? ??? ??? ??? ?<tx:method name="save*" propagation="REQUIRED" />
?? ??? ??? ??? ?<tx:method name="insert*" propagation="REQUIRED" />
?? ??? ??? ??? ?<tx:method name="add*" propagation="REQUIRED" />
?? ??? ??? ??? ?<tx:method name="create*" propagation="REQUIRED" />
?? ??? ??? ??? ?<tx:method name="delete*" propagation="REQUIRED" />
?? ??? ??? ??? ?<tx:method name="update*" propagation="REQUIRED" />
?? ??? ??? ??? ?<tx:method name="find*" propagation="SUPPORTS" read-only="true" />
?? ??? ??? ??? ?<tx:method name="select*" propagation="SUPPORTS" read-only="true" />
?? ??? ??? ??? ?<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
?? ??? ??? ?</tx:attributes>
?? ??? ?</tx:advice>
?? ??? ?<!-- 1.3 切面 -->
?? ??? ?<aop:config>
?? ??? ??? ?<aop:advisor advice-ref="txAdvice" pointcut="execution(* cn.guang.shopping.manager.service.*.*(..))"/>
?? ??? ?</aop:config>
?? ? ?
</beans>

(4)controller 配置文件

springmvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-4.0.xsd">
?? ?<!-- controller層:
?? ??? ??? ?(1)掃描包結(jié)構(gòu):把類交給spring管理
?? ??? ??? ?(2)注解驅(qū)動 :支持springmvc注解
?? ??? ??? ?(3) 過濾靜態(tài)資源:放行所有靜態(tài)資源
?? ??? ??? ?(4) 視圖解析器
?? ? -->
?? ? <!-- (1)掃描包結(jié)構(gòu):把類交給spring管理 -->
?? ?<context:component-scan base-package="cn.guang.shopping.manager.controller"></context:component-scan>
?? ? ?<!-- (2)注解驅(qū)動 :支持springmvc注解 ?-->
?? ? ?<mvc:annotation-driven/>
?? ? ?<!-- ?(3) 過濾靜態(tài)資源:放行所有靜態(tài)資源-->
?? ? ?<mvc:default-servlet-handler/>
?? ? ?<!-- ?(4) 視圖解析器-->
?? ? ??? ?<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
?? ??? ?<property name="prefix" value="/WEB-INF/jsp/"></property>
?? ??? ?<property name="suffix" value=".jsp"></property>
?? ?</bean>
?? ? ?
</beans>

?

3.3.3.6 創(chuàng)建三層代碼

(1)dao層? ?使用逆向工程插件生成

?

?

(2) service層

(3)controller層

3.2 測試

?3.2.1 打包 (安裝下圖順序打包)

3.2.2 啟動項目

clean tomcat7:run

3.2.3 訪問項目

效果:

4. 代碼

https://gitee.com/Luck_Me/ssm/tree/master

?

到這里 說明整個項目搭建成功了

轉(zhuǎn)載于:https://my.oschina.net/springMVCAndspring/blog/1942127

總結(jié)

以上是生活随笔為你收集整理的181. maven项目ssm(父工程 子工程)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。