spring mvc、spring、mybatis框架整合
来源:互联网 发布:pdf排版软件 编辑:程序博客网 时间:2024/05/21 17:26
总结
在整合中,自认为总重要的就是配置文件,但本身框架都是自学,基础还是差了点,以至于大部分的时间都在配置文件上,从难到易反而加深了理解。
首先,配置web.xml文件时要注意:
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:beans.xml;classpath:mvc-servlet.xml</param-value> </context-param>配置需要加载的上下文;<servlet> <description>spring mvc servlet</description> <servlet-name>springMvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <description>spring mvc 配置文件</description> <param-name>contextConfigLocation</param-name> <param-value>classpath:mvc-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springMvc</servlet-name> <!-- 默认匹配所有请求 --> <url-pattern>/</url-pattern> </servlet-mapping>在这部分配置中要注意url-patter,每个人的配置都可能不同,可根据自己方便来写;接着,在beans.xml中要注意:
<!-- mybatis自动扫描加载sql映射文件:MapperScannerConfigurer basePackage;指定SQL映射文件/接口所在的包(自动扫描) --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.mapper"></property> <property name="sqlSessionFactory" ref="sqlSessionFactory"></property> </bean> <!-- 事务管理:DataSourceTransactionManager --> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="ds"></property> </bean><aop:config> <!-- 配置一个切入点 --> <aop:pointcut id="serviceMethods" expression="execution(* com.service.*ServiceImpl.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethods" /> </aop:config>
最后是mvc-servlet.xml主要配置如下<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property> <property name="prefix" value="/"></property> <!-- 我这里的视图直接放在WebRoot下--> <property name="suffix" value=".jsp"></property> </bean>在搭建过程中主要碰到的问题1.忘记加载配置文件
2.web.xml中的url-patter和请求的路径没有匹配
0 0
- spring mvc + mybatis 整合框架
- (spring mvc+spring+Mybatis)框架整合
- spring mvc、spring、mybatis框架整合
- SSM(Spring mvc+Spring+Mybatis)框架整合
- spring + spring mvc + mybatis 整合框架
- Spring + Spring MVC + Mybatis 框架整合学习
- Spring MVC 框架 整合 MyBatis 框架实例
- Spring MVC+Mybatis 框架整合(一)
- Spring MVC+Mybatis 框架整合(二)
- Spring4.2 +Spring MVC+Mybatis 框架整合
- Spring MVC Mybatis 整合
- spring mvc mybatis 整合
- Spring MVC整合MyBatis
- spring mvc mybatis 整合
- spring mvc mybatis 整合
- Spring mvc+Mybatis整合
- Spring MVC整合Mybatis
- Spring+MVC+Mybatis整合
- c++中使用std::map是遇到的小问题
- PCA旋转变换矩阵的推导过程
- Webview交互实战
- https的网站使用百度地图的问题
- 写出边框的倒三角形
- spring mvc、spring、mybatis框架整合
- Android性能优化之路(一)
- 修改pulltorefresh 下拉刷新个上拉加载的显示
- uiautomator api
- 反射机制-案例
- IPC 主要是messenger和aidl的使用和简单分析
- mscoco 数椐集介绍
- 移植FreeRTOS9.0.0到M3
- 文本聚类算法之K-means算法的python实现