Skip to content

Instantly share code, notes, and snippets.

@ajjain
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajjain/e7c8bf71b87cefc7375e to your computer and use it in GitHub Desktop.
Save ajjain/e7c8bf71b87cefc7375e to your computer and use it in GitHub Desktop.
PostgreSQL+MyBatis+Insert+Autogenerated ID
CREATE TABLE BOOK (
ID SERIAL PRIMARY KEY,
NAME VARCHAR (50) UNIQUE NOT NULL,
TITLE VARCHAR (100),
DESCRIPTION VARCHAR (200)
);
<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