<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    持之以恒

    記錄本
    posts - 4, comments - 32, trackbacks - 0, articles - 74
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理
    關于com.ibatis.sqlmap.client.SqlMapExecutor下的insert (java.lang.String id, java.lang.Object parameterObject) 方法,ibatis的api文檔是這樣寫的解釋的:

    Java代碼
    Executes a mapped SQL INSERT statement. Insert is a bit different from other update methods, as it provides facilities for returning the primary key of the newly inserted row (rather than the effected rows). This functionality is of course optional.

    The parameter object is generally used to supply the input data for the INSERT values.

    Parameters:
    id - The name of the statement to execute.
    parameterObject - The parameter object (e.g. JavaBean, Map, XML etc.).
    Returns:
    The primary key of the newly inserted row. This might be automatically generated by the RDBMS, or selected from a sequence table or other source.
    Throws:
    java.sql.SQLException - If an error occurs.

    Executes a mapped SQL INSERT statement. Insert is a bit different from other update methods, as it provides facilities for returning the primary key of the newly inserted row (rather than the effected rows). This functionality is of course optional.

    The parameter object is generally used to supply the input data for the INSERT values.

    Parameters:
    id - The name of the statement to execute.
    parameterObject - The parameter object (e.g. JavaBean, Map, XML etc.).
    Returns:
    The primary key of the newly inserted row. This might be automatically generated by the RDBMS, or selected from a sequence table or other source.
    Throws:
    java.sql.SQLException - If an error occurs.


    它的意思是說返回值是新插入記錄的主鍵,類型為Object主要是因為主鍵類型可以是int也可以是String類型。

    然而,如果我們使用下列的配置文件進行插入的話,返回的值為null

    Xml代碼
    <insert id="insertPrdcategory" parameterClass="Prdcategory">
    insert into Prdcategory ( name,pid,deep ) values ( #name#,
    #pid#, #deep# )
    </insert>

    <insert id="insertPrdcategory" parameterClass="Prdcategory">
    insert into Prdcategory ( name,pid,deep ) values ( #name#,
    #pid#, #deep# )
    </insert>

    那我們要怎樣解決這個問題,讓它返回插入行的主鍵呢,這時我們就是使用到<selectKey>,下面僅以MSSQL數據庫為例,改寫上述配置文件,具體如下:



    Xml代碼
    <insert id="insertPrdcategory" parameterClass="Prdcategory">
    insert into Prdcategory ( name,pid,deep ) values ( #name#,
    #pid#, #deep# )
    <selectKey resultClass="int" keyProperty="id">
    select max(id) from Prdcategory
    </selectKey>
    </insert>

    <insert id="insertPrdcategory" parameterClass="Prdcategory">
    insert into Prdcategory ( name,pid,deep ) values ( #name#,
    #pid#, #deep# )
    <selectKey resultClass="int" keyProperty="id">
    select max(id) from Prdcategory
    </selectKey>
    </insert>


    DAO的實現類方法里面就應該這樣寫了(注意整型轉換用Integer類名)

    Java代碼
    public int insertPrdcategory(Prdcategory product) throws Exception {
    return (Integer)IbatisUtil.getSqlMapper().insert("insertPrdcategory", product);
    }

    public int insertPrdcategory(Prdcategory product) throws Exception {
    return (Integer)IbatisUtil.getSqlMapper().insert("insertPrdcategory", product);
    }


    這樣就算是OK了。


    小白

    評論

    # re: 關于Ibatis insert后返回值為null的解決辦法(轉)   回復  更多評論   

    2013-02-22 09:06 by 路過看看
    并發量大的時候,這正方法可以?

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 免费精品视频在线| 亚洲精品GV天堂无码男同| 成人A级毛片免费观看AV网站| 无码亚洲成a人在线观看| 亚洲中文字幕人成乱码| 免费午夜爽爽爽WWW视频十八禁| 16女性下面扒开无遮挡免费| 国产猛男猛女超爽免费视频| 一级做a爰片久久毛片免费陪| 亚洲色大成网站www永久男同 | 国产亚洲精品无码成人| 在线免费观看毛片网站| 久久笫一福利免费导航| 4444www免费看| 波多野结衣在线免费观看| 日本免费人成在线网站| 99久久99久久精品免费看蜜桃| **俄罗斯毛片免费| 岛国av无码免费无禁网站| 女人毛片a级大学毛片免费| 免费国产作爱视频网站| 韩国免费三片在线视频| 亚洲&#228;v永久无码精品天堂久久| 午夜色a大片在线观看免费| 亚洲精品国精品久久99热| 亚洲熟伦熟女新五十路熟妇| 国产亚洲精品岁国产微拍精品| 亚洲AV无码一区东京热久久| 亚洲视频小说图片| 亚洲精品蜜夜内射| 中文字幕a∨在线乱码免费看| 午夜精品一区二区三区免费视频| 野花高清在线观看免费完整版中文 | 日本XXX黄区免费看| 国产又大又黑又粗免费视频| 在线亚洲人成电影网站色www| 亚洲成a人片在线观看中文!!!| 一区二区三区在线观看免费| www视频免费看| 在线亚洲97se亚洲综合在线 | 在线看片韩国免费人成视频|