asp.net搭建mybatis开发环境

mybatis其实就是ibatis的升级版本不仅能在java上使用,asp.net照样可以使用mybatis来开发程序。mybatis是一个比较小巧的ORM框架,类似hibernate。自己试了一下用法和java上的mybatis差不多。这次在.net的平台上我也来小试牛刀,弄个小程序出来看看,开发之前要去mybatis官网上下载2个包。

1.asp.net版本的mybatis下载地址是http://www.mybatis.org/dotnet.html,如下图所示

如果有必要的话可以连开发文档一起下载。

 

2.把下面的dll文件全部拷贝出来,之后在项目里添加引用。日志的那个开发包可以不选

3.为了开发方便我这里在项目里添加了一个数据库student,并且建了一个学生表m_student

 

4.在项目里添加一个配置文件,这个文件存有所需要的连接配置,类似于hibernate里的方言。该文件可以从下载的包里拷贝出来使用名称为Providers.config

文件内容如下

<?xml version="1.0"?>
<providers xmlns="http://ibatis.apache.org/providers"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <clear/>
  <provider
      name="sqlServer1.0"
      description="Microsoft SQL Server, provider V1.0.3300.0 in framework .NET V1.0"
      enabled="true"
      assemblyName="System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" connectionClass="System.Data.SqlClient.SqlConnection"
      commandClass="System.Data.SqlClient.SqlCommand"
      parameterClass="System.Data.SqlClient.SqlParameter"
      parameterDbTypeClass="System.Data.SqlDbType"
      parameterDbTypeProperty="SqlDbType"
      dataAdapterClass="System.Data.SqlClient.SqlDataAdapter"
      commandBuilderClass="System.Data.SqlClient.SqlCommandBuilder"
      usePositionalParameters="false"
      useParameterPrefixInSql="true"
      useParameterPrefixInParameter="true"
      parameterPrefix="@"
      allowMARS="false"
  />
  <provider
      name="sqlServer1.1"
      description="Microsoft SQL Server, provider V1.0.5000.0 in framework .NET V1.1"
      enabled="true"
      default="true"
      assemblyName="System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
      connectionClass="System.Data.SqlClient.SqlConnection"
      commandClass="System.Data.SqlClient.SqlCommand"
      parameterClass="System.Data.SqlClient.SqlParameter"
      parameterDbTypeClass="System.Data.SqlDbType"
      parameterDbTypeProperty="SqlDbType"
      dataAdapterClass="System.Data.SqlClient.SqlDataAdapter"
      commandBuilderClass="System.Data.SqlClient.SqlCommandBuilder"
      usePositionalParameters="false"
      useParameterPrefixInSql="true"
      useParameterPrefixInParameter="true"
      parameterPrefix="@"
      allowMARS="false"
  />
  <!--SqlServer 2.0 SQl-->
  <provider
    name="sqlServer2.0"
    enabled="true"
    description="Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0"
    assemblyName="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    connectionClass="System.Data.SqlClient.SqlConnection"
    commandClass="System.Data.SqlClient.SqlCommand"
    parameterClass="System.Data.SqlClient.SqlParameter"
    parameterDbTypeClass="System.Data.SqlDbType"
    parameterDbTypeProperty="SqlDbType"
    dataAdapterClass="System.Data.SqlClient.SqlDataAdapter"
    commandBuilderClass=" System.Data.SqlClient.SqlCommandBuilder"
    usePositionalParameters = "false"
    useParameterPrefixInSql = "true"
    useParameterPrefixInParameter = "true"
    parameterPrefix="@"
    allowMARS="false"
    />
  
  <provider name="OleDb1.1"
      description="OleDb, provider V1.0.5000.0 in framework .NET V1.1"
      enabled="true"
      assemblyName="System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    connectionClass="System.Data.OleDb.OleDbConnection"
      commandClass="System.Data.OleDb.OleDbCommand"
      parameterClass="System.Data.OleDb.OleDbParameter"
      parameterDbTypeClass="System.Data.OleDb.OleDbType"
      parameterDbTypeProperty="OleDbType"
      dataAdapterClass="System.Data.OleDb.OleDbDataAdapter"
      commandBuilderClass="System.Data.OleDb.OleDbCommandBuilder"
      usePositionalParameters="true"
      useParameterPrefixInSql="false"
      useParameterPrefixInParameter="false"
      parameterPrefix=""
    allowMARS="false"
    />
  <provider name="OleDb2.0"
    description="OleDb, provider V2.0.0.0 in framework .NET V2"
    enabled="false"
    assemblyName="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    connectionClass="System.Data.OleDb.OleDbConnection"
    commandClass="System.Data.OleDb.OleDbCommand"
    parameterClass="System.Data.OleDb.OleDbParameter"
    parameterDbTypeClass="System.Data.OleDb.OleDbType"
    parameterDbTypeProperty="OleDbType"
    dataAdapterClass="System.Data.OleDb.OleDbDataAdapter"
    commandBuilderClass="System.Data.OleDb.OleDbCommandBuilder"
    usePositionalParameters="true"
    useParameterPrefixInSql="false"
    useParameterPrefixInParameter="false"
    parameterPrefix=""
    allowMARS="false"
    />
  <provider
    name="Odbc1.1"
    description="Odbc, provider V1.0.5000.0 in framework .NET V1.1"
    enabled="false"
    assemblyName="System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    connectionClass="System.Data.Odbc.OdbcConnection"
    commandClass="System.Data.Odbc.OdbcCommand"
    parameterClass="System.Data.Odbc.OdbcParameter"
    parameterDbTypeClass="System.Data.Odbc.OdbcType"
    parameterDbTypeProperty="OdbcType"
    dataAdapterClass="System.Data.Odbc.OdbcDataAdapter"
    commandBuilderClass="System.Data.Odbc.OdbcCommandBuilder"
    usePositionalParameters="true"
    useParameterPrefixInSql="false"
    useParameterPrefixInParameter="false"
    parameterPrefix="@"
    allowMARS="false"
    />
  <!--ODBC 2.0 Support-->
  <provider
    name="Odbc2.0"
    description="Odbc, provider V2.0.0.0 in framework .NET V2"
    enabled="false"
    assemblyName="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    connectionClass="System.Data.Odbc.OdbcConnection"
    commandClass="System.Data.Odbc.OdbcCommand"
    parameterClass="System.Data.Odbc.OdbcParameter"
    parameterDbTypeClass="System.Data.Odbc.OdbcType"
    parameterDbTypeProperty="OdbcType"
    dataAdapterClass="System.Data.Odbc.OdbcDataAdapter"
    commandBuilderClass="System.Data.Odbc.OdbcCommandBuilder"
    usePositionalParameters="true"
    useParameterPrefixInSql="false"
    useParameterPrefixInParameter="false"
    parameterPrefix="@"
    allowMARS="false"
  />
  
  <provider
    name="oracle9.2"
    description="Oracle, Oracle provider V9.2.0.401"
    enabled="false"
    assemblyName="Oracle.DataAccess, Version=9.2.0.401, Culture=neutral, PublicKeyToken=89b483f429c47342" connectionClass="Oracle.DataAccess.Client.OracleConnection"
    commandClass="Oracle.DataAccess.Client.OracleCommand"
    parameterClass="Oracle.DataAccess.Client.OracleParameter"
    parameterDbTypeClass="Oracle.DataAccess.Client.OracleDbType"
    parameterDbTypeProperty="OracleDbType"
    dataAdapterClass="Oracle.DataAccess.Client.OracleDataAdapter"
    commandBuilderClass="Oracle.DataAccess.Client.OracleCommandBuilder"
    usePositionalParameters="false"
    useParameterPrefixInSql="true"
    useParameterPrefixInParameter="false"
    parameterPrefix=":"
    useDeriveParameters="false"
    allowMARS="false"
  />
  <provider
    name="oracle10.1"
    description="Oracle, oracle provider V10.1.0.301"
    enabled="false"
    assemblyName="Oracle.DataAccess, Version=10.1.0.301, Culture=neutral, PublicKeyToken=89b483f429c47342" connectionClass="Oracle.DataAccess.Client.OracleConnection"
    commandClass="Oracle.DataAccess.Client.OracleCommand"
    parameterClass="Oracle.DataAccess.Client.OracleParameter"
    parameterDbTypeClass="Oracle.DataAccess.Client.OracleDbType"
    parameterDbTypeProperty="OracleDbType"
    dataAdapterClass="Oracle.DataAccess.Client.OracleDataAdapter"
    commandBuilderClass="Oracle.DataAccess.Client.OracleCommandBuilder"
    usePositionalParameters="true"
    useParameterPrefixInSql="true"
    useParameterPrefixInParameter="true"
    parameterPrefix=":"
    useDeriveParameters="false"
    allowMARS="false"
  />
  <!--Oracle Support-->
  <provider
    name="oracleClient1.0"
    description="Oracle, Microsoft provider V1.0.5000.0"
    enabled="false"
    assemblyName="System.Data.OracleClient, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" connectionClass="System.Data.OracleClient.OracleConnection"
    commandClass="System.Data.OracleClient.OracleCommand"
    parameterClass="System.Data.OracleClient.OracleParameter"
    parameterDbTypeClass="System.Data.OracleClient.OracleType"
    parameterDbTypeProperty="OracleType"
    dataAdapterClass="System.Data.OracleClient.OracleDataAdapter"
    commandBuilderClass="System.Data.OracleClient.OracleCommandBuilder"
    usePositionalParameters="false"
    useParameterPrefixInSql="true"
    useParameterPrefixInParameter="false"
    parameterPrefix=":"
    allowMARS="false"
  />
  <!--ByteFX Support-->
  <provider
    name="ByteFx"
    description="MySQL, ByteFx provider V0.7.6.15073"
    enabled="false"
    assemblyName="ByteFX.MySqlClient, Version=0.7.6.15073, Culture=neutral, PublicKeyToken=f2fef6fed1732fc1" connectionClass="ByteFX.Data.MySqlClient.MySqlConnection"
    commandClass="ByteFX.Data.MySqlClient.MySqlCommand"
    parameterClass="ByteFX.Data.MySqlClient.MySqlParameter"
    parameterDbTypeClass="ByteFX.Data.MySqlClient.MySqlDbType"
    parameterDbTypeProperty="MySqlDbType"
    dataAdapterClass="ByteFX.Data.MySqlClient.MySqlDataAdapter"
    commandBuilderClass="ByteFX.Data.MySqlClient.MySqlCommandBuilder"
    usePositionalParameters="false"
    useParameterPrefixInSql="true"
    useParameterPrefixInParameter="true"
    parameterPrefix="@"
    allowMARS="false"
  />
  <!--MySql Support-->
  <provider
    name="MySql"
    description="MySQL, MySQL provider 1.0.7.30072"
    enabled="false"
    assemblyName="MySql.Data, Version=1.0.7.30072, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionClass="MySql.Data.MySqlClient.MySqlConnection"
    commandClass="MySql.Data.MySqlClient.MySqlCommand"
    parameterClass="MySql.Data.MySqlClient.MySqlParameter"
    parameterDbTypeClass="MySql.Data.MySqlClient.MySqlDbType"
    parameterDbTypeProperty="MySqlDbType"
    dataAdapterClass="MySql.Data.MySqlClient.MySqlDataAdapter"
    commandBuilderClass="MySql.Data.MySqlClient.MySqlCommandBuilder"
    usePositionalParameters="false"
    useParameterPrefixInSql="true"
    useParameterPrefixInParameter="true"
    parameterPrefix="?"
    allowMARS="false"
  />
  <!--SQLite 3 Support-->
  <provider name="SQLite3"
    description="SQLite, SQLite.NET provider V0.21.1869.3794"
    enabled="false"
    assemblyName="SQLite.NET, Version=0.21.1869.3794, Culture=neutral, PublicKeyToken=c273bd375e695f9c"
    connectionClass="Finisar.SQLite.SQLiteConnection"
    commandClass="Finisar.SQLite.SQLiteCommand"
    parameterClass="Finisar.SQLite.SQLiteParameter"
    parameterDbTypeClass="System.Data.DbType, System.Data"
    parameterDbTypeProperty="DbType"
    dataAdapterClass="Finisar.SQLite.SQLiteDataAdapter"
    commandBuilderClass="Finisar.SQLite.SQLiteCommandBuilder"
    usePositionalParameters="false"
    useParameterPrefixInSql="true"
    useParameterPrefixInParameter="true"
    parameterPrefix="@"
    setDbParameterPrecision="false"
    setDbParameterScale="false"
    allowMARS="false"
  />
  <!--Firebird Support-->
  <provider
    name="Firebird1.7"
    description="Firebird, Firebird SQL .NET provider V1.7.0.33200"
    enabled="false"
    assemblyName="FirebirdSql.Data.Firebird, Version=1.7.0.33200, Culture=neutral, PublicKeyToken=fa843d180294369d" connectionClass="FirebirdSql.Data.Firebird.FbConnection"
    commandClass="FirebirdSql.Data.Firebird.FbCommand"
    parameterClass="FirebirdSql.Data.Firebird.FbParameter"
    parameterDbTypeClass="FirebirdSql.Data.Firebird.FbDbType"
    parameterDbTypeProperty="FbDbType"
    dataAdapterClass="FirebirdSql.Data.Firebird.FbDataAdapter"
    commandBuilderClass="FirebirdSql.Data.Firebird.FbCommandBuilder"
    usePositionalParameters="false"
    useParameterPrefixInSql="true"
    useParameterPrefixInParameter="true"
    parameterPrefix="@"
    allowMARS="false"
  />
  <!--PostgreSql Support-->
  <provider
    name="PostgreSql0.99.1.0"
    description="PostgreSql, Npgsql provider V0.99.1.0"
    enabled="false"
    assemblyName="Npgsql, Version=0.99.1.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7"
    connectionClass="Npgsql.NpgsqlConnection"
    commandClass="Npgsql.NpgsqlCommand"
    parameterClass="Npgsql.NpgsqlParameter"
    parameterDbTypeClass="NpgsqlTypes.NpgsqlDbType"
    parameterDbTypeProperty="NpgsqlDbType"
    dataAdapterClass="Npgsql.NpgsqlDataAdapter"
    commandBuilderClass="Npgsql.NpgsqlCommandBuilder"
    usePositionalParameters="false"
    useParameterPrefixInSql="true"
    useParameterPrefixInParameter="true"
    parameterPrefix=":"
    allowMARS="true"
  />
  <!--DB2 Support-->
  <provider
    name="iDb2.10"
    description="IBM DB2 Provider, V 10.0"
    enabled="false"
    assemblyName="IBM.Data.DB2.iSeries, Version=10.0.0.0,Culture=neutral, PublicKeyToken=9cdb2ebfb1f93a26, Custom=null" connectionClass="IBM.Data.DB2.iSeries.iDB2Connection"
    commandClass="IBM.Data.DB2.iSeries.iDB2Command"
    parameterClass="IBM.Data.DB2.iSeries.iDB2Parameter"
    parameterDbTypeClass="IBM.Data.DB2.iSeries.iDB2DbType"
    parameterDbTypeProperty="iDB2DbType"
    dataAdapterClass="IBM.Data.DB2.iSeries.iDB2DataAdapter"
    commandBuilderClass="IBM.Data.DB2.iSeries.iDB2CommandBuilder"
    usePositionalParameters="true"
    useParameterPrefixInSql="false"
    useParameterPrefixInParameter="false"
    parameterPrefix=""
    allowMARS="false"
  />
  <provider
    name="Informix"
    description="Informix NET Provider, 2.81.0.0"
    enabled="false"
    assemblyName="IBM.Data.Informix, Version=2.81.0.0, Culture=neutral, PublicKeyToken=7c307b91aa13d208"
    connectionClass="IBM.Data.Informix.IfxConnection"
    commandClass="IBM.Data.Informix.IfxCommand"
    parameterClass="IBM.Data.Informix.IfxParameter"
    parameterDbTypeClass="IBM.Data.Informix.IfxType"
    parameterDbTypeProperty="IfxType"
    dataAdapterClass="IBM.Data.Informix.IfxDataAdapter"
    commandBuilderClass="IBM.Data.Informix.IfxCommandBuilder"
    usePositionalParameters = "true"
    useParameterPrefixInSql = "false"
    useParameterPrefixInParameter = "false"
    useDeriveParameters="false"
    allowMARS="false"
  />
  <provider
   name="sqlServer2005"
   enabled="true"
   description="Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0"
   assemblyName="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
   connectionClass="System.Data.SqlClient.SqlConnection"
   commandClass="System.Data.SqlClient.SqlCommand"
   parameterClass="System.Data.SqlClient.SqlParameter"
   parameterDbTypeClass="System.Data.SqlDbType"
   parameterDbTypeProperty="SqlDbType"
   dataAdapterClass="System.Data.SqlClient.SqlDataAdapter"
   commandBuilderClass=" System.Data.SqlClient.SqlCommandBuilder"
   usePositionalParameters = "false"
   useParameterPrefixInSql = "true"
   useParameterPrefixInParameter = "true"
   parameterPrefix="@"
   allowMARS="true"
      />
