springmvc+mybaits的系统架构:
第一步:整合dao层
mybatis和spring整合,通过spring管理mapper接口。
使用mapper的扫描器自动扫描mapper接口在spring中进行注册。
第二步:整合service层
通过spring管理 service接口。
使用配置方式将service接口配置在spring配置文件中。
实现事务控制。
第三步:整合springmvc
由于springmvc是spring的模块,不需要整合。
所需要的jar包:
数据库驱动包:mysql5.1
mybatis的jar包
mybatis和spring整合包
log4j包
dbcp数据库连接池包
spring3.2所有jar包
jstl包
mybatis配置文件 sqlMapConfig.xml:
db.properties
jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/mybatis jdbc.username=root jdbc.password=
applicationContext-dao.xml
配置:
数据源
SqlSessionFactory
mapper扫描器
mybatis mapper接口映射文件 ItemsMapperCustom.xml
applicationContext-service.xml
事务控制(applicationContext-transaction.xml)
springmvc.xml
创建springmvc.xml文件,配置处理器映射器、适配器、视图解析器
工程的web.xml