WEB开发网
开发学院软件开发Java Struts 2.1.6 精简实例系列教程(3):新闻管理Mode... 阅读

Struts 2.1.6 精简实例系列教程(3):新闻管理Model层的开发(整合iBatis)

 2009-09-23 00:00:00 来源:WEB开发网   
核心提示: 有了数据表和实体类,现在来写两者之间映射的配置文件Article.xml,Struts 2.1.6 精简实例系列教程(3):新闻管理Model层的开发(整合iBatis)(3),代码如下:<?xmlversion="1.0"encoding="UTF-8&qu

有了数据表和实体类,现在来写两者之间映射的配置文件Article.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="Article">
    <!-- Use type aliases to avoid typing the full classname every time. -->
    <typeAlias alias="Article" type="cn.simple.pojo.Article" />
    <!--
        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 aliases) match to the properties exactly.
    -->
    <resultMap id="ArticleResult" class="Article">
        <result property="id" column="ID" />
        <result property="title" column="TITLE"/>
        <result property="author" column="AUTHOR"/>
        <result property="content" column="CONTENT"/>
        <result property="pubtime" column="PUBTIME"/>
    </resultMap>
    <!--
        Select with no parameters using the result map for Account class.
    -->
    <select id="selectAllArticles" resultMap="ArticleResult">
        select * from article
      </select>
    <!--
        A simpler select example without the result map. Note the aliases to
        match the properties of the target result class.
    -->
    <select id="selectArticleById" parameterClass="int" resultClass="Article">
        select
        ID as id,
        TITLE as title,
        AUTHOR as author,
        CONTENT as content,
        PUBTIME as pubtime
        from Article
        where ID=#id#
  </select>
    <!-- Insert example, using the Account parameter class -->
    <insert id="insertArticle" parameterClass="Article">
        insert into article (
            TITLE,
            AUTHOR,
            CONTENT,
            PUBTIME
        ) values (
            #title#,
            #author#,
            #content#,
            #pubtime#
        )
  </insert>
    <!-- Update example, using the Account parameter class -->
    <update id="updateArticle" parameterClass="Article">
        update article set
        TITLE = #title#,
        AUTHOR = #author#,
        CONTENT = #content#,
        PUBTIME = #pubtime#
        where
        ID = #id#
  </update>
    <!-- Delete example, using an integer as the parameter class -->
    <delete id="deleteArticleById" parameterClass="int">
        delete from article where ID = #id#
  </delete>
</sqlMap>

上一页  1 2 3 4 5 6  下一页

Tags:Struts 精简 实例

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接