spring、springMVC、mybatis整合配置文件问题
来源:互联网 发布:苹果7连不上4g网络吗 编辑:程序博客网 时间:2024/06/04 19:17
1.在 web.xml 文件中,初始化 spring 工厂,配置 springMVC 核心控制器,post 提交中文乱码等问题。
<!-- 初始化spring工厂 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:zpark/spring/spring-basic.xml</param-value> </context-param>
<!-- 配置springmvc核心Servlet --> <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:zpark/springmvc/spring-mvc.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>
<!-- post 提交中文编码 --> <filter> <filter-name>character</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> <init-param> <param-name>forceEncoding</param-name><param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>character</filter-name><url-pattern>/*</url-pattern> </filter-mapping>
2.在 spring-basic.xml 文件中,主要完成以下功能:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.2.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.2.xsd "><!-- 包扫描 --><context:component-scan base-package="zpark"><context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan><!-- 创建数据源 --><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="driverClassName" value="com.mysql.jdbc.Driver"/><property name="url" value="jdbc:mysql://localhost:3306/ssmvcm"/><property name="username" value="root"/><property name="password" value="123456"/><!-- 连接池相关配置 --><!-- 初始化连接数 --><property name="initialSize" value="10"/><!-- 最大活跃连接 > 初始化连接数 --><property name="maxActive" value="15"/> <!-- 最大等待时长 毫秒 --><property name="maxWait" value="2000"/></bean><!-- 创建SqlSessionFactory --><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!-- 依赖于 dataSource --><property name="dataSource" ref="dataSource" /><!-- 依赖于 mapper --><property name="mapperLocations" value="classpath:zpark/mapper/*.xml"/><!-- 给实体类其别名 默认起的别名就是类名 --><property name="typeAliasesPackage" value="zpark.entity"/></bean><!-- 创建DAO --><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" ><property name="basePackage" value="zpark.dao"/><!-- 依赖于sqlSessionFactory --><property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/></bean><!-- 创建事务管理器 --><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"/></bean><!-- 开启注解式生效 --><tx:annotation-driven transaction-manager="transactionManager"/></beans>
3.在 spring-mvc.xml 文件中,主要完成下面几步操作:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.2.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.2.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd "><!-- 包扫描 --><context:component-scan base-package="zpark" use-default-filters="false"><context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan><!-- 注册处理适配器和处理器映射器 处理响应相关 --><mvc:annotation-driven /><!-- 配置视图解析器 --><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/"/><property name="suffix" value=".jsp"/></bean><!-- 静态资源 --><mvc:default-servlet-handler/></beans>
0 0
- spring、springMVC、mybatis整合配置文件问题
- spring+springmvc+mybatis整合配置文件
- SSM整合配置文件(Springmvc+Spring+Mybatis)
- SSM(spring+mybatis+springmvc)整合 配置文件
- SSM整合配置文件(Springmvc+Spring+Mybatis)
- SpringMVC+Spring+Mybatis整合配置文件小记
- SSM整合配置文件(Springmvc+Spring+Mybatis)
- SSM整合配置文件(Springmvc+Spring+Mybatis)
- Spring+SpringMVC +MyBatis整合配置文件案例
- Spring+SpringMVC+MyBatis整合配置文件的搭建
- SSM整合配置文件(Springmvc+Spring+Mybatis)
- Spring、SpringMVC、Mybatis整合遇到的问题
- Spring+SpringMVC整合----配置文件
- spring-mybatis整合(配置文件)
- mybatis整合spring配置文件
- 浅谈spring+springMVC+mybatis框架整合(配置文件的使用)
- Spring ,Springmvc,mybatis三大框架整合的配置文件支持
- 整合SpringMVC+Spring+Mybatis+mysql的maven配置文件pom.xml
- opencv调用摄像头拍照保存
- Atitti dbutil获取多个返回结果集的解决
- 随笔 #2#3
- 时光一去不再有,不知不觉已经在前端这片深海里游了快2年了
- Android系统启动App及 app怎么去启动一个Activity的流程总结
- spring、springMVC、mybatis整合配置文件问题
- Android三种方法实现按钮点击事件
- 二.线程常见的方法
- Fmx判断ListBox显示到最下面一个文件(用来延迟加载)
- 数据存储
- POJ2352_Stars_线段树求前缀和
- Makefile的简单介绍
- 实例介绍利用valgrind定位内存非法访问问题
- marquee标签