Spring配置文件: applicationContext.xml
SprngMVC配置文件: spring-mvc.xml
MyBatis映射文件: AccountMapper.xml
MyBatis核心文件: sqlMapConfig.xml
数据库连接信息文件: jdbc.properties
Web.xml文件: web.xml
日志文件: log4j.xml
原始方式整合:不同文件的内容
MyBatis核心文件: sqlMapConfig.xml
<!--加载properties文件-->
<!--定义别名-->
<!--环境-->
<!--加载映射-->
MyBatis映射文件: AccountMapper.xml
一些sql语句
SprngMVC配置文件: spring-mvc.xml
<!--组件扫描 主要扫描controller-->
<!--配置mvc注解驱动-->
<!--内部资源视图解析器-->
<!--开放静态资源访问权限-->
Spring配置文件: applicationContext.xml
<!--组件扫描 扫描service和mapper-->
Web.xml文件: web.xml
<!--spring 监听器-->
<!--springmvc的前端控制器-->
<!--乱码过滤器-->
Spring整合MyBatis:不同文件的内容
Spring配置文件: applicationContext.xml
SprngMVC配置文件: spring-mvc.xml
MyBatis映射文件: AccountMapper.xml
MyBatis核心文件: sqlMapConfig-spring.xml
数据库连接信息文件: jdbc.properties
Web.xml文件: web.xml
日志文件: log4j.xml
MyBatis核心文件: sqlMapConfig-spring.xml
<!--定义别名-->
Spring配置文件: applicationContext.xml
<!-- 组件扫描 扫描service and mapper-->
<!-- 加载propeties文件-->
<!--配置数据源信息-->
<!--配置sessionFactory-->,<!--加载mybatis核心文件-->
<!--扫描mapper所在的包 为mapper创建实现类--> 对应之前的加载映射文件
优点:Spring整合Mybatis 可以简化Service
原始方式整合:
MyBatis映射文件: AccountMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.mapper.AccountMapper">
<select id="findAll" resultType="account">
select * from account
</select>
<insert id="save" parameterType="account">
insert into account values(#{id},#{name},#{money})
</insert>
</mapper>
MyBatis核心文件: sqlMapConfig.xml
<!--核心文件头部-->
<!--加载properties文件-->
<!--定义别名-->
<!--环境-->
<!--加载映射-->
案例:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http