Mybatis Mapper selectByPrimaryKey 空指针

问题描述:
selectByPrimaryKey 找不到数据库中已有的数据
数据库主键为int 对应配置也是没问题的

import javax.persistence.Id;

public class FundDaily {
    @Id
    private Integer id;

spring-boot 开启日志级别为debug后,日志入下

2019-08-03 11:59:45.905 DEBUG 26462 --- [nio-8080-exec-1] o.m.s.t.SpringManagedTransaction         : JDBC Connection [HikariProxyConnection@1706822744 wrapping com.mysql.cj.jdbc.ConnectionImpl@6f177ab8] will not be managed by Spring
2019-08-03 11:59:45.909 DEBUG 26462 --- [nio-8080-exec-1] b.d.m.F.selectByPrimaryKey               : ==>  Preparing: SELECT id,symbol,volume,high,low,close,open,time FROM fund_daily WHERE id = ? 
2019-08-03 11:59:45.989 DEBUG 26462 --- [nio-8080-exec-1] b.d.m.F.selectByPrimaryKey               : ==> Parameters: null
2019-08-03 11:59:46.084 DEBUG 26462 --- [nio-8080-exec-1] b.d.m.F.selectByPrimaryKey               : <==      Total: 1

主要是调用问题,对于Intger 缓存区的,不能直接写 new Integer(),像下面这样写,因为new Integer(1) != new Integer(1) 两个int对象装箱后不一致(我大致看了一下目前是 -128 到 127),但是ValueOf 会有缓存就是一致的。

//java 版本10
fundDailyMapper4.selectByPrimaryKey(Integer.valueOf(1))

你可能感兴趣的:(Mybatis Mapper selectByPrimaryKey 空指针)