Last active
August 29, 2015 14:03
-
-
Save ajjain/e7c8bf71b87cefc7375e to your computer and use it in GitHub Desktop.
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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment