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. Codeforces Round #276 (Div. 1) E. Sign on Fence 二分+主席树

    E. Sign on Fence   Bizon the Champion has recently finished painting his wood fence. The fence consi ...

  2. Toast通知

    win10 app 开发中Toast通知的模板只有一种,统一为 ToastGeneric 通用型通知,本文我们来讲讲 Toast 的 XML文档相关知识. 在以前8.1时候的Toast通知方式,到了W ...

  3. SQL简繁转换函数

    declare @jall nvarchar(4000),@fall nvarchar(4000) select @jall=N'啊阿埃挨哎唉哀皑癌蔼矮艾碍爱隘鞍氨安俺按暗岸胺案肮昂盎凹敖熬翱袄傲奥懊 ...

  4. CDN网络的原理

    来源:http://blog.csdn.net/coolmeme/article/details/9468743 版权声明:本文为博主原创文章,未经博主允许不得转载. 1.用户向浏览器输入www.we ...

  5. Loadrunner中参数化实战(9)-Unique+Once

    参数化数据30条: 脚本如下,演示登录,投资,退出操作是,打印手机号: 首先验证Vugen中迭代: Unique+Once 设置迭代4次Action 结果如下:

  6. ASP.NET中的GridView自带的编辑更新功能

    string ConStr = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].Connec ...

  7. 用padding与margin做多个元素的等间距分布

    这样做的好处是不管有多少个元素等间距分布,都可以直接写在li中,而且由于是给a设定的样式,所以在字数不一致的情况下,样式仍然是统一的. html: <!DOCTYPE html> < ...

  8. 使用jQuery要注意的问题

    1. $.find()与$.children()的区别 有如下HTML片段: 复制代码代码如下: <div id="div_four"> <input id=&q ...

  9. Codeforces Round #375 (Div. 2) - B

    题目链接:http://codeforces.com/contest/723/problem/B 题意:给定一个字符串.只包含_,大小写字母,左右括号(保证不会出现括号里面套括号的情况),_分隔开单词 ...

  10. WPF点补间、拟合回归直线

    1,path画刷,绘制正弦 点,线: 生成正弦点 profilePoint.Value = * ( - Math.Sin(i * Math.PI / )); profilePoint.Type = ; ...