1,pojo

package com.songyan.dao;

import com.songyan.pojo.Student;

public interface StudentDao {
public void insertStudent(Student student);
public void deleteStudent(String id);
public void updateStudent(Student student);
public Student selectStudent(Integer id);
}
package com.songyan.dao;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory; import com.songyan.pojo.Student; public class StudentDaoImpl implements StudentDao{
private SqlSessionFactory sqlSessionFactory; public StudentDaoImpl(SqlSessionFactory sqlSessionFactory) {
super();
this.sqlSessionFactory = sqlSessionFactory;
} public void insertStudent(Student student) { } public void deleteStudent(String id) { } public void updateStudent(Student student) { } public Student selectStudent(Integer id) {
SqlSession session=sqlSessionFactory.openSession();
Student student=session.selectOne("test.findStudentById",10);
return student;
} }

2,mapper

<?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="test">
<select id="findStudentById" parameterType="Integer"
resultType="com.songyan.pojo.Student">
select * from student where STU_ID= #{value}
</select>
</mapper>

3,核心配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration> <!--配置环境,默认的环境id为oracle -->
<environments default="oracle">
<!-- 配置环境为oracle的环境 -->
<environment id="oracle">
<!--使用JDBC的事务处理 -->
<transactionManager type="JDBC" />
<!--数据库连接池 -->
<dataSource type="POOLED">
<property name="driver" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:inspur"></property>
<property name="username" value="scott"></property>
<property name="password" value="tiger"></property>
</dataSource>
</environment>
</environments>
<!--配置mapper的位置 -->
<mappers>
<mapper resource="com/songyan/dao/test.xml" /> </mappers>
</configuration>

4,测试

package com.songyan.client;

import java.io.IOException;
import java.io.InputStream; import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test; import com.songyan.dao.StudentDao;
import com.songyan.dao.StudentDaoImpl;
import com.songyan.pojo.Student; public class Test1 {
SqlSessionFactory sqlSessionFactory; @Before
public void test1() throws IOException
{
String resource="applicationContext.xml";
InputStream in=Resources.getResourceAsStream(resource);
sqlSessionFactory=new SqlSessionFactoryBuilder().build(in);
} @Test
public void test()
{
StudentDao studentDao=new StudentDaoImpl(sqlSessionFactory);
Student student=studentDao.selectStudent(1);
System.out.println(student);
}
}

原始DAO开发的更多相关文章

  1. MyBatis原始dao开发及问题总结(五)

    一.MyBatis原始Dao开发方式 1.原始dao开发需要程序员编写dao接口和dao接口实现类 编写UserDao接口:UserDao.java package codeRose.dao; pub ...

  2. Spring+SpringMVC+MyBatis深入学习及搭建(二)——MyBatis原始Dao开发和mapper代理开发

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/6869133.html 前面有写到Spring+SpringMVC+MyBatis深入学习及搭建(一)——My ...

  3. Mybatis学习(2)原始dao开发和使用mapper接口代理开发

    基础知识: 1).SqlSessionFactoryBuilder: 通过SqlSessionFactoryBuilder创建会话工厂SqlSessionFactory.将SqlSessionFact ...

  4. mybatis由浅入深day01_5mybatis开发dao的方法(5.1SqlSession使用范围_5.2原始dao开发方法)

    5 mybatis开发dao的方法 5.1 SqlSession使用范围 5.1.1 SqlSessionFactoryBuilder 通过SqlSessionFactoryBuilder创建会话工厂 ...

  5. Spring + Mybatis - 原始dao开发整合 与 Mapper代理整合

    Spring + Mybatis - 原始dao开发整合 与 Mapper代理整合 标签: mybatisSpringbeanApplicationContextMapper 2015-12-31 1 ...

  6. 【MyBatis学习03】原始dao开发方法及其弊端

    上一篇博文总结了一下mybatis的入门,接下来就要开发dao方法了,这篇博文主要总结一下mybatis中原始dao开发的方法,最后并总结一下原始dao开发方法的弊端.mybatis中dao开发应该使 ...

  7. MyBatis开发Dao的原始Dao开发和Mapper动态代理开发

    目录 咳咳...初学者看文字(Mapper接口开发四个规范)属实有点费劲,博主我就废了点劲做了如下图,方便理解: 原始Dao开发方式 1. 编写映射文件 3.编写Dao实现类 4.编写Dao测试 Ma ...

  8. Mybatis的原始dao开发方法

    在进入主题之前先提一下sqlSession.sqlSession是一个面向用户(程序员)的接口. sqlSession中提供了很多操作数据库的方法,如: selectOne(返回单个对象).selec ...

  9. Mybatis 和Spring整合之原始dao开发

    F:\Aziliao\mybatis\代码\31.mybatis与spring整合-开发原始dao 1.1. SqlMapConfig.xml <?xml version="1.0&q ...

  10. Mybatis笔记 - 原始Dao开发方法

    使用Mybatis开发Dao,通常有两个方法,即原始Dao开发方法和Mapper接口开发方法.原始Dao的开发方式是基于入门程序的基础上,对 控制程序 进行分层开发,程序员需要 编写 Dao接口 和 ...

随机推荐

  1. django 连接 oracle 问题

    安装 oracle 后,在 django 项目中连接出现问题记录. 问题1:pip install cx_Oacle 未出现任何问题,但运行过程出现: 原因:连接 oracle 的工具 cx_Orac ...

  2. 浅析 nth-child(n) 和 nth-of-type(n)

    首先看一个例子 <div> <p>第一个段落</p> <p>第二个段落</p> </div> p:nth-child(2) { ...

  3. 关于ora-12154:TNS:could not resolve the connect identifier specified

    一:前言 刚刚出来实习,在公司配的电脑里面装的oracle和PL SQL时一次性就搞定,但是在自己的电脑上装了就出现这个问题,刚刚在网上看了下,所以自己就写份记载吧! 二: 在打开PLSQL Deve ...

  4. BZOJ 4206: 最大团

    4206: 最大团 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 91  Solved: 36[Submit][Status][Discuss] De ...

  5. 【Foreign】树 [prufer编码][DP]

    树 Time Limit: 10 Sec  Memory Limit: 256 MB Description Input Output Sample Input 3 2 2 1 Sample Outp ...

  6. [POJ2068]Nim解题报告

    Let's play a traditional game Nim. You and I are seated across a table and we have a hundred stones ...

  7. 分布式缓存Memcache

    Memcached是分布式的,也就是说它不是本地的.它基于网络连接(当然它也可以使用localhost)方式完成服务,本身它是一个独立于应用的程序或守护进程(Daemon方式). Memcached使 ...

  8. bzoj 1026 DP,数位统计

    2013-11-20 08:11 原题传送门http://www.lydsy.com/JudgeOnline/problem.php?id=1026 首先我们用w[i,j]表示最高位是第i位,且是j的 ...

  9. 包与time,datetime,random,sys,shutil 模块

    一.包 包是什么? 包是一种通过使用‘.模块名’来组织python模块名称空间的方式. 注意: 1. 在python3中,即使包下没有__init__.py文件,import 包仍然不会报错,而在py ...

  10. ggplot2绘制多图

    参考链接:http://www.cnblogs.com/nxld/p/6065237.html ggplot2.multiplot是一个易于使用的功能,将多个图形在同一页面上使用R统计软件和GGPLO ...