maven多模塊ssm+freemarker搭建總結(jié)_第1頁
maven多模塊ssm+freemarker搭建總結(jié)_第2頁
maven多模塊ssm+freemarker搭建總結(jié)_第3頁
maven多模塊ssm+freemarker搭建總結(jié)_第4頁
maven多模塊ssm+freemarker搭建總結(jié)_第5頁
已閱讀5頁,還剩41頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、Ssm+maven+freemarker搭建1. 用maven創(chuàng)建多模塊項目1.整個項目的結(jié)構(gòu)|- handsome|-handsome-biz|-handsome-biz-dao數(shù)據(jù)庫層|-handsome-biz-manager業(yè)務(wù)層|-handsome-web|-handsome-web-deploy頁面模板|-handsome-web-home控制層|-handsome-web-war用來運行,打包2.首先創(chuàng)建一個maven項目修改pom.xml文件<project xmlns="/POM/4.0.0" xmlns:

2、xsi="/2001/XMLSchema-instance" xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.handsome</groupId> <artifactId>handsome</artifactId

3、> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging>父項目必須為pom任何一個Maven項目都需要定義POM元素packaging(如果不寫則默認(rèn)值為jar)。顧名思義,該元素決定了項目的打包方式。實際的情形中,如果你不聲明該元素,Maven會幫你生成一個JAR包;如果你定義該元素的值為war,那你會得到一個WAR包;如果定義其值為POM(比如是一個父模塊),那什么包都不會生成 <name>handsome</name> <url>h

4、ttp:/</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</ver

5、sion> <scope>test</scope> </dependency> </dependencies></project>接下來創(chuàng)建的都是該項目的模塊:我理解的模塊是分級的.在本項目中分為兩級 handsome-biz 和handsome-web 是一級. 其他為二級模塊3.創(chuàng)建一級模塊handsome-biz 和handsome-web在handsome項目上新建模塊完成后在handsome中pom.xml文件中可以看到,兩個子模塊修改兩個一級模塊的pom.xml文件的package 為 pom 準(zhǔn)備創(chuàng)建二級模塊將紅框

6、中不需要的刪除, 新增packaing標(biāo)簽4.創(chuàng)建二級模塊在handsome-biz 和 handsome-web下創(chuàng)建 二級模塊創(chuàng)建方法和上面一樣.不在復(fù)述.5.刪除一些不要的目錄和依賴父項目不要依賴. 吧dependencies標(biāo)簽干掉 左側(cè) maven dependencies 目錄就沒有了.Handsome 刪成這樣其他兩個一級模塊也刪到這樣簡潔.6. 添加模塊之間的依賴關(guān)系在handsome-biz-manager中添加對 handsome-biz-dao的依賴在handsome-web-core中添加對handsome-biz-manager的依賴在handsome-web-war

7、中添加對handsome-web-core的依賴最終項目就變成了這樣:2. ssm整合1.將war項目轉(zhuǎn)換成web項目這樣項目就可以添加到tomcat了部署的少了依賴包 2.增加maven依賴到部署3.修改整理pom文件Handsome pom.xml<?xml version="1.0" encoding="UTF-8"?><project xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema

8、-instance" xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd"> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <spring.version>4.0.6.RELEASE</spring.version> <mybatis.vers

9、ion>3.2.7</mybatis.version> <mysql.version>5.1.29</mysql.version> <freemarker.version>2.3.20</freemarker.version> </properties> <modelVersion>4.0.0</modelVersion> <groupId>com.handsome</groupId> <artifactId>handsome</artifactId&

10、gt; <version>0.1</version> <packaging>pom</packaging> <name>handsome</name> <url></url> <modules> <module>handsome-biz</module> <module>handsome-web</module> </modules></project>Handsome-b

11、iz pom.xml<?xml version="1.0" encoding="UTF-8"?><project xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance" xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd

12、"> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <spring.version>4.0.6.RELEASE</spring.version> <mybatis.version>3.2.7</mybatis.version> <mysql.version>5.1.29</mysql.version> <freemarker.version>2.3

13、.20</freemarker.version> </properties> <modelVersion>4.0.0</modelVersion> <groupId>com.handsome</groupId> <artifactId>handsome</artifactId> <version>0.1</version> <packaging>pom</packaging> <name>handsome</name> <

14、url></url> <modules> <module>handsome-biz</module> <module>handsome-web</module> </modules></project>Handsome-biz-dao pom.xml<?xml version="1.0"?><project xsi:schemaLocation="/POM/4

15、.0.0 /xsd/maven-4.0.0.xsd" xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.handsome</groupId> <artifactId>hand

16、some-biz</artifactId> <version>0.1</version> </parent> <artifactId>handsome-biz-dao</artifactId> <name>handsome-biz-dao</name> <dependencies> <!- junit測試包 -> <dependency> <groupId>junit</groupId> <artifactId>junit<

