`

Using Ibatis 1

    博客分类:
  • SQL
阅读更多
1.mapping file: site.xml
<?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 namespace="SiteConfig">

	<typeAlias alias="SiteConfig"
		type="com.dingfei.vo.SiteConfig" />
		
	<resultMap id="SiteConfigMap" class="SiteConfig">
		<result property="siteID" column="SITEID"/>
		<result property="itemName" column="ITEMNAME"/>
		<result property="itemValue" column="ITEMVALUE"/>
	</resultMap>
	
	<parameterMap id="SiteConfigParamMap" class="SiteConfig">
		<parameter property="siteID" />
		<parameter property="itemName" />
		<parameter property="itemValue" />
	</parameterMap>

	<!-- using VOMap as resultMap -->
	<select id="selectAllSiteConfig" resultMap="SiteConfigMap">
		Select SITEID,ITEMNAME,ITEMVALUE from siteConfig
	</select>
	
	<select id="updateSite" parameterClass="java.util.HashMap">
		update siteConfig
		set ITEMVALUE=#itemvalue#
		where SITEID = #siteid# and ITEMNAME=#itemname#
	</select>
	
	<!-- using HashMap as  parameterClass-->
	<insert id="insertSiteByMap" parameterClass="java.util.HashMap"> 
		insert into siteConfig(SITEID,ITEMNAME,ITEMVALUE)
		values(#siteid#,#itemname#,#itemvalue#)
	</insert>
	
	<!-- using HashMap as parameterClass, PK-siteid is auto-increment -->
	<insert id="insertSiteByMapWithoutSiteID" parameterClass="java.util.HashMap"> 
		insert into siteConfig(ITEMNAME,ITEMVALUE)
		values(#itemname#,#itemvalue#)
	</insert>
	
	<!-- using VO mapping as parameterClass -->
	<insert id="insertSiteByVO" parameterClass="SiteConfig"> 
		insert into siteConfig(SITEID,ITEMNAME,ITEMVALUE)
		values(#siteID#,#itemName#,#itemValue#)
	</insert>
	
	<!-- using  VOMap as parameterMap-->
	<insert id="insertSiteByVOMap" parameterMap="SiteConfigParamMap"> 
		insert into siteConfig(SITEID,ITEMNAME,ITEMVALUE)
		values(?,?,?)
	</insert>
	
	<delete id="deleteSiteBySiteID">
		delete 
		from siteConfig
		where siteID = #siteid#
	</delete>
</sqlMap>


2. employee.xml
  <?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 namespace="Employee">

	<typeAlias alias="Employee"
		type="com.dingfei.vo.Employee" />
		
	<resultMap id="EmployeeMap" class="Employee">
		<result property="userName" column="username"/>
		<result property="email" column="email"/>
	</resultMap>

	<select id="selectAllEmployee" resultMap="EmployeeMap">
		Select * from Employee
	</select>
</sqlMap>
0
0
分享到:
评论

相关推荐

    Using Ibatis

    1. 配置文件:Ibatis的配置文件主要包含数据源、事务管理器、SqlSessionFactory的配置,它是Ibatis运行的基础。 2. SqlSessionFactory:Ibatis的核心工厂类,用于创建SqlSession对象,SqlSession是执行SQL的入口。 ...

    Using Ibatis 2

    1. 配置文件:Ibatis的配置文件(ibatis-config.xml)包含了数据源、事务管理器等全局配置信息,是启动Ibatis的起点。 2. SQL Map配置:每个数据库表通常对应一个SQL Map文件,如SiteConfig.sql和Employee.sql,...

    ibatis培训教程

    #### 一、iBATIS基础 (Chapter 1: iBATIS Basic) - **定义**: iBATIS是一个开源框架,用于简化Java应用程序与关系数据库之间的交互。它通过对象关系映射(ORM)技术实现了这一目标。 - **功能**: 提供了一种简单的...

    一个程序员的自省 iBATIS In Action:什么是iBATIS(一)

    iBATIS,全称为“Integrated Business Applications Using the SQL Maps”,是一个数据映射框架,由Anders Cui在2007年的文章中提及。iBATIS并非传统的对象关系映射(ORM)工具,而是采取了一种混合式解决方案,融合...

    IBatisDemo:Ibatis的一个简单Demo

    using (var session = factory.OpenSession()) { var userMapper = session.GetMapper(); var user = userMapper.SelectUserById(1); } ``` **6. 事务管理** IBatis支持自动和手动的事务管理。在上面的例子中,`...

    MVC框架2 struts2+ibatis+spring

    // Implementation using iBatis // ... } ``` 此类负责数据库操作,具体实现细节可能涉及SQL映射文件的编写和iBatis配置。 综上所述,Struts2+iBatis+Spring组成的MVC框架通过清晰的分层结构和各组件间的协作,...

    Asp.net 应用Ibatis 小例子

    1. **配置Ibatis**: 在Asp.net项目中,首先需要引入Ibatis的库,并在Web.config或App.config中配置SqlMapConfig.xml文件的位置。 2. **创建SqlMap**: 根据需求创建SqlMap.xml文件,定义SQL语句和结果映射。例如,...

    ibatis实例(C#)

    **Ibatis 实例 (C#)** Ibatis 是一个流行的数据访问框架,它在Java世界中广泛应用,但现在也有.NET版本,允许开发者将SQL查询与应用程序的业务逻辑分离,提高代码的可维护性和灵活性。本实例将详细介绍如何在C#环境...

    iBatis-设置缓存模式-Java源码(下载)

    PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd"&gt; &lt;sqlMap namespace="Account"&gt; &lt;typeAlias alias="Account" type="Account"/&gt; ...

    Ibatis.net的一个简单的测试

    int userId = 1; // 需要删除的用户ID sqlMapper.Delete("User.DeleteUser", userId); ``` 添加和更新操作与删除类似,通过insert和update元素定义SQL语句,然后调用SqlMapper的Insert或Update方法。例如: ```xml...

    iBATIS入门教程

    iBATIS,全称为“Integrated Business Applications Using the Java Persistence API”,中文译为“基于Java持久层的应用集成框架”。它是一个开源的Java库,主要用于简化数据库访问,并提供了将SQL语句与Java代码...

    iBATIS3用户指南(EngLish)

    - **Using a Custom Cache**:使用自定义缓存实现。 - 示例代码: ```xml ``` - **cache-ref**:引用其他映射器的缓存。 - 示例代码: ```xml ``` #### 七、动态 SQL - 动态 SQL 支持在运行时动态生成...

    IBatisNet的Codesmith模板

    Find, loads a database record using primary key value(s). FindByXXX, loads a group of records by the value of a column. Delete, deletes a database record. DeleteByXXX, deletes a group of records of...

    mybaits(ibatis)-3.0.6-bundle for java

    MyBatis couples objects with stored procedures or SQL statements using a XML descriptor. Simplicity is the biggest advantage of the MyBatis data mapper over object relational mapping tools. To use ...

    BATIS介绍.

    1. 在类路径中提供iBATIS的配置文件`sqlMapConfig.xml`: ```xml &lt;!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-config-2.dtd"&gt; ...

    Using jdbc so easy!-开源

    标题中的“Using jdbc so easy!”指的是使用Java数据库连接(JDBC)可以变得非常简单,而“开源”则意味着这里涉及的解决方案是开放源代码的,允许用户自由地查看、使用、修改和分发代码。在描述中,“sql-mapper”...

    ibatisnet連接sql server 2008連接方法

    在.NET开发环境中,Ibatis.Net是一个流行的持久层框架,它提供了灵活的数据访问接口,与SQL Server 2008数据库的交互是其重要功能之一。本文将深入探讨如何使用IbatisNet连接到SQL Server 2008,以及相关的C#编程...

    appfuse-documentation-2.0

    - **Using iBATIS**:iBATIS是一个轻量级的持久层框架,用于执行SQL语句和管理结果集。 - **Using JPA**:Java Persistence API提供了一种标准化的方法来访问关系型数据库。 ##### 3.4 服务端技术 - **Web Services...

    IBatisNet的用法

    IBatisNet,全称为iBATIS.NET,是一款基于.NET Framework的持久层框架,由iBATIS项目发展而来,旨在简化数据库操作与对象模型的映射,从而减轻开发人员在数据访问层的工作负担。它提供了一种灵活的数据访问接口,...

Global site tag (gtag.js) - Google Analytics