</providers>

最后这个是我自己加上的  

 

 

5.编写持久层代码Student.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace useribatis
{
    public class Student
    {
        public int id { set; get; }
        public String username{ set; get; }
        public String password{ set; get; }
    }
}

    6.编写mybatis的映射文件,需要注意的是名称空间要正确并且完整。我这里只写了一个比较简单的  

 

<?xml version="1.0" encoding="utf-8" ?>
<sqlMap namespace="Student" xmlns="http://ibatis.apache.org/mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  <statements>
    <insert id="create" parameterClass="useribatis.Student">
      insert into m_student(username,password)
      values (#username#,#password#)
    </insert>
  </statements>
</sqlMap>

这里建议大家把名称空间写规范些,parameterClass的地方可以使类全名,配置文件的参数我就不在强调了。  

 

 

7.编写SqlMap.config配置文件

<?xml version="1.0" encoding="utf-8"?>
<sqlMapConfig xmlns="http://ibatis.apache.org/dataMapper"  
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <settings>
    <!-- 启用缓存 -->
    <setting cacheModelsEnabled="true"/>
    <!-- 配置是否使用名称空间这里建议写成true -->
    <setting useStatementNamespaces="true" />

  </settings>
  <!-- 引入providers配置文件 -->
  <providers resource="providers.config"/>
  <database>
    <provider name="sqlServer2005" />
    <!-- 配置连接字符串 -->
    <dataSource name="SqlServer" connectionString="data source=.\SQLEXPRESS;AttachDbFilename=G:\source\useribatis\useribatis\App_Data\Student.mdf;Integrated Security=True;User Instance=True;" />
  </database>

  <sqlMaps>
    <!-- 映射的资源文件 -->
    <sqlMap resource="Maps/StudentInfo.xml"/>
  </sqlMaps>

</sqlMapConfig>

    8.编写一个类用来插入数据  

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using IBatisNet.Common;

using IBatisNet.DataMapper;

using IBatisNet.DataMapper.Configuration;

using IBatisNet.Common.Utilities;

using IBatisNet.DataAccess;

using IBatisNet.DataAccess.Configuration;

using IBatisNet.DataAccess.Interfaces;

 using IBatisNet.Common.Logging;
namespace useribatis
{
    public class Insert
    {
        public void doCreate() {
            DomSqlMapBuilder builder = new DomSqlMapBuilder();
            ISqlMapper Map = builder.Configure("SqlMap.config");
           // SqlMapper sqlMapper = builder.Configure() as SqlMapper;
            Student stu=new Student();
            stu.username="李敏镐3";
            stu.password="1234567";
           
            Map.Insert("Student.create", stu);
        }
       
    }
}

    9.创建单元测试,查看程序是否正确如下所示  

 

 

 

 

之后选择要测试的方法

点击确定,visual studio就会为我们创建单元测试了。之后为单元测试生成以下解决方案,之后就打开测试窗口

下面就可以开始单元测试了,如下所示点击之后运行选定内容

执行完成后来看下数据库是否生成了数据

 

如果程序出错了可以像下面这样做查看异常信息

到这里程序就写好了,下面我贴一个映射文件出来大家以后开发可以模仿着下面的这个写,注意下名称空间的区别就好

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap 
PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap namespace="Course">

<resultMap id="resultMap" class="com.junze.huiju.module.course.info.CourseInfo">
  <result property="REMARK1" column="REMARK1"/>
  <result property="FCOURSENATURE" column="FCOURSENATURE"/>
  <result property="REMARK2" column="REMARK2"/>
  <result property="FCOURSENUM" column="FCOURSENUM"/>
  <result property="FID" column="FID"/>
  <result property="FNAME" column="FNAME"/>
</resultMap>

<sql id="sqlwhere">	
  <dynamic>
    <isNotEmpty prepend="and" property="REMARK1">
      A.REMARK1 like #REMARK1#
    </isNotEmpty>
    <isGreaterThan prepend="and" property="FCOURSENATURE" compareValue="0">
      A.FCOURSENATURE = #FCOURSENATURE#
    </isGreaterThan>
    <isNotEmpty prepend="and" property="REMARK2">
      A.REMARK2 like #REMARK2#
    </isNotEmpty>
    <isGreaterThan prepend="and" property="FCOURSENUM" compareValue="0">
      A.FCOURSENUM = #FCOURSENUM#
    </isGreaterThan>
    <isGreaterThan prepend="and" property="FID" compareValue="0">
      A.FID = #FID#
    </isGreaterThan>
    <isNotEmpty prepend="and" property="FNAME">
      A.FNAME like #FNAME#
    </isNotEmpty>
    <isNotEmpty prepend="and" property="containIds">
      A.FID NOT IN ($containIds$)
    </isNotEmpty>
  </dynamic>
</sql>

 <!--getInfoByID-->
<select id="getInfoByID" resultMap="resultMap" parameterClass="int">
 select A.*
   from M_COURSE A where A.FID = #id#
</select>


 <!--read-->
<select id="read" resultMap="resultMap" parameterClass="com.junze.huiju.module.course.info.CourseInfo">
 select A.*
   from M_COURSE A where 1=1 
   <include refid="sqlwhere"/>
</select>

 <!--getlist-->
<select id="getList" resultMap="resultMap" parameterClass="com.junze.huiju.module.course.info.CourseInfo">
 select * from (select rownum numrow ,A.* from (select A.* 
   from M_COURSE A where 1=1 
   <include refid="sqlwhere"/>
   	 Order By A.FID 
 ) A) where numrow > $startRow$ and numrow < $endRow$
</select>

 <!--getAlllist-->
<select id="getAllList" resultMap="resultMap" parameterClass="com.junze.huiju.module.course.info.CourseInfo">
 select A.*
   from M_COURSE A where 1=1 
   <include refid="sqlwhere"/>
   Order By A.FID Desc
</select>

 <!--getBusinessList-->
<select id="getBusinessList" resultMap="resultMap" parameterClass="com.junze.huiju.module.course.info.CourseInfo">
 select A.*
   from M_COURSE A where 1=1 
   <include refid="sqlwhere"/>
   Order By A.FID Desc
</select>

 <!--getCount-->
<select id="getCount" resultClass="java.lang.Integer" parameterClass="com.junze.huiju.module.course.info.CourseInfo">
 select count(*) from M_COURSE A where 1=1 
   <include refid="sqlwhere"/>
</select>

 <!--create-->
<insert id="create" parameterClass="com.junze.huiju.module.course.info.CourseInfo">
<selectKey resultClass="int" keyProperty="FID">
      select SEQ_M_COURSE.nextVal as value from dual
 </selectKey>	  
 insert into M_COURSE(REMARK1,FCOURSENATURE,REMARK2,FCOURSENUM,FID,FNAME) 
 values (#REMARK1:VARCHAR2#,#FCOURSENATURE#,#REMARK2:VARCHAR2#,#FCOURSENUM#,#FID#,#FNAME:VARCHAR2#)
</insert>

 <!--update -->
<update id="update" parameterClass="com.junze.huiju.module.course.info.CourseInfo">
 update M_COURSE set REMARK1= #REMARK1:VARCHAR2#,
    FCOURSENATURE = #FCOURSENATURE#,
    REMARK2 = #REMARK2:VARCHAR2#,
    FCOURSENUM = #FCOURSENUM#,
    FID = #FID#,
    FNAME = #FNAME:VARCHAR2#
 where FID = #FID#
</update>

 <!--deleteByID-->
<delete id="deleteByID" parameterClass="int">
 delete from M_COURSE where FID = #id#
</delete>

 <!--deleteByCondition-->
<delete id="deleteByCondition" parameterClass="com.junze.huiju.module.course.info.CourseInfo">
 delete from M_COURSE A where 1=1 
   <include refid="sqlwhere"/>
</delete>

</sqlMap>

想这样的配置文件应该算是比较完整的了,大家练习一下吧。代码在我的资源里大家自己去下载。如果有写的不对的大家可以拍砖。

posted @ 2015-05-24 20:06  awp110  阅读(302)  评论(0编辑  收藏  举报