Sping,SpringMVC,Mybatis 三大框架整合环境搭建详解
来源:互联网 发布:韩服数据库 编辑:程序博客网 时间:2024/05/21 17:46
SpringMVC:springMVC是一个表现层的框架,类似struts2.主要用于jsp页面与后台数据交互
- SpringMVC的三大组件:
- 第一个组件:处理器映射器
- 第二个组件:处理器适配器
- 第三个组件:视图解析器
Springmvc执行流程
- strutsPrepareAndExcuteFilter拦截请求(控制层),拦截请求,转发请求
- 寻找Action执行
- ActionProxy:strutsActionProxy extends defaultActionProxy
- ActionMapping去寻找执行类Action
根据mvc设计模式:
Sping,SpringMVC,Mybatis 三大框架整合环境搭建详解:
第一步:导入jar包
第二步:配置spring的配置文件
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" xmlns:c="http://www.springframework.org/schema/c" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"><!-- 包扫描 --> <context:component-scan base-package="cn.peaceliu.springmvc.service"/> <!-- 读取配置文件 --> <context:property-placeholder location="classpath:*.properties"/> <!-- 数据源 --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"> <property name="driverClassName" value="${jdbc.driver}"></property> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"></property> <property name="password" value="${jdbc.password}"></property> </bean> <!-- sqlSessionFactoryBean --> <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="configLocation" value="classpath:SqlMapConfig.xml"></property> <property name="dataSource" ref="dataSource"></property> <property name="mapperLocations" value="classpath:mappers/*.xml"></property> </bean> <!-- 配置我们所有的接口扫描包 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="cn.peaceliu.springmvc.dao"></property> </bean><!-- 事物管理 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- 开启事物 --> <tx:annotation-driven transaction-manager="transactionManager"/> </beans>
第二步:配置mybatis的配置文件
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" xmlns:c="http://www.springframework.org/schema/c" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!-- 包扫描路径一定要配置到controller层,不要放大包扫描路径 --> <context:component-scan base-package="cn.peaceliu.springmvc.controller"></context:component-scan> <!-- 配置我们的处理器映射器和处理器适配器 --> <mvc:annotation-driven/> <!-- 配置我们的资源视图解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/"></property> <property name="suffix" value=".jsp"></property> </bean> </beans>
第四步:配置web.xml
<!-- needed for ContextLoaderListener --><context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value></context-param><!-- Bootstraps the root web application context before servlet initialization --><listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- The front controller of this Spring Web application, responsible for handling all application requests --><servlet> <servlet-name>springDispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup></servlet><!-- Map all requests to the DispatcherServlet for handling --><servlet-mapping> <servlet-name>springDispatcherServlet</servlet-name> <url-pattern>*.action</url-pattern></servlet-mapping>
阅读全文
0 0
- Sping,SpringMVC,Mybatis 三大框架整合环境搭建详解
- 三大框架Spring+Mybatis+springMVC整合
- Spring ,Springmvc,mybatis三大框架整合的配置文件支持
- SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis)
- SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis
- 三大框架整合ssm:SpringMVC + Spring + Mybatis
- Spring+SpringMVC+MyBatis三大框架整合的SSM
- Spring、SpringMVC、Mybatis三大框架整合步骤
- spring+springMVC+mybatis三大框架整合学习总结
- 使用intellij idea搭建spring-springmvc-mybatis整合框架环境
- Java三大框架环境搭建详解
- Java三大框架环境搭建详解
- SSM(SpringMVC Spring Mybatis)三大框架从零开始搭建实例
- maven整合SpringMVC和mybatis框架搭建
- 整合Spring SpringMvc Mybatis,搭建SSM框架
- SpringMVC框架搭建并整合MyBatis
- SpringMVC与Mybatis整合环境搭建
- 【AngularJS】AngularJS整合Springmvc、Mybatis环境搭建
- 3.7亿美元!诺基亚将收购芬兰电信软件公司Comptel
- Facebook推“社区帮助”功能,救受灾群众于“水火”之中
- 特斯拉员工称21美元时薪过低、加班太多,马斯克怒怼
- 福岛核电站内部辐射爆表,人活不过一分钟
- 百度改革砍掉了“医疗事业部”,Uber造飞行器想上天 | 大公司日报
- Sping,SpringMVC,Mybatis 三大框架整合环境搭建详解
- 三星S8正面真机照曝光,屏占比或高达90%
- 再看雷军七字诀:什么时候失效了,为什么?
- 金山腾讯让权给傅盛,猎豹要在人工智能领域大干一场
- LeetCode#264 Ugly Number II (week8)
- 台湾Uber司机抗议当局勒令其停运,同时呼吁网约车合法化
- 刘强东表示2021年超越阿里,特斯拉后院起火,Intel正式宣布第8代酷睿处理器 | 大公司日报
- NASA 终于研发出能在金星表面上运行的电脑
- 网易要做云音乐课堂?全面解析商业化变现方式