关于ssm框架的整合步骤

来源:互联网 发布:渔趣网有淘宝店吗 编辑:程序博客网 时间:2024/06/05 11:50

关于

ssm

框架的整合步骤

 

1.

什么是

ssm

 

ssm

指的是

springmvc+spring+mybatis,

而且这个组合框架是基于

mvc

架构

的。

Springmvc

是做控制层的,

spring

在此中是用来管理业务逻辑层的,

mybatis

是用来做

dao

层的。而架构

mvc

中的

m

指的是

model

,其中包含

service

dao

以及

javabean(pojo),

其中

v

指的是视图

其中的

c

指的是

controller(handler). 

 

 

2.

导入的

jar

 

 

3.ssm

框架配置步骤

 

1.

web.xml

文件开始

 

不管你用的什么框架,如果你使用的是

Tomcat

作为服务器,都需要在

web.xml

中配置一个入口,开启使用的框架,故此,我们先从

web.xml

文件中开

始配置

Spring

springmvc

mybatis

依附的对象。

 

web.xml

中配置

spring

监听器,配置如下:

 

 

<!--

这个上下文全局参数是给

spring

监听器使用的

--> 

<context-param> 

<param-name>contextConfigLocation</param-name> 

<param-value>classpath:application-context.xml</param-value> 

</context-param> 

<!--spring

监听器

--> 

<listener> 

<listener-class> 

org.springframework.web.context.ContextLoaderListener 

</listener-class> 

</listener> 

 

web.xml

中配置

springmvc

的前端控制器

(

中央处理器

),

配置如下:

 

 

<servlet> 

<servlet-name>springmvc</servlet-name> 

<servlet-class>org.springframework.web.servlet.DispatcherServl

et</servlet-class> 

<init-param> 

<param-name>

contextConfigLocation

</param-name> 

<param-value>classpath:springmvc.xml</param-value> 

</init-param> 

<!--

加载

web.xml

配置文件的时候立即实例化

--> 

<load-on-startup>1</load-on-startup> 

</servlet> 

 

<servlet-mapping> 

<servlet-name>springmvc</servlet-name> 

<!--/*:

 

 

 

/WEB-INF/jsp/item.jsp 

    /:

 

 

 

.css .js .doc ... 

*.do:

拦截

.do

后缀的请求

--> 

<url-pattern>*.do</url-pattern> 

</servlet-mapping> 

 

web.xml

中配置请求时中文乱码过滤器

,

配置如下:

 

 

<filter> 

<filter-name>encoding</filter-name> 

<filter-class>

org.springframework.web.filter.CharacterEncodingFilter

</filte

r-class> 

<init-param> 

<param-name>

encoding

</param-name> 

<param-value>utf-8</param-value> 

</init-param> 

</filter> 

 

<filter-mapping> 

<filter-name>encoding</filter-name> 

<url-pattern>*.do</url-pattern> 

</filter-mapping> 

 

2.

application-context.xml

中的配置

 

<!--

所有的配置文件从这里导入

--> 

<import resource=

config/*.xml

/> 

 

3.

config

包中的

jdbc.xml 

<!--

配置

c3p0

连接池

--> 

<bean id=

dataSource

 

class=

com.mchange.v2.c3p0.ComboPooledDataSource

<property  name=

driverClass

  value=

${driverClass}

/> 

<property  name=

jdbcUrl

  value=

${jdbcUrl}

/> 

<property  name=

user

  value=

${user}

/> 

<property  name=

password

  value=

${password}

/> 

</bean> 

 

4.

config

包中的

property.xml 

<!--

读取

jdbc.properties

文件

--> 

<!--

这种写法不利于扩展

--> 

<context:property-placeholder 

location=

classpath:jdbc.properties

/> 

 

使用下面这种配置,有利于扩展

 

 

 

 

 

 

<bean 

class=

”org.springframework.beans.factory.config.PropertyPlaceholderC

onfigurer”

<property name=

locations

<list> 

<value>classpath:jdbc.properties</value> 

</list> 

</property> 

</bean> 

 

0 0
原创粉丝点击