Returning values from MyBatis mapped methods

前端 未结 5 810
无人及你
无人及你 2020-12-28 08:33

I have a Java project that uses MyBatis to access a PostgreSQL database. PostgreSQL allows to return fields of a newly created row after an INSERT statement, an

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-28 09:14

    In this example using options

    import org.apache.ibatis.annotations.Insert;
    import org.apache.ibatis.annotations.Mapper;
    import org.apache.ibatis.annotations.Options;
    import org.apache.ibatis.annotations.Param;
    
    @Mapper
    public interface POJOCustomMapper {
        @Options(useGeneratedKeys = true, keyProperty = "ID", keyColumn = "ID") 
        @Insert({
            "insert into TABLE_A ( NAME "
            "values (#{NAME,jdbcType=VARCHAR})"
        })
        long insert(POJO record);
    

提交回复
热议问题