




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、Ssm+maven+freemarker搭建1. 用maven創(chuàng)建多模塊項(xiàng)目1.整個(gè)項(xiàng)目的結(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用來運(yùn)行,打包2.首先創(chuàng)建一個(gè)maven項(xiàng)目修改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>父項(xiàng)目必須為pom任何一個(gè)Maven項(xiàng)目都需要定義POM元素packaging(如果不寫則默認(rèn)值為jar)。顧名思義,該元素決定了項(xiàng)目的打包方式。實(shí)際的情形中,如果你不聲明該元素,Maven會(huì)幫你生成一個(gè)JAR包;如果你定義該元素的值為war,那你會(huì)得到一個(gè)WAR包;如果定義其值為POM(比如是一個(gè)父模塊),那什么包都不會(huì)生成 <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)建的都是該項(xiàng)目的模塊:我理解的模塊是分級(jí)的.在本項(xiàng)目中分為兩級(jí) handsome-biz 和handsome-web 是一級(jí). 其他為二級(jí)模塊3.創(chuàng)建一級(jí)模塊handsome-biz 和handsome-web在handsome項(xiàng)目上新建模塊完成后在handsome中pom.xml文件中可以看到,兩個(gè)子模塊修改兩個(gè)一級(jí)模塊的pom.xml文件的package 為 pom 準(zhǔn)備創(chuàng)建二級(jí)模塊將紅框
6、中不需要的刪除, 新增packaing標(biāo)簽4.創(chuàng)建二級(jí)模塊在handsome-biz 和 handsome-web下創(chuàng)建 二級(jí)模塊創(chuàng)建方法和上面一樣.不在復(fù)述.5.刪除一些不要的目錄和依賴父項(xiàng)目不要依賴. 吧dependencies標(biāo)簽干掉 左側(cè) maven dependencies 目錄就沒有了.Handsome 刪成這樣其他兩個(gè)一級(jí)模塊也刪到這樣簡(jiǎn)潔.6. 添加模塊之間的依賴關(guān)系在handsome-biz-manager中添加對(duì) handsome-biz-dao的依賴在handsome-web-core中添加對(duì)handsome-biz-manager的依賴在handsome-web-war
7、中添加對(duì)handsome-web-core的依賴最終項(xiàng)目就變成了這樣:2. ssm整合1.將war項(xiàng)目轉(zhuǎn)換成web項(xiàng)目這樣項(xiàng)目就可以添加到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測(cè)試包 -> <dependency> <groupId>junit</groupId> <artifactId>junit<
17、;/artifactId> <version>4.11</version> <scope>test</scope> </dependency> <!- mybatis驅(qū)動(dòng)包 -> <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ū)動(dòng)包 -> <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測(cè)試包 -> <dependency> <groupId>junit</groupId> <artifactId>junit&
23、lt;/artifactId> <version>4.11</version> <scope>test</scope> </dependency> <!- mybatis驅(qū)動(dòng)包 -> <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ū)動(dòng)包 -> <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測(cè)試包 -> <dependency> <groupId>junit</groupId> <artifactId>junit</ar
29、tifactId> <version>4.11</version> <scope>test</scope> </dependency> <!- mybatis驅(qū)動(dòng)包 -> <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ū)動(dòng)包 -> <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. 編譯項(xiàng)目在上選擇 maven install如果有錯(cuò), 整項(xiàng)目部署目錄和web.xml文件完成后可以看到tomcat中的變化依賴包出現(xiàn)了.5.整合思路6. 寫一個(gè)簡(jiǎn)單功能代碼寫一個(gè)簡(jiǎn)單功能代碼. 從dao到 manager(service) 到controllerDao層 新建userdao,userdoManager層Controller層 也就是handsome-web-core模塊Handsome-web-deploy 上面詳細(xì)的
42、列出了項(xiàng)目結(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.*"/> <!- 啟動(dòng)注解支持 -> <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><!- 時(shí)間格式化 -> <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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 公司畫冊(cè)怎樣策劃方案
- 公司新聞播放策劃方案
- 公司百家宴活動(dòng)策劃方案
- 公司組織敬老院活動(dòng)方案
- 2025年移動(dòng)通信工程師考試試題及答案
- 2025年信息檢索與知識(shí)管理考試題及答案
- 2025年生物技術(shù)相關(guān)領(lǐng)域資格考試試卷及答案
- 2025年軟裝設(shè)計(jì)師職業(yè)考試試題及答案
- 2025年青年志愿者能力測(cè)試試卷及答案
- 小學(xué)班主任工作計(jì)劃總結(jié)
- 大麻制品項(xiàng)目建議書
- 楚雄彝族自治州人民醫(yī)院死亡通知暨尸檢建議書
- 建筑垃圾清運(yùn)投標(biāo)方案(技術(shù)標(biāo))
- FREE高考英語核心詞匯1783
- 第4章-汽油機(jī)后處理凈化技術(shù)課件
- 績(jī)效專員崗位月度KPI績(jī)效考核表
- 統(tǒng)計(jì)模型與統(tǒng)計(jì)實(shí)驗(yàn)-南京財(cái)經(jīng)大學(xué)中國(guó)大學(xué)mooc課后章節(jié)答案期末考試題庫2023年
- 小學(xué)語文部編版五年級(jí)下冊(cè)《修改語段》專項(xiàng)練習(xí)
- 2022年07月湖南郴電國(guó)際發(fā)展股份有限公司招聘105名新員工筆試題庫含答案解析
- 三年級(jí)綜合實(shí)踐制作校園提示牌
- 《持輕物擲準(zhǔn)》教案
評(píng)論
0/150
提交評(píng)論