日期:2014-05-20  浏览次数:20959 次

求ibatis映射文件在java语言中标准格式?
ibatis框架在.net和java语言中的不同点?

在CodeSmith中生成的.net的ibatis的xml映射的代码为:
<?xml version="1.0" encoding="utf-8" ?> 
<sqlMap 
namespace="VUser" xmlns="http://ibatis.apache.org/mapping" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >

<alias>
<typeAlias alias="VUser" type="USER.VUser, USER" />
</alias>

<resultMaps>
<resultMap id="SelectResult" class="VUser">
<result property="ID" column="ID" />
<result property="USERNAME" column="USERNAME" />
<result property="PASSWORD" column="PASSWORD" />
</resultMap>
</resultMaps>

<statements>

<select id="SelectAll" resultMap="SelectResult">
<![CDATA[
select
ID,
USERNAME,
PASSWORD
from V_USER
]]>
</select>

<select id="SelectById" extends="SelectAll" parameterClass="" resultMap="SelectResult">
<![CDATA[
where
1 = 1
]]>
</select>

<select id="SelectByParam" extends="SelectAll" parameterClass="VUser" resultMap="SelectResult">
<dynamic prepend="WHERE">
<isNotNull prepend="AND" property="ID">
  <![CDATA[ ID = #ID# ]]>
</isNotNull>
<isNotEmpty prepend="AND" property="USERNAME">
  <![CDATA[ USERNAME = #USERNAME# ]]>
</isNotEmpty>
<isNotEmpty prepend="AND" property="PASSWORD">
  <![CDATA[ PASSWORD = #PASSWORD# ]]>
</isNotEmpty>
</dynamic>
</select>

<select id="SelectForPageing" extends="SelectAll" parameterClass="System.Collections.IDictionary">
<dynamic prepend="WHERE">
<isNotNull prepend="AND" property="ID">
  <![CDATA[ ID = #ID# ]]>
</isNotNull>
<isNotNull prepend="AND" property="USERNAME">
  <![CDATA[ USERNAME = #USERNAME# ]]>
</isNotNull>
<isNotNull prepend="AND" property="PASSWORD">
  <![CDATA[ PASSWORD = #PASSWORD# ]]>
</isNotNull>
</dynamic>
</select>
<insert id="Insert" parameterClass="VUser">
<![CDATA[
insert into V_USER
(
ID,
USERNAME,
PASSWORD
)
values 
(
#ID#,
#USERNAME#,
#PASSWORD#
)
]]>
</insert>
<update id="Update" parameterClass="VUser" >
<![CDATA[
update V_USER set
ID = #ID#,
USERNAME = #USERNAME#,
PASSWORD = #PASSWORD#
where
1=1
]]>
</update>
<delete id="Delete" parameterClass="VUser" >
<![CDATA[
delete from V_USER
where 
1=1
]]>
</delete>
</statements>

</sqlMap>

但是这些代码复制到java中就不行了
请问ibatis的映射xml文件在java中标准格式是什么样子的?
谁能给我一个完整的实例?
谢谢

------解决方案--------------------
XML code

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "/conf/dtd/sql-map-2.dtd">

<sqlMap namespace="com.devtek.sys.pb.pojo.Pblog_ipmodify">

    <typeAlias alias="Pblog_ipmodify"
        type="com.devtek.sys.pb.pojo.Pblog_ipmodify" />

    <resultMap id="Pblog_ipmodifyResult" class="Pblog_ipmodify">
        <result column="id" property="id" javaType="java.lang.Integer"
            jdbcType="int" nullValue="0" />
        <result column="service_code" property="service_code"
            javaType="java.lang.String" jdbcType="varchar" />
        
        <result column="original_ip" property="original_ip"
            javaType="java.lang.String" jdbcType="varchar" />
        <result column="modify_ip" property="modify_ip"
            javaType="java.lang.String" jdbcType="varchar" />
        <result column="modify_time" property="modify_time" />
        
    </resultMap>
    <resultMap id="Pblog_iprs" class="Pblog_ipmodify">
        <result column="id" property="id" javaType="java.lang.Integer"
            jdbcType="int" nullValue="0" />
        <result column="service_code" property="service_code"
            javaType="java.lang.String" jdbcType="varchar" />
        <result column="service_name" property="service_name"
            javaType="java.lang.String" jdbcType="varchar" />
    
        <result column="modify_ip" property="modify_ip"
            javaType="java.lang.String" jdbcType="varchar" />
            <result column="original_ip" property="original_ip"
            javaType="java.lang.String" jdbcType="varchar" />
        <result column="modify_time" property="modify_time" javaType="java.lang.String" jdbcType="varchar" />
        <result column="cbs" property="countByServiceCode"
            javaType="java.lang.String" jdbcType="int" />
    </resultMap>
    <resultMap id="getipModifyDetil" class="Pblog_ipmodify">
        <result column="id" property="id" javaType="java.lang.Integer"
            jdbcType="int" nullValue="0" />
        <result column="original_ip" property="original_ip"
            javaType="java.lang.String" jdbcType="varchar" />
        <result column="modify_time" property="modify_time"
            javaType="java.lang.String" jdbcType="varchar" />
        <result column="modify_ip" property="modify_ip"
            javaType="java.lang.String" jdbcType="varchar" />
    </resultMap>
    <sql id="where">
        <dynamic prepend="where">
            <isNotNull property="id">
                <isGreaterEqual prepend="and" property="id"
                    compareValue="0">
                    id = #id:int#
                </isGreaterEqual>
            </isNotNull>
            <isNotNull property="service_code">
                <isNotEmpty prepend="and" property="service_code">
                    service_code = #service_code:varchar#
                </isNotEmpty>
            </isNotNull>
            <isNotNull property="original_ip">
                <isNotEmpty prepend="and" property="original_ip">
                    original_ip = #original_ip:varchar#
                </isNotEmpty>
            </isNotNull>
            <isNotNull property="modify_ip">
                <isNotEmpty prepend="and" property="modify_ip">
                    modify_ip = #modify_ip:varchar#
                </isNotEmpty>
            </isNotNull>
            <isNotNull property="modify_time">
                <isNotEmpty prepend="and" property="modify_time">
                    modify_time = #modify_time:datetime#
                </isNotEmpty>
            </isNotNull>
            <isNotNull property="service_name">
                <isNotEmpty prepend="and" property="service_name">
                    a.service_name = #service_name:varchar#
                </isNotEmpty>
            </isNotNull>
            <isNotNull property="start_time">
                <isNotEmpty prepend="and" property="start_time">
                    to_date(a.modify_time,'yyyy-MM-dd hh24:mi:ss') >= to_date('$start_time$ 00:00:00','yyyy-MM-dd hh24:mi:ss')
                </isNotEmpty>
            </isNotNull>
            <isNotNull property="end_time">
                <isNotEmpty prepend="and" property="end_time">
                <![CDATA[     to_date(a.modify_time,'yyyy-MM-dd hh24:mi:ss') <= to_date('$end_time$ 23:59:59','yyyy-MM-dd hh24:mi:ss')]]>
                </isNotEmpty>
            </isNotNull>
        </dynamic>
    </sql>

    <sql id="whereByLike">
        <dynamic prepend="where">
            <isNotNull prepend="and" property="service_code">
                service_code like '%$service_code$%'
            </isNotNull>
            <isNotNull prepend="and" property="original_ip">
                original_ip like '%$original_ip$%'
            </isNotNull>
            <isNotNull prepend="and" property="modify_ip">
                modify_ip like '%$modify_ip$%'
            </isNotNull>
        </dynamic>
    </sql>


    <select id="select" resultMap="Pblog_iprs"
        parameterClass="Pblog_ipmodify">
        select * from (select
        a.service_code,pi.service_name,b.modify_ip,b.original_ip,a.modify_time,a.cbs, b.id
        from(select p.service_code,count(*) cbs,max(p.modify_time)
        modify_time from pblog_ipmodify p where 1=1 group by p.service_code) a
        left join pblog_ipmodify b on b.service_code=a.service_code and
        a.modify_time=b.modify_time left join pb_isbnlist pi on
        pi.service_code=a.service_code) a
        <include refid="com.devtek.sys.pb.pojo.Pblog_ipmodify.where" />
    </select>
    <select id="getIpModifyDetilByService" resultMap="getipModifyDetil"
        parameterClass="Pblog_ipmodify">
        select id,modify_ip,original_ip,modify_time from pblog_ipmodify
        <include refid="com.devtek.sys.pb.pojo.Pblog_ipmodify.where" />
    </select>
    <select id="selectCount" resultClass="int"
        parameterClass="Pblog_ipmodify">
        select count(*) from (select a.service_code,
                       pi.service_name,
                       b.modify_ip,
                      b.original_ip,
                       a.modify_time,
                       a.cbs
                  from (select p.service_code,
                               count(*) cbs,
                               max(p.modify_time) modify_time
                          from pblog_ipmodify p
                      
                         group by p.service_code) a
                  left join pblog_ipmodify b on b.service_code =
                                                a.service_code
                                            and a.modify_time = b.modify_time
                  left join pb_isbnlist pi on pi.service_code =
                                              a.service_code ) a
        <include refid="com.devtek.sys.pb.pojo.Pblog_ipmodify.where" />
    </select>

    <select id="selectByLike" resultMap="Pblog_ipmodifyResult"
        parameterClass="Pblog_ipmodify">
        select * from pblog_ipmodify
        <include
            refid="com.devtek.sys.pb.pojo.Pblog_ipmodify.whereByLike" />
    </select>

    <select id="selectByMap" resultMap="Pblog_ipmodifyResult"
        parameterClass="java.util.Map">
        select * from pblog_ipmodify
    </select>

    <select id="findLikeByMap" resultMap="Pblog_ipmodifyResult"
        parameterClass="java.util.Map">
        select * from pblog_ipmodify
        <include
            refid="com.devtek.sys.pb.pojo.Pblog_ipmodify.whereByLike" />
    </select>

    <select id="findByMap" resultMap="Pblog_ipmodifyResult"
        parameterClass="java.util.Map">
        select * from pblog_ipmodify
        <include refid="com.devtek.sys.pb.pojo.Pblog_ipmodify.where" />
    </select>

    
</sqlMap>