日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring+SpringMVC +MyBatis整合配置文件案例66666

發布時間:2024/10/12 javascript 75 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring+SpringMVC +MyBatis整合配置文件案例66666 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Spring+SpringMVC +MyBatis整合配置文件案例

標簽: springspringmvcmybatismvcjava 分類: java_javaSE(2)

目錄(?)[+]

Spring+SpringMVC +MyBatis整合配置文件案例

針對spring/SpringMVC/MyBatis三個框架的整合有很多的方式,經過最近的學習我來總結一下其配置文件的設置以及三大框架之間的一些關系.代碼配置后面附上,僅作為建議.

三大框架之間的關系圖如下:

配置文件配置的對應關系:

1.Spring配置文件

  • applicationContext.xml

    <context:component-scan base-package="service"/> <context:property-placeholder location="classpath:/c3p0.properties"/><!-- 注冊數據庫的資源 --> <bean id="dataSource" class = "com.mchange.v2.c3p0.ComboPooledDataSource"><property name="driverClass" value = "${c3p0.driver}"></property><property name="jdbcUrl" value = "${c3p0.url}"></property><property name="user" value = "${c3p0.user}"></property><property name="password" value = "${c3p0.password}"></property> </bean><!-- 聲明式的事務處理 --> <bean id = "transactionManager" class = "org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="datasource"></property> </bean><!-- 創建通知 配置切面和切入點--> <tx:advice id="advice"><tx:attributes><tx:method name="add*" propagation="REQUIRED" /><tx:method name="del*" propagation="REQUIRED" /><tx:method name="update*" propagation="REQUIRED" /><tx:method name="find*" propagation="SUPPORTS" read-only="true" /><tx:method name="*" read-only="true" /></tx:attributes> </tx:advice><aop:config ><aop:pointcut expression="execution(* servlet..*.*(..))" id="pc"/><aop:advisor advice-ref="advice" pointcut-ref="pc"/> </aop:config><!-- 整合MyBatis --> <bean id = "SqlSessionFactory" class = "org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref = "dataSource"></property><!-- 導入核心配置文件 --><property name="configLocation" value = "classpath:/sqlMapConfig.xml"></property><!-- 導入映射文件 --><property name="mapperLocations" value = "classpath:/pojo/*.xml"></property> </bean><!-- spring為mapper接口創建代理對象 --> <bean class = "org.mybatis.spring.mapper.MapperScannerConfigurer" ><property name="basePackage" value = "mapper"></property> </bean>

2.SpringMVC配置文件

  • applicationContext-mvc.xml

    1. <!-- 開啟mvc注解 --> <mvc:annotation-driven /> <context:component-scan base-package="controller"></context:component-scan> 2. <!-- 內部資源視圖管理器 --> <bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/"></property><property name="suffix" value = ".jsp"></property> </bean>

3.MyBatis配置文件

  • sqlMapConfig.xml

    1. MyBatis核心配置文件 <configuration><!-- 可以設置其緩存和其他一些事務--> </configuration>
  • UserMapper.xml

    <mapper namespace="mapper.UserMapper"><!-- 映射配置文件指定開啟二級緩存 --> <cache/><!-- 復用sql語句 --> <sql id="selectUser"> select * from user </sql><select id="findAll" resultType="pojo.User"><include refid="selectUser"/> </select>

4.web.xml配置文件

  • web.xml

    1. <!--配置過濾器--> <filter><filter-name>filter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param><param-name>Encoding</param-name><param-value>UTF-8</param-value> </init-param> </filter><filter-mapping><filter-name>filter</filter-name><url-pattern>/*</url-pattern> </filter-mapping> <servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:/applicationContext*.xml</param-value></init-param> </servlet><servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>*.action</url-pattern> </servlet-mapping>

不太善于言辭,希望得到大家的支持,謝謝!

寫于2017/04/13

轉載于:https://www.cnblogs.com/zftxdh/p/7086501.html

總結

以上是生活随笔為你收集整理的Spring+SpringMVC +MyBatis整合配置文件案例66666的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。