17、;/artifactId> <version>4.11</version> <scope>test</scope> </dependency> <!- mybatis驅(qū)動包 -> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>$mybatis.version</version> </dependency&

18、gt; <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.2.2</version> </dependency> <!- mysql驅(qū)動包 -> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</arti

19、factId> <version>$mysql.version</version> </dependency> <!- dbcp數(shù)據(jù)源 -> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>

20、commons-pool</groupId> <artifactId>commons-pool</artifactId> <version>1.6</version> </dependency> </dependencies> </project>handsome-biz-manager pom.xml<?xml version="1.0"?><project xsi:schemaLocation="/POM

21、/4.0.0 /xsd/maven-4.0.0.xsd" xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.handsome</groupId> <artifactId>ha

22、ndsome-biz</artifactId> <version>0.1</version> </parent> <artifactId>handsome-biz-dao</artifactId> <name>handsome-biz-dao</name> <dependencies> <!- junit測試包 -> <dependency> <groupId>junit</groupId> <artifactId>junit&

23、lt;/artifactId> <version>4.11</version> <scope>test</scope> </dependency> <!- mybatis驅(qū)動包 -> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>$mybatis.version</version> </dependenc

24、y> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.2.2</version> </dependency> <!- mysql驅(qū)動包 -> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</ar

25、tifactId> <version>$mysql.version</version> </dependency> <!- dbcp數(shù)據(jù)源 -> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.4</version> </dependency> <dependency> <groupId&g

26、t;commons-pool</groupId> <artifactId>commons-pool</artifactId> <version>1.6</version> </dependency> </dependencies> </project>handsome-web pom.xml<?xml version="1.0"?><project xsi:schemaLocation="/POM/4.0.0

27、 /xsd/maven-4.0.0.xsd" xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.handsome</groupId> <artifactId>handsome

28、-biz</artifactId> <version>0.1</version> </parent> <artifactId>handsome-biz-dao</artifactId> <name>handsome-biz-dao</name> <dependencies> <!- junit測試包 -> <dependency> <groupId>junit</groupId> <artifactId>junit</ar

29、tifactId> <version>4.11</version> <scope>test</scope> </dependency> <!- mybatis驅(qū)動包 -> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>$mybatis.version</version> </dependency>

30、<dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.2.2</version> </dependency> <!- mysql驅(qū)動包 -> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifact

31、Id> <version>$mysql.version</version> </dependency> <!- dbcp數(shù)據(jù)源 -> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>comm

32、ons-pool</groupId> <artifactId>commons-pool</artifactId> <version>1.6</version> </dependency> </dependencies> </project>Handsome-web-core pom.xml<?xml version="1.0"?><project xsi:schemaLocation="/POM/4.0.0

33、/xsd/maven-4.0.0.xsd" xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.handsome</groupId> <artifactId>handsome-

34、web</artifactId> <version>0.1</version> </parent> <artifactId>handsome-web-core</artifactId> <name>handsome-web-core</name> <dependencies> <dependency> <groupId>com.handsome</groupId> <artifactId>handsome-biz-manager</a

35、rtifactId> <version>$project.version</version> </dependency> <!- freemarker依賴 -> <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> <version>$freemarker.version</version> </dependency> </dep

36、endencies></project>handsome-web-deploy pom.xml<?xml version="1.0"?><project xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd" xmlns="/POM/4.0.0" xmlns:xsi="/2001

37、/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.handsome</groupId> <artifactId>handsome-web</artifactId> <version>0.1</version> </parent> <artifactId>handsome-web-deploy</artifactId> <na

38、me>handsome-web-deploy</name> <packaging>pom</packaging></project>handsome-web-war pom.xml<?xml version="1.0"?><project xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd" xmlns="http:/maven.apa

39、/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.handsome</groupId> <artifactId>handsome-web</artifactId> <version>0.1</version> </parent> &l

40、t;artifactId>handsome-web-war</artifactId> <name>handsome-web-war</name> <packaging>war</packaging> <dependencies> <dependency> <groupId>com.handsome</groupId> <artifactId>handsome-web-core</artifactId> <version>$project.vers

41、ion</version> </dependency> </dependencies></project>4. 編譯項目在上選擇 maven install如果有錯, 整項目部署目錄和web.xml文件完成后可以看到tomcat中的變化依賴包出現(xiàn)了.5.整合思路6. 寫一個簡單功能代碼寫一個簡單功能代碼. 從dao到 manager(service) 到controllerDao層 新建userdao,userdoManager層Controller層 也就是handsome-web-core模塊Handsome-web-deploy 上面詳細(xì)的

