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驱动 ...
随机推荐
- Android adb的使用
参考:http://blog.csdn.net/veryitman/article/details/6437090 1. 进入shell 进入设备shell adb shell 2. 安装 apk & ...
- JFreeChart 使用一 饼图之高级特性
原文链接:http://www.cnblogs.com/jtmjx/archive/2013/04/23/jfreechart_advantage.html 本文主要讲解JFreeChart中饼图的一 ...
- ASP.NET MVC使用过滤器进行权限控制
1.新建MVC项目 2.找到Models文件夹,新建 LoginCheckFilterAttribute 类 public class LoginCheckFilterAttribute : Acti ...
- Android 蹲坑的疑难杂症集锦一
各位看官老爷子你们好,我就是那个挖坑不埋,还喜欢开新矿的小喵同志. 问大家一个问题,在Github上找项目的时候,看到中文简介说明你们是不是觉得这个项目很low不屑一顾? 最近朋友无意中说,在Gith ...
- CSS3 2D 转换
2D 转换 在本章中,您将学到如下 2D 转换方法: translate() rotate() scale() skew() matrix() 您将在下一章学习 3D 转换. 实例 div { tra ...
- Uva 10976 Fractions Again?!
直接暴力 没技巧 y应该从k+1开始循环,因为不然y-k<0的时候 你相当于(x*y) % (负数) 了. #include <iostream> using namespace s ...
- Python与Hack之Unix口令
1.在实验时候,先导入crypt库:必须在Unix环境下才能实现这个模块 2.代码贴一下,以后有了Unix环境试试吧: import cryptimport syssys.modules['Crypt ...
- hive streaming 使用shell脚本
一.HIVE streaming 在Hive中,需要实现Hive中的函数无法实现的功能时,就可以用Streaming来实现.其原理可以理解成:用HQL语句之外的语言,如Python.Shell来实现这 ...
- [转载]Robotium API 翻译(三)——判断测试结果的方法assert、is、search
该文来源于:http://blog.csdn.net/dongmu1986 下面的这些方法都主要用来判断测试结果是否与预期结果相符,一般把is和search方法放在assert里面判断.asser ...
- 【原】iOS学习40网络之数据安全
在互联网发展趋势迅猛的今天,数据安全的重要性日趋凸显.也成为我们必须了解的互联网知识. 在移动互联网浪潮下,用户的资金安全.企业的信息安全都是我们实际开发中必须考虑的内容.