sql xml 回填自增id

CardDao.java


import com.example.domain.card.Card;

/**
 * 卡片 Dao接口
 *
 * @author ming
 * @version 1.0.0
 * @date 2022-05-20 11:23:01
 **/

public interface CardDao {

    /**
     * 新增(回填自增id)
     *
     * @param card 卡片
     * @return java.lang.Integer
     * @author ming
     * @date 2022/5/24 15:35
     */
    Integer cardInsert(Card card);
}

CardMapper.xml

keyProperty就是我们要回填的字段

<insert id="cardInsert" parameterType="com.example.domain.card.Card" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
    INSERT into t_card(name,description,icon_url,creator,create_time)
    VALUES(#{name},#{description},#{iconUrl},#{creator},#{createTime})
</insert>

调用

// 这样就可以拿到自增id
int res = cardDao.cardInsert(card);
log.info(card.getId() + "");
posted @ 2022-05-24 15:42  itwetouch  阅读(78)  评论(0编辑  收藏  举报