mybatis insert 插入数据成功后返回值为 null

使用MyBatis的sqlMap.insert()方法,数据插入成功,但返回的结果总是null。解决方法:

 将原来的insert语句加上标签

 
            INSERT INTO TB_PY_BASIC (
        ph_id ,
        device_id ,
        physical_name ,
        device_type ,
        cr_user ,
        cr_time ,
        status ,
        rs_type ,
        alarm_state ,
        ip_address ,
        os_type ,
        update_time 
        ) VALUES (
        #phId# ,
        #deviceId# ,
        #physicalName# ,
        #deviceType# ,
        #crUser# ,
        #crTime# ,
        #status# ,
        #rsType# ,
        #alarmState# ,
        #ipAddress# ,
        #osType# ,
        #updateTime# 
        )
    ]]>
   
       
            select last_insert_id() as phId
       

   

其中中的keyProperty="phId" 为相应表的主键名。保证该属性的类型和javabean中
相应属性类型一致。

但若该属性id为int,则中的resultClass="int",接着将sqlMap.insert返回的object转换为int类型。


你可能感兴趣的:(mysql)