项目下web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"><display-name></display-name> <welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list><!-- post请求 乱码过滤器 --><filter><filter-name>encoding</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>encoding</filter-name><url-pattern>*.shtml</url-pattern></filter-mapping><filter-mapping><filter-name>encoding</filter-name><url-pattern>*.do</url-pattern></filter-mapping><!-- spring监听器 --><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:application-context.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- springmvc控制请求流转,有前台系统和后台系统之分 --><!-- 前台(买家) --><servlet><servlet-name>front</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:springmvc-front.xml</param-value></init-param></servlet><servlet-mapping><servlet-name>front</servlet-name><url-pattern>*.shtml</url-pattern></servlet-mapping><!-- 后台(卖家) --><servlet><servlet-name>back</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:springmvc-back.xml</param-value></init-param></servlet><servlet-mapping><servlet-name>back</servlet-name><url-pattern>*.do</url-pattern></servlet-mapping></web-app>


tomcat/config/server.xml能解决get请求乱码,修改tomcat7下server.xml的第71行

    <Connector port="8080" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443" URIEncoding="UTF-8"/>


application-context.xml管理config文件夹下的配置文件

<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-2.5.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"><import resource="config/*.xml" /></beans>

config文件夹下文件的约束要与application-context.xml一致


config/annotation.xml

<!-- spring注解驱动扫包+依赖注入@Resource,不扫controller注解 -->
<context:component-scan base-package="cn.itcast"><context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan><!-- 注解方式的-依赖注入 -->
<context:annotation-config/>

config/transaction.xml

<!-- spring事务 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"></property>
</bean><!-- 开启事务注解 -->
<tx:annotation-driven transaction-manager="transactionManager"/>

config/jdbc.xml

<!-- c3p0-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="driverClass" value="${driverClass}"/><property name="jdbcUrl" value="${jdbcUrl}"></property><property name="user" value="${user}" /><property name="password" value="${password}"/>
</bean>

config/property.xml

<!-- 读取jdbc配置 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="locations"><list><!-- jdbc配置 --><value>classpath:properties/jdbc.properties</value><!-- memcached配置 --></list></property>
</bean>

config/mybatis.xml

<!-- mybatis sessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource"/><property name="mapperLocations" value="classpath:cn/itcast/core/dao/*.xml"/><property name="typeAliasesPackage" value="cn.itcast.core.bean"></property>
</bean><!-- mapper代理 管理dao-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="cn.itcast.core.dao"/>
</bean>

properties/jdbc.properties

driverClass=com.mysql.jdbc.Driver

jdbcUrl=jdbc:mysql://localhost:3306/babasport03?characterEncoding=UTF-8

user=root

password=root

Controller层对象交给springmvc处理

springmvc-back.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:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-2.5.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"><!-- 只扫controller,扫完就不要扫其他的注解 --><context:component-scan base-package="cn.itcast" use-default-filters="false"><context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan><!-- 请求参数类型转换 --><bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"><property name="webBindingInitializer"><bean class="cn.itcast.core.web.DateEditor"/></property></bean><!-- 视图解析器 --><bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/back_page"/><property name="suffix" value=".jsp"/></bean><!-- 图片上传的解析器 --><bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"><!-- 最大上传尺寸 --><property name="maxUploadSize" value="1048576"></property></bean></beans>


转载于:https://blog.51cto.com/pengya123/1859097

spring+mybatis+springmvc项目配置相关推荐

  1. spring mybatis 多数据源配置 jeesite 多数据源配置

    spring mybatis 多数据源配置 jeesite 多数据源配置 一.情景描述 在系统数据达到一定的访问量时,遇到单个数据库瓶颈,所以需要扩展数据库,启用第二个数据源资源,项目架构变成 一个服 ...

  2. Spring+Mybatis+SpringMVC+Maven+MySql(SSM框架)搭建实例

    这篇文章我们来实现使用maven构建工具来搭建Spring+Mybatis+SpringMVC+MySql的框架搭建实例.工程下载 使用maven当然得配置有关环境了,不会配置的请看我前几篇文章,都有 ...

  3. spring,mybatis事务管理配置与@Transactional注解使用[转]

    spring,mybatis事务管理配置与@Transactional注解使用[转] spring,mybatis事务管理配置与@Transactional注解使用 概述 事务管理对于企业应用来说是至 ...

  4. spring,mybatis事务管理配置与@Transactional注解使用

    spring,mybatis事务管理配置与@Transactional注解使用 概述 事务管理对于企业应用来说是至关重要的,即使出现异常情况,它也可以保证数据的一致性. Spring Framewor ...

  5. gradle idea java ssm_应用框架:IDEA+Gradle创建MyBatis+SpringMVC项目

    Gradle是一个基于Apache Ant和Apache Maven概念的项目自动化构建工具.它使用一种基于Groovy的特定领域语言(DSL)来声明项目设置,抛弃了基于XML的各种繁琐配置. IDE ...

  6. Spring+Mybatis多数据源配置(一)——MySQL与Oracle通过配置切换

    欢迎支持笔者新作:<深入理解Kafka:核心设计与实践原理>和<RabbitMQ实战指南>,同时欢迎关注笔者的微信公众号:朱小厮的博客. 欢迎跳转到本文的原文链接:https: ...

  7. (支付宝支付)Spring实现一个项目配置多个信息、付款给对应商户

    如何实现一个项目配置多个商户信息付款给对应商户 最近在对接支付宝支付时,遇到了一个问题 用户在付款时,需要直接付款到指定支付宝账户. 这个需求也无可厚非,就像我们公司有四个分公司,分别在北京.上海等地 ...

  8. springmvc+spring+mybatis+maven项目集成shiro进行用户权限控制【转】

    项目结构: 1.maven项目的pom中引入shiro所需的jar包依赖关系 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ...

  9. 【超详细】SSM框架项目实战|Spring+Mybatis+Springmvc框架项目实战整合-【CRM客户管理系统】——课程笔记

    相关资料网盘链接: CRM客户管理系统资料 提取码 :0u04 P1--CRM阶段简介: web项目开发:如何分析,设计,编码,测试.        形成编程思想和编程习惯. P2--CRM的技术架构 ...

最新文章

  1. 哪些人适合学软件测试呢
  2. 那些下载不了的视频,Python只用1行代码就能直接下载
  3. J.U.C系列(五)BlockingQueue的使用
  4. 用VuePress搞定你的博客(一)
  5. jenkins active exited(待编辑)
  6. m.2接口和nvme区别_M.2硬盘的分类和区别
  7. Unable to resolve dependency for xxx, Could not resolve project
  8. STM32(十一)- 串行FLASH文件系统FatFs
  9. Hibernate4 buildSessionFactory过时解决方案(Annotation也是一样解决)
  10. 看完这道题,你敢在心里承认自己是高手么
  11. Chrome最新版本如何通过JS设置支持自动播放音频
  12. 展视互动签约新华网 创在线教育新蓝图
  13. 读书百客:《月夜》鉴赏
  14. 拥塞控制算法(Congestion Control)对比
  15. 大道至简大巧不工——和田玉雕中的哲学
  16. Feign原理:current list of Servers哪里来的
  17. Fedora修复grub2启动项grub rescue
  18. 确定有限自动机(DFA)和不确定有限自动机(NFA)的主要区别
  19. 你可能不知道的 new.target
  20. android 手表按钮事件,关于android-studio:上手做一个华为鸿蒙手表应用-4-生命周期事件...

热门文章

  1. tablepc是什么平板电脑_54位平板电脑充电柜长什么样?安和力
  2. ROS知识【11-1】:建立用户自己的工作空间、功能包
  3. 图像处理:Hough变换原理分析
  4. Vue+ElementUI纯前端技术实现对表格数据的增删改查
  5. uni-app 请求封装
  6. Java如何解析markdown_使用Java实现的一款Markdown解析器md2x
  7. 面试题整理10 最小的k个数
  8. C++之临时对象的构造与析构
  9. 【ros】4.rosbag的相关用法
  10. Nginx(四)------nginx 负载均衡