整合ssm集成框架

整合ssm集成框架

第一步:配置pom.xml

整合ssm集成框架_第1张图片

该代码放在里面


      
    <dependency>
    <groupId>org.springframeworkgroupId>
    <artifactId>spring-webartifactId>
    <version>5.1.0.RELEASEversion>
    dependency>
        
    <dependency>
    <groupId>org.springframeworkgroupId>
    <artifactId>spring-aopartifactId>
    <version>5.1.0.RELEASEversion>
    dependency>
        
    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-jdbcartifactId>
      <version>5.1.0.RELEASEversion>
    dependency>
       
    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-webmvcartifactId>
      <version>5.1.0.RELEASEversion>
    dependency>

      
        
    <dependency>
      <groupId>org.mybatisgroupId>
      <artifactId>mybatisartifactId>
      <version>3.4.6version>
    dependency>
        
    <dependency>
      <groupId>org.mybatisgroupId>
      <artifactId>mybatis-springartifactId>
      <version>1.3.2version>
    dependency>

        
    <dependency>
      <groupId>org.mariadb.jdbcgroupId>
      <artifactId>mariadb-java-clientartifactId>
      <version>2.3.0version>
    dependency>
    <dependency>
      <groupId>com.mchangegroupId>
      <artifactId>c3p0artifactId>
      <version>0.9.5.2version>
    dependency>

    
    <dependency>
      <groupId>javax.servletgroupId>
      <artifactId>jstlartifactId>
      <version>1.2version>
    dependency>
View Code

 第二步:添加mvc公共的包和文件

1、在main目录下添加个java文件  (放源代码)

2、在java目录下创建包

3、包目录下创建分层

4、main目录下创建resources文件(资源文件、配置信息)

5、resources下创建mapper(映射器)

6、在WEB-INF目录下创建views  (视图)

整合ssm集成框架_第2张图片

第三步:创建xml文件

1、在mapper文件下创建bookMapper.xml

2、在resources目录下创建spring-root.xml

3、在resourecs目录下创建spring-web.xml

整合ssm集成框架_第3张图片

bookMapper.xml文件

整合ssm集成框架_第4张图片

xml version="1.0" encoding="utf-8" ?>
DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.wbg.book_ssm.dao.BookDAO">
  
mapper>

spring-root.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:context="http://www.springframework.org/schema/context"
       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">
    
    <context:component-scan base-package="com.wbg.book_ssm.service"/>
    
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        
        <property name="driverClass" value="org.mariadb.jdbc.Driver"/>
        
        <property name="jdbcUrl" value="jdbc:mariadb://localhost:3306/book_ssm"/>
        
        <property name="user" value="root"/>
        
        <property name="password" value="123456"/>
    bean>
    
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="typeAliasesPackage" value="com.wbg.book_ssm.dao"/>
        <property name="mapperLocations" value="classpath:mapper/bookMapper.xml"/>
    bean>
    
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
        <property name="basePackage" value="com.wbg.book_ssm.dao"/>
    bean>
    
beans>
View Code

spring-web.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:contxt="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.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
    
    <contxt:component-scan base-package="com.wbg.book_ssm.web"/>
    
    <mvc:annotation-driven/>
    
    <mvc:default-servlet-handler/>
    
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/views"/>
        <property name="suffix" value=".jsp"/>
    bean>
beans>
View Code

 第四步:实现类和业务

1、实体类,在entity目录创建Book类

2、数据访问,在dao目录创建BookDAO接口

3、服务,在service目录下创建BookService接口和BookServiceImpl类

4、控制,在web目录下创建BookController类

整合ssm集成框架_第5张图片

 

posted @ 2018-09-26 20:08 韦邦杠 阅读( ...) 评论( ...) 编辑 收藏

你可能感兴趣的:(整合ssm集成框架)