ibatis 搭建环境

本文详细介绍了如何使用IBatis框架配置与Oracle数据库的连接,包括配置文件的编写、属性注入以及实体映射文件的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、导入相应的jar包

2、配置文件:

jdbc连接的属性文件

driver = oracle.jdbc.driver.OracleDriver

url = jdbc:oracle:thin:@127.0.0.1:1521:orcl

username = itcast

password = itcast

总配置文件

<?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"/>

 <transactionManager type="JDBC">

      <dataSource type="SIMPLE">

                   <property value="${driver}" name="JDBC.Driver"/>  来自.properties文件上面的

                  <property value="${url}" name="JDBC.ConnectionURL"/>

                 <property value="${username}" name="JDBC.Username"/>

                  <property value="${password}" name="JDBC.Password"/>

    </dataSource>

</transactionManager>

<sqlMap resource="Student.xml"/>

</sqlMapConfig>

关于每个实体的映射文件(map 文件)

 

<?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-2.dtd " >

<sqlMap>

<!-- Result maps describe the mapping between the columns returned from a query, and the class properties. A result map isn't necessary if the columns (or allases)

match to the properties exactly.-->

<resultMap id="StudentResult" class="Student">

    <result property = "sid" column="sid"/>

     <result property = "sname"  column="sname"/>

    <result property = "major" column="major"/>

    <result property = "birth" column="birth"/>

</resultMap>

</sqlMap>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值