Returning values from MyBatis mapped methods

前端 未结 5 816
无人及你
无人及你 2020-12-28 08:33

I have a Java project that uses MyBatis to access a PostgreSQL database. PostgreSQL allows to return fields of a newly created row after an INSERT statement, an

5条回答
  •  死守一世寂寞
    2020-12-28 09:09

    You can use as follows. In xml

     
                
                    select NEXTVAL('base.user_id_seq')
                
                INSERT INTO base.user(
                    user_id, user_name)
                VALUES (#{userId}, #{userName});
        
    

    In Java class from where you have called the method to insert, you can get the value by calling user.getUserId().

    Basically the next val is stored inside the variable of the object. Here userId inside User.

提交回复
热议问题