1.项目骨架建立

一、使用开发工具IDEA,构建Maven项目,然后调整Maven项目结构,使其成为一个标准的web项目:

  • 此处不选择Maven骨架,直接Next:

  • 输入项目的相关信息,直接Finish

  • 项目构建完成后,选择pom.xml 打包方式为 war

    <packaging>war</packaging>

  • 选择1,建立项目的webapp目录,选择2,在指定目录的WEB-INF下建立web.xml文件:

项目最终构建完成结构层次图:

2.整合SSM + FreeMarker:

一、数据库资源文件配置:

# 数据库配置文件 db.properties
db.username=root
db.password=root
db.url=jdbc:mysql:///meeting?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai

二、Spring配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd"> <!--Spring配置文件,配置注解扫描,使用过滤器不扫描Controller注解-->
<context:component-scan base-package="org.taoguoguo.meeting" use-default-filters="true">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan> <!--加载外部资源-->
<context:property-placeholder location="classpath:db.properties" /> <!--数据源配置-->
<bean class="com.alibaba.druid.pool.DruidDataSource" id="dataSource">
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
<property name="url" value="${db.url}" />
</bean> <!--mybatis配置-->
<bean class="org.mybatis.spring.SqlSessionFactoryBean" id="sqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage" value="org.taoguoguo.meeting.model" />
<!--mapper资源加载多路径配置-->
<property name="mapperLocations">
<array>
<value>classpath:mapper/*Mapper.xml</value>
<value>classpath:org/taoguoguo/meeting/mapper/*Mapper.xml</value>
</array>
</property>
</bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" id="mapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactoryBean" />
<property name="basePackage" value="org.taoguoguo.meeting.mapper" />
</bean> <!--事务配置-->
<!-- 配置事务管理器 -->
<bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="transactionManager">
<property name="dataSource" ref="dataSource" />
</bean> <!--定义属性,声明事务规则 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice> <!--定义切面-->
<aop:config>
<aop:pointcut id="pc1" expression="execution(* org.taoguoguo.meeting.service.*.*(..))"/>
<!-- 将事务增强与切入点组合(织入事务切面) -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="pc1" />
</aop:config> <!--注解方式配置事务
<tx:annotation-driven transaction-manager="transactionManager" />
-->
</beans>

三、SpringMVC配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!--Springmvc配置文件 只扫描Controller注解-->
<context:component-scan base-package="org.taoguoguo.meeting" use-default-filters="true">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan> <!--注解驱动 HandlereMapping & HandlerAdapter-->
<mvc:annotation-driven /> <!--静态资源放行-->
<mvc:resources mapping="/**" location="/" /> <!--加载外部资源文件-->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:freemarker-var.properties</value>
</list>
</property>
</bean> <!--配置模板基本属性-->
<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer" id="freeMarkerConfigurer">
<!--模板文件位置-->
<property name="templateLoaderPath" value="/WEB-INF/ftl/"/>
<!--默认编码格式-->
<property name="defaultEncoding" value="UTF-8" />
<!--全局变量设置-->
<property name="freemarkerVariables">
<map>
<entry key="root" value="${root}" />
</map>
</property>
<!--基本格式配置:时间格式、数字格式-->
<property name="freemarkerSettings">
<props>
<!--模版的缓存时间,单位是s,超过缓存时间则从磁盘加载最新的模版-->
<prop key="template_update_delay">10</prop>
<!--设置默认地区,主要影响数字、日期输出格式,request中没有指定地区时模板查找的值-->
<prop key="locale">zh_CN</prop>
<!--设置日期时间的输出格式。-->
<prop key="datetime_format">yyyy-MM-dd HH:mm:ss </prop>
<!--设置日期的输出格式-->
<prop key="date_format">yyyy-MM-dd</prop>
<!--设置时间的输出格式-->
<prop key="time_format">HH:mm:ss</prop>
<!--设置数字的输出格式-->
<prop key="number_format">#.####</prop>
</props>
</property>
</bean> <!--freemarker视图解析器配置-->
<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<!--视图解析器类-->
<property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
<!--后缀配置-->
<property name="suffix" value=".ftl"/>
<!--设置各种属性覆盖-->
<!--允许重写Request属性-->
<property name="allowRequestOverride" value="true"/>
<!--允许重写Session属性-->
<property name="allowSessionOverride" value="true"/>
<!--设置request Attribute添加到模型-->
<property name="exposeRequestAttributes" value="true"/>
<!--设置session Attribute添加到模型-->
<property name="exposeSessionAttributes" value="true"/>
<!--页面内容类型-->
<property name="contentType" value="text/html;charset=utf-8"/>
</bean> </beans>

四、FreeMarker配置:

##freemarker-var.properties 也可以在mvc配置文件中直接写死
root=/
  1. web.xml配置

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
    version="4.0"> <!--spring配置-->
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener> <!--springmvc配置-->
    <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:spring-servlet.xml</param-value>
    </init-param>
    </servlet>
    <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>
    </servlet-mapping> <!--乱码过滤器配置-->
    <filter>
    <filter-name>encodingFilter</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>
    <init-param>
    <param-name>forceRequestEncoding</param-name>
    <param-value>true</param-value>
    </init-param>
    <init-param>
    <param-name>forceResponseEncoding</param-name>
    <param-value>true</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    </web-app>

最后在指定目录下创建html文件,将后缀改为ftl,然后写一个Controller 请求访问即可。

SSM + Freemarker 开发框架快速搭建的更多相关文章

  1. SSM项目环境快速搭建

    SSM项目的环境搭建 环境搭建的目标 工程创建 创建父工程 创建空 maven工程 xxx-parent 作为父工程 修改父工程中的 pom.xml <!--?xml version=" ...

  2. (转载) android快速搭建项目积累

    android快速搭建项目积累 2016-04-05 20:07 519人阅读 评论(0) 收藏 举报  分类: android优化(8)   Rx技术(5)  版权声明:本文为博主原创文章,未经博主 ...

  3. 快速搭建一个SSM框架demo

    我之所以写一个快速搭建的demo,主要想做一些容器的demo,所以为了方便大家,所以一切从简,简单的3层架构 先用mysql的ddl,后期不上oracle的ddl ; -- ------------- ...

  4. windows下如何快速搭建web.py开发框架

    在windows下如何快速搭建web.py开发框架 用Python进行web开发的话有很多框架供选择,比如最出名的Django,tornado等,除了这些框架之外,有一个轻量级的框架使用起来也是非常方 ...

  5. 快速搭建ssm框架

    快速搭建SSM框架 因为最近有很多朋友问我自己的项目搭建的不够完善,并且经常出现一些小问题,那么今天我又整理了一下文档教大家如何快速搭建SSM框架我是用 eclipse搭建的,如果想用idear的话我 ...

  6. 在windows下如何快速搭建web.py开发框架

    在windows下如何快速搭建web.py开发框架 用Python进行web开发的话有很多框架供选择,比如最出名的Django,tornado等,除了这些框架之外,有一个轻量级的框架使用起来也是非常方 ...

  7. 使用Springboot快速搭建SSM框架

    Spring Boot设计目的是用来简化Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置. 一.环境准备 Idea 2017 或 201 ...

  8. 快速搭建springboot框架以及整合ssm+shiro+安装Rabbitmq和Erlang、Mysql下载与配置

    1.快速搭建springboot框架(在idea中): file–>new project–>Spring Initializr–>next–>然后一直下一步. 然后复制一下代 ...

  9. EpiiAdmin 开源的php交互性管理后台框架, 让复杂的交互变得更简单!Phper快速搭建交互性平台的开发框架,基于Thinkphp5.1+Adminlte3.0+Require.js。

    EpiiAdmin EpiiAdmin php开源交互性管理后台框架,基于Thinkphp5.1+Adminlte3.0+Require.js, 让复杂的交互变得更简单!Phper快速搭建交互性平台的 ...

  10. SSM(SpringMVC+Spring+MyBatis)三大框架使用Maven快速搭建整合(实现数据库数据到页面进行展示)

    本文介绍使用SpringMVC+Spring+MyBatis三大框架使用Maven快速搭建一个demo,实现数据从数据库中查询返回到页面进行展示的过程. 技术选型:SpringMVC+Spring+M ...

随机推荐

  1. python中dict和list的数据结构

    要理解dict的有关内容需要你理解哈希表(map)的相关基础知识,这个其实是<算法与数据结构>里面的内容. 1.list和tuple其实是用链表顺序存储的,也就是前一个元素中存储了下一个元 ...

  2. CF1137C 题解

    考虑把每个点进行拆成 \(d\) 个点表示星期几走到这个点,那么原图上的边 \((u,v)\) 就被拆成\((pos_{u,i},pos_{v,i+1})\) 表示星期的变化. 然后考虑进行缩点,在一 ...

  3. 谈谈你对 Vue 生命周期的理解?

    生命周期是什么? Vue 实例有一个完整的生命周期,也就是从 开始创建.初始化数据.编译模版.挂载 Dom -> 渲染.更新 -> 渲染.卸载等一系列过程,我们称这是 Vue 的生命周期. ...

  4. Java 面向对象编程之接口

    什么是接口? 是抽象方法的集合,接口通常以interface来声明,一个类通过继承接口的方式,从而来继承接口的抽象方法 语法 interface 名称 [extends 其他的接⼝名] { // 声明 ...

  5. linux信号机制(初识版)

    转载 https://www.zhihu.com/question/24913599/answer/2584544572 信号是操作系统内核为我们提供用于在进程间通信的机制,内核可以利用信号来通知进程 ...

  6. my-http-server 静态服务器源码学习实现缓存及压缩

    目录 一.准备工作及流程说明 二.配置命令行 三.设置入口文件和渲染模板 四.my-http-server源码 一.准备工作及流程说明 一看这标题,大家可能一下子没有反应过来,到底是要干什么?那么就先 ...

  7. 学习笔记--Java中static关键字

    Java中static关键字 static基础用法 什么时候成员变量声明为实例变量 所有对象的这个属性随对象而变化 什么时候成员变量声明为静态变量 所有对象都是这个属性 静态变量在类加载的时候初始化, ...

  8. Nginx $remote_addr和$proxy_add_x_forwarded_for变量详解

    $remote_addr 代表客户端IP.注意,这里的客户端指的是直接请求Nginx的客户端,非间接请求的客户端.假设用户请求过程如下: 用户客户端--发送请求->Nginx1 --转发请求-- ...

  9. java srpint boot 2.2.1 第二部份,乐观锁机制, 构造复杂查询条件,分页查询 相关内容,删除与软删除

    第二部份,引起锁机制的原理和解决方案: 测试环境搭建第一步先建一个数据库表用于模拟商品购买. CREATE TABLE product ( id INT AUTO_INCREMENT PRIMARY ...

  10. 关于RuntimeException与事务

    1.spring的默认回滚策略 当采用@Transactional注解方法抛出RuntimeException时,spring会默认回滚事务 对于检查型异常(即不是RuntimeException子类 ...