SSM整合

 整合思路

1、Dao层:

Mybatis的配置文件:SqlMapConfig.xml

不需要配置任何内容,需要有文件头。文件必须存在。

applicationContext-dao.xml

mybatis整合spring,通过由spring创建数据库连接池,spring管理SqlSessionFactorymapper代理对象。需要mybatisspring的整合包。

2、Service层:

applicationContext-service.xml

所有的service实现类都放到spring容器中管理。并由spring管理事务。

 

3、表现层:

Springmvc框架,由springmvc管理controller

Springmvc的三大组件。

1.1. Dao整合

1.1.1. 创建SqlMapConfig.xml配置文件


PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">










 

1.1.2. Spring整合mybatis

创建applicationContext-dao.xml


xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">






destroy-method="close">

















db.properties

jdbc.driver=com.mysql.jdbc.Driver

jdbc.url=jdbc:mysql://localhost:3306/e3mall?characterEncoding=utf-8

jdbc.username=root

jdbc.password=root

 

 

备注:

Druid是目前最好的数据库连接池,在功能、性能、扩展性方面,都超过其他数据库连接池,包括DBCPC3P0BoneCPProxoolJBoss DataSource

Druid已经在阿里巴巴部署了超过600个应用,经过多年多生产环境大规模部署的严苛考验。

 

1.2. Service整合

1.2.1. 管理Service




	
	
	
	
	
	
	
	
	
	
	
	

 

1.2.2. 事务管理

创建applicationContext-trans.xml


xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">




















pointcut="execution(* cn.e3mall.service..*.*(..))" />

 

1.3. 表现层整合

1.3.1. Springmvc.xml


xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" 
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
        http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">







class="org.springframework.web.servlet.view.InternalResourceViewResolver">







class="org.springframework.web.multipart.commons.CommonsMultipartResolver">














 

1.3.2. Web.xml

xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns="http://java.sun.com/xml/ns/javaee"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

id="WebApp_ID" version="2.5">

<display-name>e3-managerdisplay-name>

<welcome-file-list>

<welcome-file>index.jspwelcome-file>

welcome-file-list>

<context-param>

<param-name>contextConfigLocationparam-name>

<param-value>classpath:spring/applicationContext*.xmlparam-value>

context-param>

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>

listener>

<filter>

<filter-name>CharacterEncodingFilterfilter-name>

<filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>

<init-param>

<param-name>encodingparam-name>

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

init-param>

filter>

<filter-mapping>

<filter-name>CharacterEncodingFilterfilter-name>

<url-pattern>/*url-pattern>

filter-mapping>

 

 

<servlet>

<servlet-name>e3-managerservlet-name>

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

<init-param>

<param-name>contextConfigLocationparam-name>

<param-value>classpath:spring/springmvc.xmlparam-value>

init-param>

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

servlet>

<servlet-mapping>

<servlet-name>e3-managerservlet-name>

<url-pattern>/url-pattern>

servlet-mapping>

web-app>















你可能感兴趣的:(SSM整合)