1、MyBatis优点
操作简单话,代码量少,效率高,成本就降低了
2、MyBatis缺点
参数只能限制为一个
selece语都要手动来写

3、与JDBC的关系:是对JDBC的扩展
把sql语句和java代码分离后,改了sql语句不用改动java代码

<!--SqlMapConfig.xml配置文件-->

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<!--导入数据库连接配置信息 -->
<properties resource="SqlMap.properties"></properties>
<!-- type="JDBC"表示使用jdbc 进行事务管理SIMPLE 使用简单的方式-->
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="${driver}"></property>
<property name="JDBC.ConnectionURL" value="${url}"></property>
<property name="JDBC.Username" value="${username}"></property>
<property name="JDBC.Password" value="${password}"></property>
</dataSource>
</transactionManager>

<!-- 映射文件 -->
<sqlMap resource="entity/Student.xml"/>

</sqlMapConfig>

<!--SqlMap.properties 文件-->

driver=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@localhost:1521:ORCL
username=scott
password=abc123

<!-- Student映射文件 -->

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">

<sqlMap>
<!-- 给操作的类取个别名 以便下面好用 -->
<typeAlias alias="Student" type="entity.Student"/>

<!--selectAllStudent相当于下面查询语句的一个别称 -->
<select id="selectAllStudent" resultClass="Student">
select * from Student
</select>

<!--parameterClass 传进来的参数类型 -->
<select id="selectStudentById" parameterClass="int" resultClass="Student">
select * from Student where sid=#sid#
</select>

<!--添加类型要一一对应,不然会类型转换报错 没有返回值类型就不用配置 resultClass属性-->
<insert id="insertStudent" parameterClass="Student" >
insert into Student(sid,sname,major,birth,score) values(#sid#,#sname#,#major#,#birth#,#score#)
</insert>

<!-- 中间的那个配置表示去查找序列 把序列的下一个值付给Strudent对象中的一个属性 -->
<insert id="insertStudentBySequence" parameterClass="Student">
<selectKey resultClass="int" keyProperty="sid">
  select seqenct_student.nextVal from dual
</selectKey>
  insert into Student(sid,sname,birth,major,score)
  values(#sid#,#sname#,#birth#,#major#,#score#)
</insert>
<!--删除对象-->
<delete id="deleteStudentById" parameterClass="int">
delete from Student where sid=#sid#
</delete>

<!--修改信息-->
<update id="updateStudentById" parameterClass="Student">
update Student
set sname=#sname#,
major=#major#,
birth=#birth#,
score=#score#
where sid=#sid#
</update>

<!-- 模糊查询 -->
<select id="selectStudentByName" parameterClass="String" resultClass="Student">
select sid,sname,major,birth,score from Student
where sname like '%$sname$%'
</select>
</sqlMap>

入门教学视频下载链接:http://pan.baidu.com/s/1laU4m

MyBatis环境搭建配置文件+入门视频下载的更多相关文章

  1. Mybatis学习笔记之---环境搭建与入门

    Mybatis环境搭建与入门 (一)环境搭建 (1)第一步:创建maven工程并导入jar包 <dependencies> <dependency> <groupId&g ...

  2. MyBatis -01- 初识 MyBatis + MyBatis 环境搭建

    MyBatis -01- 初识 MyBatis + MyBatis 环境搭建 MyBatis 本是 apache 的一个开源项目 iBatis(iBATIS = "internet" ...

  3. Android菜鸟的成长笔记(1)——Android开发环境搭建从入门到精通

    原文:Android菜鸟的成长笔记(1)--Android开发环境搭建从入门到精通 今天在博客中看到好多Android的初学者对Android的开发环境的搭建不熟悉而导致不能进行学习,所以我决定自己写 ...

  4. Spark+ECLIPSE+JAVA+MAVEN windows开发环境搭建及入门实例【附详细代码】

    http://blog.csdn.net/xiefu5hh/article/details/51707529 Spark+ECLIPSE+JAVA+MAVEN windows开发环境搭建及入门实例[附 ...

  5. MyBatis之MyBatis环境搭建

    MyBatis之MyBatis环境搭建 一.MyBatis开发环境搭建 1.引入Jar包 ①MyBatis mybatis-3.4.1.jar ant-1.9.6.jar ant-launcher-1 ...

  6. Mybatis环境搭建中的案例分析 及 如果自己编写DAO接口的实现类

    Mybatis环境搭建中的案例分析public static void main (String[] args) throws Exception { //读配置文件 //第一个: 使用类加载器,只能 ...

  7. (十八)整合Nacos组件,环境搭建和入门案例详解

    整合Nacos组件,环境搭建和入门案例详解 1.Nacos基础简介 1.1 关键特性 1.2 专业术语解释 1.3 Nacos生态圈 2.SpringBoot整合Nacos 2.1 新建配置 2.2 ...

  8. MyBatis 环境搭建(四)

    MyBatis 引言 在回顾JDBC时,我们已经创建有 Java 工程,而且也已经导入 mysql 依赖包,这里就直接在原有工程上搭建MyBatis环境,以及使用MyBatis来实现之前用 JDBC ...

  9. Mybatis环境搭建及测试

    1.新建java project,导入相应jar包 本次使用到的mybatis-3.2.7版本 mybatis需要jar包:mybatis-3.2.7.jar.lib文件下的依赖jar mysql驱动 ...

随机推荐

  1. Android JNI开发生成.h头文件问题(转)

    在JNI开发中,首先要将建立的anroid类编译成.h文件,编译用到命令javah,由于第一次用,以前对java的编译过程也不怎么了解,所以走了好多弯路,网络没有对这一步的详细介绍,这里讲一下: 通过 ...

  2. (C#基础) byte[] 之初始化, 赋值,转换。(转)

    byte[] 之初始化赋值 用for loop 赋值当然是最基本的方法,不过在C#里面还有其他的便捷方法. 1. 创建一个长度为10的byte数组,并且其中每个byte的值为0. byte[] myB ...

  3. $(function(){})与window.onload的区别

    不太一样window.onload是在页面所有的元素都加载完成后才触发$(function(){})是在页面的dom结构加载完毕后就触发 dom里的内容不一定都已经加载完成比如说一个页面有好多图片 而 ...

  4. windows修改虚拟内存

    右键电脑属性: 高级系统设置: 性能设置: 虚拟内存更改:

  5. hdu1863 最小生成树(prim)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1863 思路:最小生成树模板题,直接套模板. 代码: #include<iostrea ...

  6. 制作一个访问量很高的大型网站,你会如何来管理所有HTML、CSS、JS与图片?

    1.先确定全局样式和编码方式. 2.编写习惯,标注样式. 3.文件夹存放,命名.

  7. BZOJ 3053 The Closest M Points

    [题目分析] 典型的KD-Tree例题,求k维空间中的最近点对,只需要在判断的过程中加上一个优先队列,就可以了. [代码] #include <cstdio> #include <c ...

  8. CSS3-样式继承,层叠管理,文本格式化

  9. jquery.color.js的使用

    Jquery本身不支持变色,Jquery Color.js弥补了这缺陷并为animate动画赋予变色效果,如下红变蓝后执行回调再由蓝变红. <!DOCTYPE html> <html ...

  10. JavaScript类型转换

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...