How do I return auto-generated IDs inserted in table within the same insert API?
PostgreSQL+MyBatis+Insert+Autogenerated ID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE BOOK ( | |
ID SERIAL PRIMARY KEY, | |
NAME VARCHAR (50) UNIQUE NOT NULL, | |
TITLE VARCHAR (100), | |
DESCRIPTION VARCHAR (200) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mapper> | |
<select id="add_book" parameterType="map" resultType="map"> | |
INSERT | |
INTO BOOK(NAME,TITLE,DESCRIPTION) | |
VALUES | |
(#{name},#{title},#{description}) | |
RETURNING *; | |
</select> | |
<select id="add_book" parameterType="list" resultType="map"> | |
INSERT | |
INTO BOOK(NAME,TITLE,DESCRIPTION) | |
VALUES | |
<foreach collection="list" item="item" index="index" open="" separator="," close=""> | |
(#{item.name},#{item.title},#{item.description}) | |
</foreach> | |
RETURNING *; | |
</select> | |
</mapper> |
No comments:
Post a Comment