SSM;Spring+SpringMVC+MyBatis

建立Java web项目

一、导包

1)、Spring:

【aop核心】

com.springsource.net.sf.cglib-2.2.0.jar

com.springsource.org.aopalliance-1.0.0.jar

com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar

spring-aspects-4.0.0.RELEASE.jar

【ioc核心】

commons-logging-1.1.3.jar

spring-aop-4.0.0.RELEASE.jar

spring-beans-4.0.0.RELEASE.jar

spring-context-4.0.0.RELEASE.jar

spring-core-4.0.0.RELEASE.jar

spring-expression-4.0.0.RELEASE.jar

【jdbc核心】

spring-jdbc-4.0.0.RELEASE.jar

spring-orm-4.0.0.RELEASE.jar

spring-tx-4.0.0.RELEASE.jar

【测试】

spring-test-4.0.0.RELEASE.jar

2)、SpringMVC:

【ajax】

jackson-annotations-2.1.5.jar

jackson-core-2.1.5.jar

jackson-databind-2.1.5.jar

【数据校验】

hibernate-validator-5.0.0.CR2.jar

hibernate-validator-annotation-processor-5.0.0.CR2.jar

classmate-0.8.0.jar

jboss-logging-3.1.1.GA.jar

validation-api-1.1.0.CR1.jar

【上传下载】

commons-fileupload-1.2.1.jar

commons-io-2.0.jar

【jstl-jsp标准标签库】

jstl.jar

standard.jar

【验证码】

kaptcha-2.3.2.jar

【springmvc核心】

spring-web-4.0.0.RELEASE.jar

spring-webmvc-4.0.0.RELEASE.jar

 3)、MyBatis

【mybatis核心】

mybatis-3.4.1.jar

【和Spring整合包】

mybatis-spring-1.3.0.jar

【日志】

log4j-1.2.17.jar

【ehcache整合】

ehcache-core-2.6.8.jar

mybatis-ehcache-1.0.3.jar

slf4j-api-1.7.21.jar

slf4j-log4j12-1.7.21.jar

 4)、其他的

mysql-connector-java-5.1.37-bin.jar

c3p0-0.9.1.2.jar

二、写配置

0、web.xml配置:

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

  <display-name>7.SSM</display-name>

  <welcome-file-list>

    <welcome-file>index.jsp</welcome-file>

  </welcome-file-list>

  <!-- 配置Spring容器启动: -->

  <!-- needed for ContextLoaderListener -->

    <context-param>

        <param-name>contextConfigLocation</param-name>

        <!--指定spring配置文件位置  -->

        <param-value>classpath:spring/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>

    <!-- 配置springmvc的前端控制器 -->

    <!-- 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:spring/applicationContext-mvc.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>/</url-pattern>

    </servlet-mapping>

    <!--  两个标准配置-->

    <!-- 字符编码 -->

    <filter>

        <filter-name>CharacterEncodingFilter</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>CharacterEncodingFilter</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>

    <!-- 支持Rest风格的过滤器 -->

    <filter>

        <filter-name>HiddenHttpMethodFilter</filter-name>

        <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>

    </filter>

    <filter-mapping>

        <filter-name>HiddenHttpMethodFilter</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>

</web-app>

1、spring配置:

2、springmvc的配置:

<?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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <!-- SpringMVC只扫描控制器;禁用默认的规则 -->
<context:component-scan base-package="com.atguigu" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"></property>
<property name="suffix" value=".jsp"></property>
</bean> <!--配置文件上传解析器 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8"></property>
<property name="maxUploadSize" value="#{1024*1024*20}"></property>
</bean> <!-- 扫静态资源 -->
<mvc:default-servlet-handler/>
<!-- 扫动态 -->
<mvc:annotation-driven></mvc:annotation-driven> </beans>

3、mybatis的配置:

整合步骤:导入整合包;(能将dao的实现加入到容器中)

整合的关键配置其实实在spring.xml中的

<!--2、配置JdbcTemplate操作数据库。pass  -->
<!--3、配置使用mybatis操作数据库 -->
<!-- 可以根据配置文件得到sqlSessionFactory -->
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 指定配置文件位置 -->
<property name="configLocation" value="classpath:mybatis/mybatis-config.xml"></property>
<property name="dataSource" ref="ds"></property>
<!-- 指定xml映射文件的位置 -->
<property name="mapperLocations" value="classpath:mybatis/mapper/*.xml"></property>
</bean>
<!-- 我们要把每一个dao接口的实现加入到ioc容器; -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 指定dao接口所在的包 -->
<property name="basePackage" value="com.atguigu.dao"></property>
</bean>

4、其他小家伙的配置:

