SSM整合步骤

SSM- CRUD

SSM : SpringMVC+Spring+Mybatis

Create (新建) +Retrieve (查询) +Update(更新)+Delete(删除)

 

 功能点

1:分页

2:数据校验:JQuery前端校验+JSR后端校验。

3:ajax

4:Rest风格URL:使用HTTP协议请求方式的动词,来表示对对资源的操作:GET(查询)、POST(新增)、PUT(修改)、DELETE(删除)。

 

技术点

1:基础框架-SSM (SpringMVC+Spring+MyBatis)

2:数据库-MySQL 5

3:前端框架-bootstrap快速搭建简洁美观的前端界面。

4:项目的依赖管理-Maven。

5:分页插件-pagehelper

6:逆向工程-MyBatis Generator

 

基础环境搭建

1:创建一个maven工程

2:引入项目依赖的jar包

  • spring
  • springMVC
  • Mybatis
  • 数据库连接池,驱动包
  • 其它包[  jstl , servlet-api ,  junit ]

maven 配置文件增加配置

阿里云下载镜像

 
    
      alimaven
      central
      aliyun maven
      http://maven.aliyun.com/nexus/content/groups/public/
   

版本

 
      jdk1.8
     
          true
              1.8
     

     
          1.8
          1.8
          1.8   
     

   

 

pom.xml


    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    4.0.0
    cn.yi
    ssm-crud
    0.0.1-SNAPSHOT
    war

    
    
    
    
        
            org.springframework
            spring-webmvc
            4.3.12.RELEASE
        

        
        
        
            org.springframework
            spring-jdbc
            4.3.12.RELEASE
        

        
        
        
            org.springframework
            spring-aspects
            4.3.12.RELEASE
        

        
        
        
            org.mybatis
            mybatis
            3.4.2
        

        
        
        
            org.mybatis
            mybatis-spring
            1.3.1
        

        
        
        
            c3p0
            c3p0
            0.9.1
        

        
        
        
            mysql
            mysql-connector-java
            5.1.41
        

        
        
        
            jstl
            jstl
            1.2
        
        
        
            org.mortbay.jetty
            servlet-api
            2.5-6.0.0
            provided
        
        
        
            junit
            junit
            4.12
            test
        
        
        
        
        
            org.springframework
            spring-test
            4.3.12.RELEASE
            test
        
        
        
        
        
            org.mybatis.generator
            mybatis-generator-core
            1.3.5
        
    

 

 

 

 

 3: 引入bootstrap前端框架

4: 编写SSM整合的关键配置文件

 web.xml spring,springMVC mybatis 使用mybatis的逆向工程生成对应的bean以及mapper

 web.xml



    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_2_5.xsd"
    id="WebApp_ID" version="2.5">

    
    
    
        contextConfigLocation
        classpath:applicationContext.xml
    

    
    
        class>org.springframework.web.context.ContextLoaderListenerclass>
    

    

    
    
        dispatcherServlet
        class>org.springframework.web.servlet.DispatcherServletclass>
        1
    

    
    
        dispatcherServlet
        /
    

    
    
        CharacterEncodingFilter
        class>org.springframework.web.filter.CharacterEncodingFilterclass>
        
            encoding
            utf-8
        
        
            forceRequestEncoding
            true
        
        
            forceResponseEncoding
            true
        
    
    
    
        CharacterEncodingFilter
        /*
    

    
    
        HiddenHttpMethodFilter
        org.springframework.web.filter.HiddenHttpMethodFilter
    
    
        HiddenHttpMethodFilter
        /*
    

 

applicationContext.xml



    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="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.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">

    package="cn.yi">
        
        
            expression="org.springframework.stereotype.Controller" />
    
    
    
    
    
    
    class="com.mchange.v2.c3p0.ComboPooledDataSource">
        
                
        
        
    

    
    class="org.mybatis.spring.SqlSessionFactoryBean">
    
        
        
        
        
        
        
    

    
    class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        
        
    

    
    class="org.mybatis.spring.SqlSessionTemplate">
    
    
    

    
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        
        
    
    
    
    
        
        
        
        
    

    
    
        
            
            
            
            
        
    
    

 

dispatcherServlet-servlet.xml



    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/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
        

    
    package="cn.yi" use-default-filters="false">        
        
        
    
    
    
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        
        
        
        
    
    
    
    
    default-servlet-handler/>
    
    
    

 

mybatis-Config.xml


DOCTYPE configuration
  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-config.dtd">


    
    
        
    
    
        <package name="cn.yi.crud.bean" />
    

mbg.xml 


DOCTYPE generatorConfiguration
  PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">


    
    
        
        
            
        
        
        
        
            connectionURL="jdbc:mysql://localhost:3306/ssm-crud" userId="root"
            password="">
        

        
            
        

        
        
            targetProject=".\src\main\java">
            
            
        

        
        
            
        

        
        
            targetPackage="cn.yi.crud.dao" targetProject="./src/main/java">
            
        

        
        

 5: 测试mapper

 

转载于:https://www.cnblogs.com/pxuan/p/7776384.html

你可能感兴趣的:(java,前端,数据库)