MyBatis-Plus 踩坑 ,getById查询无效

使用AutoGenerator(AutoGenerator 是 MyBatis-Plus 的代码生成器,通过 AutoGenerator 可以快速生成 Entity、Mapper、Mapper XML、Service、Controller 等各个模块的代码)生成代码后,在Controller中使用Service的getById()进行查询,返回的对象居然是null

问题出在Entity上,由于我数据表的id字段名为id且int类型,自动生成的id字段名serialVersionUID且类型为long类型,与数据库表对不上号。

使用getById(id)查询自然为null

因为entity生成出来的主键没注意到是不符合数据表的

所以解决方法是,把主键改成数据表对应的:把主键id字段名改回id,且数据类型设置int

@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("board_parent")
public class Parent extends BaseEntity {

    //private static final long serialVersionUID = 1L;

    private int id;

    @NotEmpty(message = "父论坛名不能为空!")
    private String name;

    @NotNull(message = "管理员ID不能为空!")
    private Integer adminId;

    public LocalDateTime createdDate;

    public LocalDateTime updateDate;

    public Integer state;


}

 

  • 7
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 15
    评论
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值