【串线篇】Mybatis之SSM整合的更多相关文章

  1. 【串线篇】spring boot整合SpringData JPA

    一.SpringData简介 其中SpringData JPA底层基于hibernate 二.整合SpringData JPA JPA: Java Persistence API的简称,中文名Java ...

  2. Spring框架学习笔记(4)——SSM整合以及创建Maven自定义模版

    Spring+Spring MVC+MyBatis+Maven SSM整合的核心还是Spring+MyBatis的整合,回顾一下MyBatis操作数据库流程,我们是使用一个SQLSessionFact ...

  3. [置顶] Java Web学习总结(24)——SSM(Spring+SpringMVC+MyBatis)框架快速整合入门教程

    1.基本概念 1.1.Spring Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson 在其著作Expert One-On-One  ...

  4. ssm整合说明与模板-Spring Spring MVC Mybatis整合开发

    ssm整合说明 spring+spring mvc+mybatis 说明 源码下载 由于之前存在ssh框架,spring+struts+hibernate,其中spring负责aop与ioc,所以一般 ...

  5. 吴裕雄--天生自然JAVA SPRING框架开发学习笔记:SSM(Spring+Spring MVC+MyBatis)框架整合搭建详细步骤

    因为 Spring MVC 是 Spring 框架中的一个子模块,所以 Spring 与 SpringMVC 之间不存在整合的问题.实际上,SSM 框架的整合只涉及 Spring 与 MyBatis ...

  6. Mybatis第五篇【Mybatis与Spring整合】

    Mybatis与Spring整合 既然我们已经学了Mybatis的基本开发了,接下来就是Mybatis与Spring的整合了! 以下使用的是Oracle数据库来进行测试 导入jar包 aopallia ...

  7. SSM整合配置

    SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis) 使用SSM(Spring.SpringMVC和Mybatis)已经有三个多月了,项目在技术上已经没有什么难点了,基于现有 ...

  8. SpringMVC之简单的增删改查示例(SSM整合)

    本篇文章主要介绍了SpringMVC之简单的增删改查示例(SSM整合),这个例子是基于SpringMVC+Spring+Mybatis实现的.有兴趣的可以了解一下. 虽然已经在做关于SpringMVC ...

  9. 【MyBatis学习14】MyBatis和Spring整合

    前面十几篇博文总结了mybatis在开发中的相关技术,但在实际中都是和spring整合开发的,所以这里总结一下mybatis和spring的整合方法,并在整合后进行测试. 1. 整合的环境 这都是老掉 ...

随机推荐

  1. 阿里云Serverless应用引擎(SAE)3大核心优势全解析

    软件发展到今,企业业务系统日趋复杂,开发一个业务系统需要掌握和关注的知识点越来越多.除实现业务逻辑本身,还需考虑很多非业务的基础技术系统:如分布式cache和队列.基础服务能力集成.容量规划.弹性伸缩 ...

  2. redis学习 --List

    1:添加   lpush    rpush     如果没有key的话,会报错.   lpushx    rpushx    如果没有key的话,不做任何反应. 2:得到 lpop   rpop   ...

  3. 【2019 Multi-University Training Contest 8】

    01: 02: 03:https://www.cnblogs.com/myx12345/p/11655876.html 04: 05: 06:https://www.cnblogs.com/myx12 ...

  4. 【HDOJ6621】K-th Closest Distance(主席树,二分)

    题意:给定一个长为n的序列,有m次强制在线的询问,每次询问位置[L,R]中abs(a[i]-p)第k小的值 n,m<=1e5,a[i]<=1e6,p<=1e6,k<=169 思 ...

  5. 在浏览器地址栏中查看cookie

    在IE地址栏中输入javascript:alert(document.cookie) 或者地址栏直接打javascript:document.write(document.cookie);

  6. Emmet基本使用教程

    转载来自:http://www.iteye.com/news/27580 Emmet的前身是大名鼎鼎的Zen coding,如果你从事Web前端开发的话,对该插件一定不会陌生.它使用仿CSS选择器的语 ...

  7. DG-V$MANAGED_STANDBY视图

    V$MANAGED_STANDBY displays current status information for some Oracle Database processes related to ...

  8. mongodb用户创建及权限控制

    转载 2017年03月30日 12:36:15 2169 摘要: MongoDB 3.0 安全权限访问控制,在添加用户上面3.0版本和之前的版本有很大的区别,这里就说明下3.0的添加用户的方法. 环境 ...

  9. 高德WMTS规则

    新版 http://wprd0{1-4}.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1& ...

  10. Python 学习笔记21 CMD执行测试用例

    使用CMD命令执行测试用例 当我们在ride中设计好测试用例后,我们可以使用ride的界面工具来选择和运行测试用例. 系统也会提供比较好的报告和日志的浏览功能. 但是这样的自动化,毕竟是需要手工介入的 ...