maven多模块ssm+freemarker搭建总结_第1页
maven多模块ssm+freemarker搭建总结_第2页
maven多模块ssm+freemarker搭建总结_第3页
maven多模块ssm+freemarker搭建总结_第4页
maven多模块ssm+freemarker搭建总结_第5页
已阅读5页,还剩41页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Ssm+maven+freemarker搭建1. 用maven创建多模块项目1.整个项目的结构|- handsome|-handsome-biz|-handsome-biz-dao数据库层|-handsome-biz-manager业务层|-handsome-web|-handsome-web-deploy页面模板|-handsome-web-home控制层|-handsome-web-war用来运行,打包2.首先创建一个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(如果不写则默认值为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>接下来创建的都是该项目的模块:我理解的模块是分级的.在本项目中分为两级 handsome-biz 和handsome-web 是一级. 其他为二级模块3.创建一级模块handsome-biz 和handsome-web在handsome项目上新建模块完成后在handsome中pom.xml文件中可以看到,两个子模块修改两个一级模块的pom.xml文件的package 为 pom 准备创建二级模块将红框

6、中不需要的删除, 新增packaing标签4.创建二级模块在handsome-biz 和 handsome-web下创建 二级模块创建方法和上面一样.不在复述.5.删除一些不要的目录和依赖父项目不要依赖. 吧dependencies标签干掉 左侧 maven dependencies 目录就没有了.Handsome 删成这样其他两个一级模块也删到这样简洁.6. 添加模块之间的依赖关系在handsome-biz-manager中添加对 handsome-biz-dao的依赖在handsome-web-core中添加对handsome-biz-manager的依赖在handsome-web-war

7、中添加对handsome-web-core的依赖最终项目就变成了这样:2. ssm整合1.将war项目转换成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驱动包 -> <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驱动包 -> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</arti

19、factId> <version>$mysql.version</version> </dependency> <!- dbcp数据源 -> <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驱动包 -> <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驱动包 -> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</ar

25、tifactId> <version>$mysql.version</version> </dependency> <!- dbcp数据源 -> <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驱动包 -> <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驱动包 -> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifact

31、Id> <version>$mysql.version</version> </dependency> <!- dbcp数据源 -> <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中的变化依赖包出现了.5.整合思路6. 写一个简单功能代码写一个简单功能代码. 从dao到 manager(service) 到controllerDao层 新建userdao,userdoManager层Controller层 也就是handsome-web-core模块Handsome-web-deploy 上面详细的

42、列出了项目结构和具体代码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、;!- 上面已经配了,这里就不用配啦 -> <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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论