mybatis属于分离sql语句,当结合spring框架一起使用
1、准备jar包
2、创建spring配置文件:application.xml
<beans>
<comtext:component-scan base-baggage="com.jd"></comtext>//扫描加入IOC容器的目标对象
<bean id="dateSource" class="HikariDateSource" lazy-inie="flase" destory-
method="close">//链接数据库连接池
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test"></property>
<property name="username" value="root"></property>
<property name="password" value="admin"></property>
</bean>
<bean class="SqlSessionFcaroryBean"//配置mybatis-config.xml
p:dataSource-ref="dateSource"
p:configLocation="classPath:mybatis-config.xml"
p:mapperLocations="classPath:./sql/*.xml"
>
</bean>
<mybatis-spring:scan base-package:"com.jd.*.dao"/>//为dao层接口产生代理类并产生代理对象
</beans>