报错Cause: java.sql.SQLSyntaxErrorException: Unknown column ‘id‘ in ‘field list‘

IDEA reports the following error

Cause: java.sql.SQLSyntaxErrorException: Unknown column 'id' in 'field list'

insert image description here

The code at the beginning is as follows

package entity;

import lombok.Data;

@Data
public class User {
    private Long id;
    private String name;
    private int age;
    private String email;
}

The reason is because my primary key mapping is wrong, the
modification is as follows

Import import javax.persistence.*;, update
the code to update

package entity;

import lombok.Data;
import javax.persistence.*;

@Data
public class User {
    @Id
    @Column(name = "id")
    private Long id;
    private String name;
    private int age;
    private String email;
}

Finally, I found that the problem was caused by the inconsistency between the table name and the entity name.
My table name is this
and my entity name is this

Add a mapping in the code, map it to the table, specify the id in the table, and the id field cannot be found without specifying it. The final code is as follows

package entity;

import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import javax.persistence.*;

@Data
@TableName("testmybatisplus")
public class User {
    @Id
    @Column(name = "id")
    private Long id;
    private String name;
    private int age;
    private String email;
}

Guess you like

Origin blog.csdn.net/yilingpupu/article/details/121910578