3、SpringBoot+Mybatis整合------主键回填

开发工具:STS 代码下载链接:https://github.com/theIndoorTrain/SpringBoot_Mybatis01/tree/d68efe51774fc4d96e5c6870786eb3f1a1a5b629 前言:

当我们插入一个一对一、一对多、多对多的关系数据时,往往需要分表插入,那么我们可能需要获取自动生成的主键用于后面的插入操作,因此今天来介绍下mybatis里的主键回填。

一、代码实现: 1.数据操作层接口mapper:

3、SpringBoot+Mybatis整合------主键回填

3、SpringBoot+Mybatis整合------主键回填

1 package com.xm.mapper; 2 3 import java.util.List; 4 5 import com.xm.pojo.Student; 6 7 public interface StudentMapper { 8 9 /** 10 * 根据id查询 11 * @param id 12 * @return 13 */ 14 public Student getById(Integer id); 15 16 /** 17 * 查询全部 18 * @return 19 */ 20 public List<Student> list(); 21 22 /** 23 * 插入 24 * @param student 25 */ 26 public int insert(Student student); 27 /** 28 * 主键回填的插入 29 * @param student 30 * @return 31 */ 32 public int insertToId(Student student); 33 34 /** 35 * 根据student的id修改 36 * @param student 37 */ 38 public void update(Student student); 39 40 /** 41 * 根据id删除 42 * @param id 43 */ 44 public void delete(Integer id); 45 46 47 }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpzgxy.html