脚本宝典收集整理的这篇文章主要介绍了SpringMVC和Mybatis的整合的工作原理,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
4.SPRingMVC和Mybatis的整合 在做这个项目之前,我们的前提条件是:你已经有一个能运行的SpringMVC的最简单的项目了。请同学们参考我的SpringMVC那章。做这个项目关键在于导包,请参考下图:SpringMVC和Mybatis的整合的工作原理马克-to-win: org.mybatis.spring.mapPEr.MapperScannerconfigurer会自动往Spring容器注入com.mapper目录下所有的Mapper比如RegisterMapper(这就是为什么在Controller当中你能用@Resource注解找到RegisterMapper的实例的原因),条件是org.mybatis.spring.SQLSessionFactoryBean类的实例已经在Spring容器中(实际上id是多少都无所谓,这里就是sqlSessionFactoryQQqq,因为反正也没有人调用它,只要有实例在容器中就行),有了它,MapperScannerConfigurer才能正常工作,因为SqlSessionFactoryBean的一个属性是dataSource,它掌握着连接数据库的密码等。例 1.4<htML><head> <tITle>Spring 3.0</title></head><body> <a href="helloa.do">Say Hello</a></body></html>spring-servlet.XMl:<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" 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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:component-scan base-package="com" /> <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> <bean id="dataSource" class="org.apache.COMmons.dbcp.BasicDataSource" > 更多内容请见原文,原文转载自:https://blog.csdn.net/qq_44639795/article/details/100163517
以上是脚本宝典为你收集整理的SpringMVC和Mybatis的整合的工作原理全部内容,希望文章能够帮你解决SpringMVC和Mybatis的整合的工作原理所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。