数据库表中的自增主键与Java类中属性的映射

在xml文件中添加红框代码

 

 keyProperty指数据库表中的自增主键

keyColum指映射的类中的属性名称

 

上代码:

<insert id="add" parameterType="com.example.demo01.domain.Video" useGeneratedKeys="true" keyProperty="id" keyColumn="id">

INSERT INTO `db_video`.`video` (`id`, `title`, `detail`, `cover_img`, `price`, `point`)
VALUES (#{id,jdbcType=INTEGER},#{title,jdbcType=VARCHAR},#{detail,jdbcType=VARCHAR},#{coverImg,jdbcType=VARCHAR},#{price,jdbcType=INTEGER},#{point,jdbcType=DOUBLE});

</insert>

 

posted @ 2021-11-19 10:34  智慧搬运工  阅读(130)  评论(0)    收藏  举报