springboot使用通用mapper返回主键id

加上这三个注解就行了
@Id
@Column(name = “id”)
@KeySql(useGeneratedKeys = true)

package com.example.pluginstest.dao;

import tk.mybatis.mapper.annotation.KeySql;

import javax.persistence.*;

/**
 * @author zhang
 * @date 2020-7-21
 */
public class User {
     
    @Id
    @Column(name = "id")
    @KeySql(useGeneratedKeys = true)
    private int id;
    private String name;
    private String sex;

    @Override
    public String toString() {
     
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                '}';
    }

    public int getId() {
     
        return id;
    }

    public void setId(int id) {
     
        this.id = id;
    }

    public String getName() {
     
        return name;
    }

    public void setName(String name) {
     
        this.name = name;
    }

    public String getSex() {
     
        return sex;
    }

    public void setSex(String sex) {
     
        this.sex = sex;
    }
}

你可能感兴趣的:(java)