美文网首页
Spring boot 注解系列 插入对象返回 id

Spring boot 注解系列 插入对象返回 id

作者: crMiao | 来源:发表于2019-05-10 13:24 被阅读0次
    @Insert("insert into table(name, phone) value(#{name},#{phone})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")//加入该注解可以保持对象后,查看对象插入id
    public int insert(Object object);
    }
    @Service
    public class ObjectService {

    @Resource
    private ObjectDao objectDao;

    public int insert(Object o){
        objectDao.insert(o);
        return o.getId();
    }
}

相关文章

网友评论

      本文标题:Spring boot 注解系列 插入对象返回 id

      本文链接:https://www.haomeiwen.com/subject/sxfaoqtx.html