`
jingfengluo
  • 浏览: 44478 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

ibatis crub返回值问题

阅读更多

<insert id="insertBook" parameterClass="book">
insert into BOOKS (bookNum, bookName, author, publisher,price,
state, quality) values ( #bookNum:VARCHAR#, #bookName:VARCHAR#,
#author:VARCHAR#,#publisher:VARCHAR#, #price:FLOAT#,
#state:INTEGER#, #quality:INTEGER#)

<selectKey resultClass="int" keyProperty="bookId" >
SELECT @@IDENTITY AS bookId
</selectKey> 

</insert>

 

在执行insert是才会返回插入的id

    public int update(Book book) throws DatabaseException{
        String method = "update";
        int result = 0;
        try {
            result = update("updateBook", book);
            debug("", method, Constant.LOG_UPDATE_SUCCESS);
        } catch (RuntimeException e) {
            error("", method, Constant.LOG_UPDATE_FAIL);
            throw new DatabaseException(DatabaseException.DB_Message, e);
        }
        return result;
    }

///////////////////////////////////////////////

对于删除

<delete id="deleteBook" parameterClass="int" >
        DELETE FROM BOOKS WHERE BookId = #bookId#
 </delete>

直接返回影响记录集

    /**
     * 
     * @param bookId
     * @throws DatabaseException
     * @return int >0:delete success  <0: delete fail
     */
    public int deleteBook(int bookId) throws DatabaseException{
        String method = "deleteBook";
        int result = -1;
        try {
            result = (Integer)this.delete("deleteBook", bookId);
            debug("", method, Constant.LOG_DELETE_SUCCESS);
        } catch (RuntimeException e) {
            result = -1;
            error("", method, Constant.LOG_DELETE_FAIL);
            throw new DatabaseException(DatabaseException.DB_Message, e);
        }
        return result;
    }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics