聪明文档网

聪明文档网

最新最全的文档下载
当前位置: 首页> SSM三大框架的整合(技术学习)

SSM三大框架的整合(技术学习)

时间:    下载该word文档

SSM三大框架的整合
Spring+SpringMVC+MyBatis
1123SSMSSMSSM
目录
SSM三大框架的整合(Spring+SpringMVC+MyBatis............11、基本概念...........................................21.1Spring........................................21.2SpringMVC.....................................21.3MyBatis.......................................22、整合步骤...........................................32.1Maven引入需要的JAR.........................32.2SpringMyBatis的整合........................92.3、整合SpringMVC................................20补充一...............................................30配置实例演示.........................................40
互联网络


1、基本概念
1.1Spring
SpringSpring2003JavaRodJohnson
ExpertOne-On-OneJ2EEDevelopmentandDesignSpring使JavaBeanEJBSpringJavaSpringSpring转(IoC)和AOP
1.2SpringMVC
SpringMVCSpringFrameWork
SpringWebFlowSpringMVC
1.3MyBatis
MyBatisapacheiBatis,2010apachesoftwarefoundationgooglecodeMyBatisMyBatisJavaiBATISSQLMapsDataAccessObjectsDAOMyBatisJDBCMyBatis使XMLJavaPOJOsPlainOldJavaObjectsJava2

http://blog.csdn.net/zhshulin/article/details/30779873
互联网络


3MavenWeb
http://blog.csdn.net/zhshulin/article/details/379217054SSM
2spring-mybatis.xmlspringmybatisspring-mvc2jdbc.propertislog4j.properties

使Spring4.0.2RELEASESpringMVC4.0.2RELEASEMyBatis3.2.6
2、整合步骤
2.1Maven引入需要的JAR
互联网络


便JARJAR,这JAR,每,就pom.xml

-->


junit
junit4.11

4.0.2.RELEASE
3.2.6
1.7.71.2.17


test


org.springframeworkspring-core${spring.version}

互联网络





org.springframeworkspring-webmvc${spring.version}


org.springframeworkspring-jdbc${spring.version}


org.springframeworkspring-web${spring.version}

org.springframeworkspring-oxm${spring.version}

org.springframeworkspring-tx${spring.version}



互联网络



互联网络


org.springframeworkspring-aop${spring.version}



org.springframework
spring-context-support

${spring.version}



org.springframeworkspring-test${spring.version}


org.mybatismybatis${mybatis.version}


org.mybatis
mybatis-spring1.2.2







javax
javaee-api7.0


mysql
mysql-connector-java

5.1.30




commons-dbcp
commons-dbcp1.2.2

jstl
jstl1.2


log4j
log4j
互联网络



互联网络

${log4j.version}


com.alibabafastjson1.1.41



org.slf4j
slf4j-api${slf4j.version}



org.slf4j
slf4j-log4j12${slf4j.version}

org.codehaus.jackson
jackson-mapper-asl

1.9.13





commons-fileupload
commons-fileupload

1.3.1

commons-io
commons-io2.4

commons-codec
commons-codec1.9




2.2SpringMyBatis的整合
JAR,首SpringMyBatis,然JUnit
互联网络



2.2.1、建立JDBC属性文件
jdbc.propertiesutf-8
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://10.221.10.111:8080/db_zslusername=demaopassword=demao#initialSize=0#maxActive=20#maxIdle=20#minIdle=1#maxWait=60000
互联网络




2.2.2、建立spring-mybatis.xml配置文件
springmybatis。这,主,自,配。注,大spring-mybatis.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/c
ontext"
xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/sch
ema/beans

http://www.springframework.org/schema/beans/spring-beans-3.1.xsd

http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd

http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">


互联网络




class="org.springframework.beans.factory.config.Proper
tyPlaceholderConfigurer">


value="classpath:jdbc.properties"/>

class="org.apache.commons.dbcp.BasicDataSource"

destroy-method="close">

value="${driver}"/>




value="${initialSize}">


value="${maxActive}">


value="${maxIdle}">


value="${minIdle}">


value="${maxWait}">
互联网络




-->

value="classpath:com/cn/hnust/mapping/*.xml">

class="org.mybatis.spring.mapper.MapperScannerConfigurer">


value="com.cn.hnust.dao"/>


value="sqlSessionFactory">

class="org.springframework.jdbc.datasource.DataSourceT
ransactionManager">





互联网络



2.2.3Log4j的配置
便使Log4jApache,通使Log4j,我GUINTUNIXSyslog;我;通
Log4jLog4j
http://blog.csdn.net/zhshulin/article/details/37937365

log4j.properties
#LOG
log4j.rootLogger=INFO,Console,File#
log4j.appender.Console=org.apache.log4j.ConsoleAppenderlog4j.appender.Console.Target=System.out#
log4j.appender.Console.layout=org.apache.log4j.PatternLayoutlog4j.appender.Console.layout.ConversionPattern=[%c]-%m%n
#
互联网络


log4j.appender.File=org.apache.log4j.RollingFileAppender#
log4j.appender.File.File=logs/ssm.log#
log4j.appender.File.MaxFileSize=10MB
#DEBUGDEBUGlog4j.appender.File.Threshold=ALL
log4j.appender.File.layout=org.apache.log4j.PatternLayoutlog4j.appender.File.layout.ConversionPattern=[%p][%d{yyyy-MM-ddHH\:mm\:ss}][%c]%m%n


2.2.4JUnit测试
4.2.2log4j),我Springmybatis
2.2.4.1、创建测试用表
,那,这SQL
DROPTABLEIFEXISTS`user_t`;
CREATETABLE`user_t`(
`id`int(11NOTNULLAUTO_INCREMENT,`user_name`varchar(40NOTNULL,`password`varchar(255NOTNULL,`age`int(4NOTNULL,PRIMARYKEY(`id`
ENGINE=InnoDBAUTO_INCREMENT=2DEFAULTCHARSET=utf8;
互联网络


/*Dataforthetable`user_t`*/
insertinto`user_t`(`id`,`user_name`,`password`,`age`values(1,'','sfasgfaf',24;


2.2.4.2、利用MyBatisGenerator自动创建代码
http://blog.csdn.net/zhshulin/article/details/23912615
MyBatisDAO,当IUserDaoUserMapper

2.2.4.3、建立Service接口和实现类

互联网络



IUserService.jave
packagecom.cn.hnust.service;
importcom.cn.hnust.pojo.User;
publicinterfaceIUserService{}
publicUsergetUserById(intuserId;

UserServiceImpl.java
packagecom.cn.hnust.service.impl;
importjavax.annotation.Resource;
importorg.springframework.stereotype.Service;
互联网络


importcom.cn.hnust.dao.IUserDao;importcom.cn.hnust.pojo.User;
importcom.cn.hnust.service.IUserService;
@Service("userService"
publicclassUserServiceImplimplementsIUserService{}
@Resource
privateIUserDaouserDao;@Override
publicUsergetUserById(intuserId{}
//TODOAuto-generatedmethodstub
returnthis.userDao.selectByPrimaryKey(userId;


2.2.4.4、建立测试类
src/test/java使Spring使Spring使,然service,就
SpringMybatis使Log4j
packageorg.zsl.testmybatis;
importjavax.annotation.Resource;
互联网络



importorg.apache.log4j.Logger;importorg.junit.Before;importorg.junit.Test;
importorg.junit.runner.RunWith;
importorg.springframework.context.ApplicationContext;import
org.springframework.context.support.ClassPathXmlApplicationContext;
importorg.springframework.test.context.ContextConfiguration;import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
importcom.alibaba.fastjson.JSON;importcom.cn.hnust.pojo.User;
importcom.cn.hnust.service.IUserService;
@RunWith(SpringJUnit4ClassRunner.classSpringJUnit4ClassRunner
@ContextConfiguration(locations={"classpath:spring-mybatis.xml"}
publicclassTestMyBatis{
privatestaticLoggerlogger=
//
Logger.getLogger(TestMyBatis.class;//////
互联网络
privateApplicationContextac=null;@Resource
privateIUserServiceuserService=null;
@Before
publicvoidbefore({


//ac=new
ClassPathXmlApplicationContext("applicationContext.xml";//

userService=(IUserService
ac.getBean("userService";//}
@Test
publicvoidtest1({}
Useruser=userService.getUserById(1;//System.out.println(user.getUserName(;//logger.info(""+user.getUserName(;logger.info(JSON.toJSONString(user;
}




,完Springmybatis,下SpringMVC
2.3、整合SpringMVC
2SpringMVCweb.xml
互联网络


2.3.1、配置spring-mvc.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/c
ontext"
xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/sch
ema/beans

http://www.springframework.org/schema/beans/spring-beans-3.1.xsd

http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd

http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">


base-package="com.cn.hnust.controller"/>
class="org.springframework.http.converter.json.Mapping
JacksonHttpMessageConverter">
互联网络







text/html;charset=UTF-8





class="org.springframework.web.servlet.mvc.annotation.
AnnotationMethodHandlerAdapter">











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






互联网络




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





互联网络



2.3.2、配置web.xml文件
spring-mybatis.xmlspring-mvcServletSSM2
web.xml

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_3_0.xsd"
version="3.0">
ArchetypeCreatedWeb
Application
>
org.springframework.web.filter.Character
EncodingFilter


true

encodingFilter
classpath:spring-mybatis.xml
contextConfigLocation
互联网络





encodingUTF-8



encodingFilter/*

org.springframework.web.context.Contex
tLoaderListener

org.springframework.web.util.Introspec
torCleanupListener

org.springframework.web.servlet.Dispatc
herServlet

互联网络




SpringMVC


contextConfigLocation
classpath:spring-mvc.xml





1true


SpringMVC
/

/index.jsp




2.3.3、测试
SSM,如,继,作BUG
互联网络


2.3.3.1、新建jsp页面

showUser.jsp
<%@pagelanguage="java"import="java.util.*"pageEncoding="utf-8"%>

</word><wordclass='19_1'>测</word><wordclass='19_1'>试</word><wordclass='15_1'>


${user.userName}


2.3.3.2、建立UserController
UserController.java
packagecom.cn.hnust.controller;
互联网络


importjavax.annotation.Resource;
importjavax.servlet.http.HttpServletRequest;
importorg.springframework.stereotype.Controller;importorg.springframework.ui.Model;
importorg.springframework.web.bind.annotation.RequestMapping;
importcom.cn.hnust.pojo.User;
importcom.cn.hnust.service.IUserService;
@Controller
@RequestMapping("/user"publicclassUserController{
@Resource
privateIUserServiceuserService;
@RequestMapping("/showUser"
publicStringtoIndex(HttpServletRequestrequest,Model
model{

intuserId=
Integer.parseInt(request.getParameter("id";}
}
Useruser=this.userService.getUserById(userId;model.addAttribute("user",user;return"showUser";


互联网络


2.3.3.3、部署项目
localhost:8080//user/showUser?id=1

SSM
互联网络



补充一
1.所需要Jar.
//Spring3.0.1
org.springframework.web-3.0.1系列//公共包
slf4j-api-1.5.6.jarslf4j-log4j12-1.5.6.jarlog4j-1.2.13.jar
commons-logging-1.1.1.jarasm-3.1.jarcglib-2.2.jar
//mybatisSpring的整合所需的包
mybatis-3.0.5.jar
aopalliance-1.0.jar
mybatis-spring-1.0.1.jar
mybatis-generator-core-1.3.1.jar(mybatis代码生成器包
//jdbcdriven
mysql-connector-java-3.1.6-bin.jar
//JSR验证-Hibernatevalidate4.1
hibernate-validator-4.1.0.Final.jar
validation-api-1.0.0.GA.jar
//SpringJson支持包
jackson-all-1.8.1.jar
互联网络



2.web.xml配置

Servlet配置
org.springframework.web.servlet.DispatcherServlet
init-param配置servlet初始化文件.
以及servlet-mapping配置.
应用路径配置
webAppRootKey
Log4j配置
Log4jConfigLocation
Log4jRefreshInterval
Spring上下文配置
contextConfigLocation
Spring字符集过滤器配置
org.springframework.web.filter.CharacterEncodingFilter
Spring监听器配置
org.springframework.web.context.ContextLoaderListener
log4j监听器配置
org.springframework.web.util.Log4jConfigListener
互联网络



3.springmvc-servlet.xml配置

启动mvc注解驱动

组件scanner主要是自动去注入指定包里的对象

base-package="com.los.mvc.controller"/>
ViewResolver&View映射关系
InternalResourceViewResolver基于resourcejsp/jstl的支持





value="org.springframework.web.servlet.view.JstlView">

自定义拦截器配置



.MyInterceptor">

互联网络
name="viewClass"




国际化配置


id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
4.Spring上下文--applicationContext.xml配置

支持注解
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">



service.xmldao.xml配置@service@Repository
5.Mybatis3.0.5-Spring整合--orm.xml

DataSource配置
互联网络



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





注册事务管理器(Mybatis将事务转交给Spring来管理


SqlSessionFactory配置(Mybatis核心是sqlSessionFactory来获取orm处理对象,dataSource,mapperLocations配置mybaits自动生成的xml文件.就是注入映射关系.




MapperScanner配置.自动去搜索mapper里的对象,并注入.
.MapperScannerConfigurer">


互联网络
id="dataSource"
id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">



启动Spring注解事务

6.mybatis自动生成器配置--generatorConfig.xml

sqlMapGeneratorsqlMpper.xml生成器
javaClientGeneratorModelDao生成器
javaModelGeneratorModel生成器
com.los.util.MBG.java运行会自动生成mybatis代码.然后再配置orm.xml
7.Controller层配置
类注解
@Controller
@RequestMapping("/json"为访问该层的路径.
方法注解
@RequestMapping(method=RequestMethod.GET只有get方法才能访问.
@ResponseBody自动将返回的封装成json,方法返回值必须是map类型.
@RequestMapping(value="/doLogin"value=”doLogin”为访问该方法的handlermapping
return"login/login";会通过ViewResolver找到对应的view
return"redirect:/user/toRegister.html";spring-mvc的重定向.
互联网络


@InitBinder(为绑定器,可以为request传来的数据进行数据类型转换.
数据自动验证
方法中参数需要有后面的两个(@ValidUseruser,BindingResultresult.@Valid的支持标准是JSR,HibernateValidate4是对该标准比较好的实现.需要在Model类中配置验证的注解.判断验证是否正确通过result.hasErrors(或者result.hasFieldErrors(来判断,通过result.getAllErrors(result.getFieldErrors(ErrorsErrors,Error.getDeafaultMessage(,这个是获取错误信息.具体的错误验证机制还地在Model类中配置.
属性注解
@Autowired会为该属性自动注入bean,默认方式是byType.也可以用@Resource这个注解默认byName.
8.Service层配置.(业务层
类注解
@Service@Component的子注解,分工更明细.
@Transactional可以为该业务类声明一个全类的事务.也可以将事务写在方法上.根据不同的需.
方法注解
@Transactional(readOnly=true
@Transactional(readOnly=false,propagation=Propagation.REQUIRED,rollbackFor=Exception.class类的事务声明,可以设置隔离级别和传播属性,以及要回滚的异常名或者异常类,不需要回滚的异常名或者异常类.异常通常抛出给controller层来处理
互联网络


属性注解
@Autowired@Resource
互联网络



9.Repository层配置.(持久层DaoImpl
类注解
@Repository@Component的子注解,意为持久层,分工更明细.一般不在这层处理事务.
10.Entry层配置(Model
类注解@Entry
验证注解,常用的有:
@NotEmpty
@NotNull
@Size(min=2,max=10,message=”xx必须在{min}{max}之间@Email
@DecimalMax
@AssertFalse@AssertTrue@Null@Valid
@URL(protocol=,host=,port=,regexp=,flags=
一般情况下属性或者方法可以放多个约束注解,hibernatevalidate会以随机的顺序去验证这些约.所以多个注解约束会有可能同一个属性返回多个message.所以有时候需要只返回一条message,则需要使用验证组Groups来达成.组别序列可以把一系列的组别按照一定的顺序排列在一起,然后逐个验证,只要有一个组别验证失败,就不继续验证剩余的组别。
互联网络


@GroupSequence({User.class,GroupB.class,GroupC.class}验证组的顺序,约束里不指定group的为默认的User.class.
约束组放在类前,User.class为默认的约束组,GroupB,GroupC为空的接口.写在User外同个java文件下.
@NotEmpty(message="密码不能为空"
@Size(min=4,max=20,message="{min}-{max}",groups=GroupB.class
如果@NotEmpty验证失败了,就不会继续验证@Size
互联网络



配置实例演示
最近做了个maven管理的springmvc+spring+mybatis,还用到了阿里巴巴的fastjsondruid连接池,配置文件如下pom.xml文件
[html]viewplaincopy

1.version="1.0"encoding="UTF-8"?>
2.xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.
org/2001/XMLSchema-instance"
3.xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apach
e.org/maven-v4_0_0.xsd">
4.4.0.05.com.dahafo.demo6.um
7.war
8.1.0.0-BUILD-SNAPSHOT9.
10.1.7
11.3.2.3.RELEASE
ion>
12.1.6.1013.1.6.614.
15.16.17.
18.org.springframework19.spring-context
20.${org.springframework-version}21.
22.23.
24.commons-logging25.commons-logging26.
27.
28.
互联网络


29.
30.org.springframework31.spring-webmvc
32.${org.springframework-version}33.
34.
35.org.springframework36.spring-jdbc
37.${org.springframework-version}38.
39.
40.41.
42.org.aspectj43.aspectjrt44.${org.aspectj-version}45.
46.
47.48.
49.org.slf4j50.slf4j-api51.${org.slf4j-version}52.
53.
54.org.slf4j
55.jcl-over-slf4j56.${org.slf4j-version}57.runtime58.
59.
60.org.slf4j
61.slf4j-log4j1262.${org.slf4j-version}63.runtime64.
65.
66.log4j67.log4j68.1.2.1569.70.
71.javax.mail
互联网络


72.mail73.
74.
75.javax.jms76.jms77.
78.
79.com.sun.jdmk80.jmxtools81.
82.
83.com.sun.jmx84.jmxri85.
86.

87.runtime88.
89.
90.91.
92.javax.inject93.javax.inject94.195.
96.
97.98.
99.javax.servlet100.servlet-api101.2.5102.provided103.
104.
105.javax.servlet.jsp106.jsp-api107.2.1108.provided109.
110.
111.javax.servlet112.jstl113.1.2114.

互联网络


115.116.
117.org.mybatis118.mybatis119.3.2.1120.
121.
122.org.mybatis
123.mybatis-spring124.1.2.0125.
126.
127.mysql
128.mysql-connector-java129.5.1.26130.
131.132.133.
134.135.
136.junit137.junit138.4.7139.test140.
141.
142.com.alibaba143.druid144.0.2.20145.
146.
147.
148.org.aspectj
149.aspectjweaver150.1.7.2151.
152.
153.com.alibaba154.fastjson155.1.1.34156.
157.
互联网络


158.com.fasterxml.jackson.core159.jackson-core160.2.2.2161.
162.
163.com.fasterxml.jackson.core164.jackson-databind165.2.2.2166.
167.
168.commons-fileupload169.commons-fileupload170.1.2.2171.
172.
173.174.175.176.177.178.179.180.181.182.183.184.
185.maven-eclipse-plugin186.2.9187.
188.
189.org.springframework.ide.eclipse.core
.springnature

190.
191.
192.org.springframework.ide.eclipse.core.
springbuilder

193.

194.true195.true196.
197.
198.
互联网络


199.org.apache.maven.plugins200.maven-compiler-plugin201.2.5.1202.
203.1.6204.1.6
205.-Xlint:all206.true207.true208.
209.
210.
211.org.codehaus.mojo212.exec-maven-plugin213.1.2.1214.
215.org.test.int1.Main216.
217.
218.
219.

220.demo-um221.

web.xml
[html]viewplaincopy

1.version="1.0"encoding="UTF-8"?>
2.version="2.5"xmlns="http://java.sun.com/xml/ns/javaee"3.xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4.xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.co
m/xml/ns/javaee/web-app_2_5.xsd">5.6.7.
8.9.
10.contextConfigLocation
11./WEB-INF/spring/root-context.xml12.

13.
互联网络


14.
15.encodingFilter
16.org.springframework.web.filter.CharacterEncodingFi
lter
17.
18.encoding19.UTF-820.
21.
22.forceEncoding23.true24.
25.

26.
27.encodingFilter28./*29.

30.

31.
32.org.springframework.web.context.ContextLoaderListene
r
33.
34.
35.36.37.
38.39.
40.appServlet
41.org.springframework.web.servlet.DispatcherServlet
rvlet-class>
42.
43.contextConfigLocation
44./WEB-INF/spring/appServlet/servlet-context.xml
am-value>
45.

46.147.
48.
49.
50.appServlet51./
互联网络


52.
53.
54.
root-context.xmlspring的主配置文件
[html]viewplaincopy

1.version="1.0"encoding="UTF-8"?>
2.xmlns="http://www.springframework.org/schema/beans"3.xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4.xmlns:context="http://www.springframework.org/schema/context"
5.xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://w
ww.springframework.org/schema/beans/spring-beans.xsd
6.http://www.springframework.org/schema/contexthttp://www.springframework
.org/schema/context/spring-context-3.0.xsd7.">
8./>
9.base-package="com.dahafo.demo.um"/>10.resource="spring-mybatis.xml"/>11.

servlet-context.xmlspringmvc的主配置文件
[html]viewplaincopy

1.version="1.0"encoding="UTF-8"?>
2.xmlns="http://www.springframework.org/schema/mvc"3.xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"4.xmlns:beans="http://www.springframework.org/schema/beans"5.xmlns:context="http://www.springframework.org/schema/context"
6.xsi:schemaLocation="http://www.springframework.org/schema/mvchttp://www
.springframework.org/schema/mvc/spring-mvc.xsd
7.http://www.springframework.org/schema/beanshttp://www.springframewo
rk.org/schema/beans/spring-beans.xsd
8.http://www.springframework.org/schema/contexthttp://www.springframe
work.org/schema/context/spring-context.xsd">9.
10.11.
12.13./>
14.base-package="com.dahafo.demo.um.controller"/>

互联网络


15.
16.17.mapping="/resources/**"location="/resources/"/>18.mapping="/css/**"location="/css/"/>19.mapping="/images/**"location="/images/"/>20.mapping="/js/**"location="/js/"/>21.
22.
23.id="mappingJacksonHttpMessageConverter"class="org.springfra
mework.http.converter.json.MappingJackson2HttpMessageConverter"/>24.
25.id="fastJsonHttpMessageConverter"class="com.alibaba.fastjs
on.support.spring.FastJsonHttpMessageConverter"/>
26.class="org.springframework.web.servlet.mvc.annotation.Annota
tionMethodHandlerAdapter">
27.name="messageConverters">28.
29.bean="fastJsonHttpMessageConverter"/>
30.
31.32.
33.
34.class="org.springframework.web.servlet.view.InternalResource
ViewResolver">
35.name="prefix"value="/WEB-INF/views/"/>36.name="suffix"value=".jsp"/>37.38.
39.id="maxUploadSize"class="org.springframework.web.multipart.
commons.CommonsMultipartResolver">
40.name="maxUploadSize"value="32505856"/>
41.name="maxInMemorySize"value="4096"/>42.43.44.45.
46.

互联网络


spring-mybatis.xmlmybatis的配置文件,数据源用的是阿里巴巴的druid

[html]viewplaincopy

1.version="1.0"encoding="UTF-8"?>
2.xmlns="http://www.springframework.org/schema/beans"3.xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4.xmlns:context="http://www.springframework.org/schema/context"5.xmlns:tx="http://www.springframework.org/schema/tx"6.xmlns:aop="http://www.springframework.org/schema/aop"
7.xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://w
ww.springframework.org/schema/beans/spring-beans.xsd
8.http://www.springframework.org/schema/contexthttp://www.springframework
.org/schema/context/spring-context-3.0.xsd
9.http://www.springframework.org/schema/txhttp://www.springframework.org
/schema/tx/spring-tx-3.0.xsd
10.http://www.springframework.org/schema/aophttp://www.springframework.org
/schema/aop/spring-aop-3.0.xsd11.">
12.
13.location="classpath:jdbc.properties"/>14.
15.
16.name="dataSource"class="com.alibaba.druid.pool.DruidDataSource"i
nit-method="init"destroy-method="close">17.name="url"value="${url}"/>
18.name="username"value="${username}"/>19.name="password"value="${password}"/>20.name="initialSize"value="1"/>21.name="maxActive"value="20"/>22.name="minIdle"value="1"/>23.name="maxWait"value="60000"/>
24.name="validationQuery"value="${validationQuery}"/>25.name="testOnBorrow"value="false"/>26.name="testOnReturn"value="false"/>27.name="testWhileIdle"value="true"/>
28.name="timeBetweenEvictionRunsMillis"value="60000"/>29.name="minEvictableIdleTimeMillis"value="25200000"/>30.name="removeAbandoned"value="true"/>31.name="removeAbandonedTimeout"value="1800"/>32.name="logAbandoned"value="true"/>33.name="filters"value="mergeStat"/>34.
互联网络


35.
36.
37.id="sqlSessionFactory"class="org.mybatis.spring.SqlSessionFactory
Bean">
38.name="dataSource"ref="dataSource"/>
39.name="mapperLocations"value="classpath:com/dahafo/demo/um
/mapping/*Mapper.xml"/>40.41.
42.class="org.mybatis.spring.mapper.MapperScannerConfigurer">43.name="basePackage"value="com.dahafo.demo.um.dao"/>44.name="sqlSessionFactoryBeanName"value="sqlSessionFactory"
/>
45.46.
47.
48.id="transactionManager"class="org.springframework.jdbc.datasource
.DataSourceTransactionManager">
49.name="dataSource"ref="dataSource"/>50.51.
52.
53.
56.id="transactionAdvice"transaction-manager="transactionManage
r">
57.
58.name="add*"propagation="REQUIRED"/>59.name="modify*"propagation="REQUIRED"/>60.name="delete*"propagation="REQUIRED"/>61.name="find*"propagation="SUPPORTS"/>62.name="query"propagation="SUPPORTS"/>63.name="search*"propagation="SUPPORTS"/>64.name="*"propagation="SUPPORTS"/>65.
66.67.
68.id="transactionPointcut"expression="execution(*com.d
ahafo.demo.um.service.*.*(.."/>
69.pointcut-ref="transactionPointcut"advice-ref="transact
ionAdvice"/>
互联网络

免费下载 Word文档免费下载: SSM三大框架的整合(技术学习)

  • 29.8

    ¥45 每天只需1.0元
    1个月 推荐
  • 9.9

    ¥15
    1天
  • 59.8

    ¥90
    3个月

选择支付方式

  • 微信付款
郑重提醒:支付后,系统自动为您完成注册

请使用微信扫码支付(元)

订单号:
支付后,系统自动为您完成注册
遇到问题请联系 在线客服

常用手机号:
用于找回密码
图片验证码:
看不清?点击更换
短信验证码:
新密码:
 
绑定后可用手机号登录
请不要关闭本页面,支付完成后请点击【支付完成】按钮
遇到问题请联系 在线客服