mapper文件

springboot + mybatis plus使用insert 语句并返回主键

映射文件中在insert中设置useGeneratedKeys为true,keyProperty设置为主键名称

<insert >
    INSERT
        INTO
        employees (emp_name, emp_age, emp_no, hire_date, sal, deptno, mgr,
        user_name, email, phone_number, sex, emp_password, status, remark)
    VALUES(#{empName},#{empAge},#{empNo},#{hireDate},cast(#{sal} as money),#{deptno},#{mgr},
    #{userName},#{email},#{phoneNumber},#{sex},#{empPassword},#{status},#{remark})
</insert>

在业务层中使用对象的getter方法得到自动化生成的主键值

springboot + mybatis plus使用insert 语句并返回主键
参考资料:
https://www.cnblogs.com/Lyn4ever/p/11390497.html





相关文章:

  • 2021-07-25
  • 2022-02-01
  • 2021-07-27
  • 2022-12-23
  • 2021-07-01
  • 2021-11-26
  • 2021-07-28
  • 2021-10-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-26
  • 2022-02-14
  • 2021-05-24
相关资源
相似解决方案