MyBatis环境搭建配置文件+入门视频下载
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环境搭建配置文件+入门视频下载的更多相关文章
- Mybatis学习笔记之---环境搭建与入门
Mybatis环境搭建与入门 (一)环境搭建 (1)第一步:创建maven工程并导入jar包 <dependencies> <dependency> <groupId&g ...
- MyBatis -01- 初识 MyBatis + MyBatis 环境搭建
MyBatis -01- 初识 MyBatis + MyBatis 环境搭建 MyBatis 本是 apache 的一个开源项目 iBatis(iBATIS = "internet" ...
- Android菜鸟的成长笔记(1)——Android开发环境搭建从入门到精通
原文:Android菜鸟的成长笔记(1)--Android开发环境搭建从入门到精通 今天在博客中看到好多Android的初学者对Android的开发环境的搭建不熟悉而导致不能进行学习,所以我决定自己写 ...
- Spark+ECLIPSE+JAVA+MAVEN windows开发环境搭建及入门实例【附详细代码】
http://blog.csdn.net/xiefu5hh/article/details/51707529 Spark+ECLIPSE+JAVA+MAVEN windows开发环境搭建及入门实例[附 ...
- MyBatis之MyBatis环境搭建
MyBatis之MyBatis环境搭建 一.MyBatis开发环境搭建 1.引入Jar包 ①MyBatis mybatis-3.4.1.jar ant-1.9.6.jar ant-launcher-1 ...
- Mybatis环境搭建中的案例分析 及 如果自己编写DAO接口的实现类
Mybatis环境搭建中的案例分析public static void main (String[] args) throws Exception { //读配置文件 //第一个: 使用类加载器,只能 ...
- (十八)整合Nacos组件,环境搭建和入门案例详解
整合Nacos组件,环境搭建和入门案例详解 1.Nacos基础简介 1.1 关键特性 1.2 专业术语解释 1.3 Nacos生态圈 2.SpringBoot整合Nacos 2.1 新建配置 2.2 ...
- MyBatis 环境搭建(四)
MyBatis 引言 在回顾JDBC时,我们已经创建有 Java 工程,而且也已经导入 mysql 依赖包,这里就直接在原有工程上搭建MyBatis环境,以及使用MyBatis来实现之前用 JDBC ...
- Mybatis环境搭建及测试
1.新建java project,导入相应jar包 本次使用到的mybatis-3.2.7版本 mybatis需要jar包:mybatis-3.2.7.jar.lib文件下的依赖jar mysql驱动 ...
随机推荐
- RDS MySQL 全文检索相关问题的处理
RDS MySQL 全文检索相关问题 1. RDS MySQL 对全文检索的支持 2. RDS MySQL 全文检索相关参数 3. RDS MySQL 全文检索中文支持 3.1 MyISAM 引擎表 ...
- flex_宽度补全
宽度40px,另一个的补全宽度: <!DOCTYPE html> <html lang="en"> <head> <meta charse ...
- BZOJ 2342 回文串-Manacher
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2342 思路:先跑一遍Manacher求出p[i]为每个位置为中心的回文半径,因为双倍回文串 ...
- 关于DOM
前言 DOM的作用是将网页转为一个javascript对象,从而可以使用javascript对网页进行各种操作(比如增删内容).浏览器会根据DOM模型,将HTML文档解析成一系列的节点,再由这些节点组 ...
- 【CLR Via C#】第5章 基元类型、引用类型、值类型
第二遍看这本书,决定记录一下加深印象. 1,基元类型 什么事基元类型?基元类型是直接映射到FrameWork类库(FCL)中存在的类型,编译器直接支持的数据类型.比如int直接映射到System.In ...
- 解决eclipse报PermGen space内存溢出异常的问题
异常问题如下所示: 1.点击Eclipse->Window->Preferences,如下所示: 2.点击Server->Runtime Environments,选择Apache ...
- How to retrieve instance parameters from an uninstantiated (uninserted) family
The trick to be able to read the default values for instance parameters is to get to the FamilyManag ...
- 【Oralce】时间操作
加法 select sysdate,add_months(sysdate,12) from dual; --加1年 select sysdate,add_months(sysdate,1 ...
- 一个简单的C语言语法检查器的实现
我自己的实现方法的核心过程:首先用一个非终结符代表所有要检查的程序代码,然后根据文法将这个整体的符号不断展开,以拼凑成按检查的程序的顺序排列的终结符序列,能成功说明语法正确,否则有错误. 关键词:分词 ...
- 【BZOJ3531】[Sdoi2014]旅行 树链剖分+动态开点线段树
[BZOJ3531][Sdoi2014]旅行 Description S国有N个城市,编号从1到N.城市间用N-1条双向道路连接,满足从一个城市出发可以到达其它所有城市.每个城市信仰不同的宗教,如飞天 ...