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 >
select sid,sname,major,birth,score from Student
where sname like '%$sname$%'
</select>
</sqlMap>

 

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

 

 

 

相关文章:

  • 2021-08-07
  • 2021-12-10
  • 2022-12-23
  • 2021-06-17
  • 2022-12-23
  • 2021-04-15
  • 2022-12-23
猜你喜欢
  • 2021-12-24
  • 2021-11-28
  • 2021-07-18
  • 2021-06-27
  • 2021-08-21
  • 2022-12-23
  • 2021-12-14
相关资源
相似解决方案