通用Mapper的selectByPrimaryKey方法,写的是正确的,却从数据库中查不到数据
问题描述:通用Mapper的selectByPrimaryKey方法,写的是正确的,却从数据库中查不到数据解决方案:实体类的主键属性一定要添加JPA的@Id注解,否则查询不到主键如果是int类型,不能使用int id 声明,一定要使用包装类Intergerpackage com.code_g.pojo;import lombok.Data;import tk.mybatis.mapper.anno
·
问题描述:
通用Mapper的selectByPrimaryKey方法,写的是正确的,却从数据库中查不到数据
解决方案:
- 实体类的主键属性一定要添加JPA的@Id注解,否则查询不到
- 主键如果是int类型,不能使用int id 声明,一定要使用包装类Interger
package com.code_g.pojo;
import lombok.Data;
import tk.mybatis.mapper.annotation.KeySql;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Data
@Entity
@Table(name = "user")
public class User {
@Id
@KeySql(useGeneratedKeys = true)
//使用int查不到
private Integer id;
private String username;
private String password;
}
更多推荐
已为社区贡献1条内容
所有评论(0)