ibatis 返回自增主键值(MYSQL)

XML配置文件:

 <!-- 添加 -->  
    <insert id="add" parameterClass="java.util.HashMap" >  
     
        <![CDATA[  
            INSERT INTO TS_AREA(TITLE,PID) VALUES(#title#,#pid#)  
        ]]>  
       
        <selectKey resultClass="int" keyProperty="area_id" >
   			SELECT @@IDENTITY AS area_id
   		</selectKey>
   		 
    </insert>  

 

调用代码:

	/*
	 *增加地区,插入成功,返回插入记录的主键值,插入失败,返回0
	 *ts_area
	 */
	public int add(Map map) {

		int result = 0;
		try {
			result = Integer.parseInt(sqlMapClient.insert("area.add", map)+"");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return result;
	}
 

你可能感兴趣的:(ibatis)