ssm整合:spring框架和mybatis框架的整合 可以了解

目录

1.什么是ssm整合?

2.流程步骤

(1)先创建一个maven的web工程,加入相关的依赖

(2).配置文件-----》springmvc配置文件

(3).配置文件----》spring配置文件

(4) .配置文件 ---》web.xml文件

(5).代码---dao---entity---mapping 可以使用easycode代码生成器

(6).业务层

(7).实现业务层

(8).控制层

(8).测试效果


 

1.什么是ssm整合?

ssm的整合实际就是spring框架和mybatis框架的整合,更白的:spring配置文件把mybatis配置文件的内容集成起来。spring为了集成mybatis的配置文件专门封装了一个类SqlSessionFactoryBean类。[plugins--->属性plugins datasource--->属性datasource mapper--mapper属性]

2.流程步骤

(1)先创建一个maven的web工程,加入相关的依赖




  4.0.0

  org.example
  ssm01
  1.0-SNAPSHOT
  war

  
    
      org.springframework
      spring-tx
      5.2.9.RELEASE
    
    
      org.springframework
      spring-jdbc
      5.2.9.RELEASE
    
    
    
      org.mybatis
      mybatis-spring
      2.0.6
    
    
    
      com.alibaba
      druid
      1.2.4
    
    
    
      org.springframework
      spring-webmvc
      5.2.9.RELEASE
    
    
    
      org.mybatis
      mybatis
      3.5.6
    
    
    
      mysql
      mysql-connector-java
      8.0.26
    
    
    
      org.projectlombok
      lombok
      1.18.22
    
    
    
      com.fasterxml.jackson.core
      jackson-databind
      2.12.4
    
    
    
      javax.servlet
      servlet-api
      2.5
    
    
      javax.servlet.jsp
      jsp-api
      2.2
    
    
    
      log4j
      log4j
      1.2.17
    
    
      org.slf4j
      slf4j-log4j12
      1.7.30
    

  

(2).配置文件-----》springmvc配置文件




    
    

    
    

    
    

    
    
        
        
    

(3).配置文件----》spring配置文件




    
    

    
    
        
        
        
        
        
        
        
    

    
    
        
        
    

    
    
        
    

(4) .配置文件 ---》web.xml文件



    
    
        springmvc
        org.springframework.web.servlet.DispatcherServlet
        
            contextConfigLocation
            classpath:springmvc.xml
        
    
    
    
        springmvc
        /
    

    
    
        org.springframework.web.context.ContextLoaderListener
    
    
        contextConfigLocation
        classpath:spring.xml
    

(5).代码---dao---entity---mapping 可以使用easycode代码生成器

ssm整合:spring框架和mybatis框架的整合 可以了解_第1张图片

(6).业务层

package com.qy.service;

import com.qy.entity.Emp;

import java.util.List;

/**
 * @program: ssm01
 * @description:
 * @author: 秦王
 * @create: 2021-12-09 16:05
 **/
public interface EmpService {
    /*
    * 查询所有员工信息
    * */
    public List findAll();
}

(7).实现业务层

package com.qy.service.impl;

import com.qy.dao.EmpDao;
import com.qy.entity.Emp;
import com.qy.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: ssm01
 * @description:
 * @author: 秦王
 * @create: 2021-12-09 16:07
 **/
@Service(value = "empService")
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpDao empDao;
    public List findAll() {
        return empDao.selectAll();
    }
}

(8).控制层

package com.qy.controller;

import com.qy.entity.Emp;
import com.qy.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @program: ssm01
 * @description:
 * @author: 秦王
 * @create: 2021-12-09 16:13
 **/
@Controller
@RequestMapping("/emp")
public class EmpController {
    @Autowired //spring容器注入该对象
    private EmpService empService;
    @RequestMapping("/list")
    @ResponseBody
    public List list(){
        List all = empService.findAll();
        return all;
    }
}

(8).测试效果

ssm整合:spring框架和mybatis框架的整合 可以了解_第2张图片

感谢翻阅!

你可能感兴趣的:(spring,java,eureka)