java中的接口是类吗
315
2022-11-17
详解Spring与Mybatis的整合方法(基于Eclipse的搭建)
项目工程总览:
项目路径建的包不是唯一,只要之后配置的路径映射正确即可
Emp.java
EmpMapper.java 与EmpMapper.xml配置
package com.jektong.dao;
ihttp://mport java.util.List;
import com.jektong.entity.Emp;
/**
* @author jektong
* @Date 2020-10-16 10:13:12
*/
public interface EmpMapper {
List
}
EmpMapper.xml配置
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
select * from t_emp
配置数据源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
xmlns:xsi="http://w3.org/2001/XMLSchema-instance"
xmlns:context="http://springframework.org/schema/context"
xmlns:jdbc="http://springframework.org/schema/jdbc"
xmlns:jee="http://springframework.org/schema/jee"
xmlns:tx="http://springframework.org/schema/tx"
xmlns:aop="http://springframework.org/schema/aop"
xmlns:mvc="http://springframework.org/schema/mvc"
xmlns:util="http://springframework.org/schema/util"
xsi:schemaLocation="
http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans-4.1.xsd
http://springframework.org/schema/context http://springframework.org/schema/context/spring-context-4.1.xsd
http://springframework.org/schema/jdbc http://springframework.org/schema/jdbc/spring-jdbc-4.1.xsd
http://springframework.org/schema/jee http://springframework.org/schema/jee/spring-jee-4.1.xsd
http://springframework.org/schema/tx http://springframework.org/schema/tx/spring-tx-4.1.xsd
http://springframework.org/schema/aop http://springframework.org/schema/aop/spring-aop-4.1.xsd
http://springframework.org/schema/mvc http://springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://springframework.org/schema/util http://springframework.org/schema/util/spring-util-4.1.xsd
http://springframework.org/schema/jdbc
http://springframework.org/schema/jdbc ">
xmlns:xsi="http://w3.org/2001/XMLSchema-instance"
xmlns:context="http://springframework.org/schema/context"
xmlns:jdbc="http://springframework.org/schema/jdbc"
xmlns:jee="http://springframework.org/schema/jee"
xmlns:tx="http://springframework.org/schema/tx"
xmlns:aop="http://springframework.org/schema/aop"
xmlns:mvc="http://springframework.org/schema/mvc"
xmlns:util="http://springframework.org/schema/util"
xsi:schemaLocation="
http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans-4.1.xsd
http://springframework.org/schema/context http://springframework.org/schema/context/spring-context-4.1.xsd
http://springframework.org/schema/jdbc http://springframework.org/schema/jdbc/spring-jdbc-4.1.xsd
http://springframework.org/schema/jee http://springframework.org/schema/jee/spring-jee-4.1.xsd
http://springframework.org/schema/tx http://springframework.org/schema/tx/spring-tx-4.1.xsd
http://springframework.org/schema/aop http://springframework.org/schema/aop/spring-aop-4.1.xsd
http://springframework.org/schema/mvc http://springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://springframework.org/schema/util http://springframework.org/schema/util/spring-util-4.1.xsd
http://springframework.org/schema/jdbc
http://springframework.org/schema/jdbc ">
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
for (Emp emps : selectAllEmps) {
System.out.println(emps.getName());
}
}
}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~