详解Spring与Mybatis的整合方法(基于Eclipse的搭建)

项目工程总览:

详解Spring与Mybatis的整合方法(基于Eclipse的搭建)_第1张图片

项目路径建的包不是唯一,只要之后配置的路径映射正确即可

Emp.java

 
    5.1.5.RELEASE
    3.4.6
    1.2.17
  
  
    
    
      junit
      junit
      4.11
      
      test
    
    
      org.projectlombok
      lombok
      1.18.14
      provided
    
    
    
      org.springframework
      spring-core
      ${spring.version}
    
    
      org.springframework
      spring-web
      ${spring.version}
    
    
      org.springframework
      spring-oxm
      ${spring.version}
    
    
      org.springframework
      spring-tx
      ${spring.version}
    
    
      org.springframework
      spring-jdbc
      ${spring.version}
    
    
      org.springframework
      spring-webmvc
      ${spring.version}
    
    
      org.springframework
      spring-aop
      ${spring.version}
    
    
      org.springframework
      spring-context
      ${spring.version}
    
    
      org.springframework
      spring-test
      ${spring.version}
    
    
    
      org.mybatis
      mybatis
      ${mybatis.version}
    
    
    
      org.mybatis
      mybatis-spring
      1.3.2
    
    
    
      mysql
      mysql-connector-java
      5.1.17
    
    
      com.mchange
      c3p0
      0.9.5.5
    

    
      jstl
      jstl
      1.2
    
    
      org.apache.commons
      commons-dbcp2
      2.7.0
    
    
      commons-io
      commons-io
      2.4
    
    
      commons-logging
      commons-logging
      1.2
    
    
      org.junit.jupiter
      junit-jupiter
      RELEASE
      compile
    
  

EmpMapper.java 与EmpMapper.xml配置

package com.jektong.dao;
import java.util.List;
import com.jektong.entity.Emp;
/**
 * @author jektong 
 * @Date 2020-10-16 10:13:12
 */
public interface EmpMapper {	
	List selectAllEmps();
}

EmpMapper.xml配置




	
		
		
		
		
		
		
	
	
	

配置数据源db.properties文件

# mysql
url=jdbc:mysql://localhost:3306/jektong?useUnicode=true&characterEncoding=utf-8
driver=com.mysql.jdbc.Driver
username=jektong
password=123456

配置applicationContext.xml



    

	
	
  
    
    
    
    
  
  
  
	 
		
  	  
  	
  	
  	
  	
	 
	
	
    
    
	

test

package com.jektong.test;
import java.util.List;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.jektong.dao.EmpMapper;
import com.jektong.entity.Emp;
/**
 * @author jektong
 * @Date 2020-10-15 16:31:58
 */
public class TestOne {
	@Test
	public void t() throws Exception {
	  ApplicationContext ac =
	        new ClassPathXmlApplicationContext("applicationContext.xml");
	  EmpMapper mapper = (EmpMapper) ac.getBean("empMapper");
		List selectAllEmps = mapper.selectAllEmps();
		for (Emp emps : selectAllEmps) {
			System.out.println(emps.getName());
		}
	}
}

到此这篇关于详解Spring与Mybatis的整合方法(基于Eclipse的搭建)的文章就介绍到这了,更多相关Spring与Mybatis的整合内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

你可能感兴趣的:(详解Spring与Mybatis的整合方法(基于Eclipse的搭建))