42、列出了項目結(jié)構(gòu)和具體代碼7.具體配置Web.xml<?xml version="1.0" encoding="UTF-8" ?><web-app xmlns=" xmlns:xsi="/2001/XMLSchema-instance" xsi:schemaLocation=" version="3.0"><servlet><servlet-name>springmvc</servlet-name><

43、servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring/spring-mvc.xml</param-value></init-param><load-on-startup>1</load-on-startup>

44、;</servlet><servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>/</url-pattern></servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>Handsome-web-war中Config.p

45、roperties#freemarker的配置#handsome.freemarker.templates=E:/eclipse_workspace/ssm_workspace/handsome/handsome-web/handsome-web-deploy/templates#log4j的配置#handsome.loggingRoot=/tmp/Logs/handsomehandsome.loggingLevel=infoSpringmvc.xml<?xml version="1.0" encoding="UTF-8"?><bean

46、s xmlns="/schema/beans" xmlns:xsi="/2001/XMLSchema-instance" xmlns:context="/schema/context" xmlns:mvc="/schema/mvc" xmlns:aop="http:/www.springframewor

47、/schema/aop" xmlns:tx="/schema/tx" xmlns:p="/schema/p" xsi:schemaLocation="/schema/beans /schema/beans/spring-beans-4.0.xsd http:/www.springframework

48、.org/schema/mvc /schema/mvc/spring-mvc-4.0.xsd /schema/context /schema/context/spring-context-4.0.xsd /schema/aop /schema/aop/spring-aop-4.0.xsd http:/www.

49、/schema/tx /schema/tx/spring-tx-4.0.xsd"> <import resource="classpath*:spring/manager-context.xml"/><context:property-placeholder location="classpath:config/perties" ignore-unresolvable="true"/&g

50、t; <!- 掃描controller(controller層注入) -> <context:component-scan base-package="org.handsome.web.controller.*"/> <!- 啟動注解支持 -> <mvc:annotation-driven /> <!- freemarker的配置 -> <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.

51、freemarker.FreeMarkerConfigurer"> <property name="templateLoaderPath" value="file:/$handsome.freemarker.templates" /> <property name="defaultEncoding" value="utf-8" /> <property name="freemarkerSettings"> <props> <p

52、rop key="template_update_delay">10</prop> <prop key="locale">zh_CN</prop> <prop key="datetime_format">yyyy-MM-dd</prop><!- 時間格式化 -> <prop key="date_format">yyyy-MM-dd</prop> <prop key="number_format&qu

53、ot;>#.#</prop> </props> </property> </bean> <!- 視圖配置 在list中按照配置的先后順序 -> <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <property name="ignoreAcceptHeader" value="true" /> <property name=

54、"defaultContentType" value="text/html" /> <property name="mediaTypes"> <map> <entry key="json" value="application/json" /> <entry key="xls" value="application/vnd.ms-excel" /> <entry key="xlsx&qu

55、ot; value="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" /> <entry key="pdf" value="application/pdf" /> </map> </property> <property name="favorParameter" value="false" /> <property name="viewRe

56、solvers"> <list> <!- 配置freeMarker視圖解析器 -> <bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> <property name="cache" value="true" /> <property name="prefix" value="/home/" /> <

57、;!- 上面已經(jīng)配了,這里就不用配啦 -> <property name="suffix" value=".ftl" /> <property name="contentType" value="text/html;charset=UTF-8" /> <property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView"

58、; /> <property name="allowSessionOverride" value="true" /> <property name="allowRequestOverride" value="true" /> <property name="exposeSpringMacroHelpers" value="false" /> <property name="exposeRequestAttributes

59、" value="true" /> <property name="exposeSessionAttributes" value="true" /> <property name="requestContextAttribute" value="request" /> </bean> </list> </property> </bean></beans> Manager-context.xml&l

60、t;?xml version="1.0" encoding="UTF-8" ?><beans xmlns="/schema/beans" xmlns:xsi="/2001/XMLSchema-instance" xmlns:cache="/schema/cache" xmlns:context="http:/www.spring

61、/schema/context" xsi:schemaLocation=" /schema/beans /schema/beans/spring-beans-3.0.xsd /schema/cache /schema/cache/spring-cache-4.2.xsd http:/www.springframework

62、.org/schema/context /schema/context/spring-context-3.0.xsd"><import resource="classpath*:spring/biz-dao-mybatis.xml"/><bean id="userManager" class=".manager.user.impl.UserManagerImpl"></bean> </be

63、ans>Biz-dao-mybatis.xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="/schema/beans" xmlns:xsi="/2001/XMLSchema-instance" xmlns:context="/schema/context" xmlns:aop="/schema/aop" xmlns:tx="/schema/tx" xmlns:p="/schema/p" xsi:schemaL

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論