This primary key of “id“ is primitive !不建议如此请使用包装类 in Class package com.mcp.enity.student解决方法
详解This primary key of “id“ is primitive !不建议如此请使用包装类 in Class package com.mcp.enity.student解决方法
·
1.原因分析:
默认在Student类中使用了int类型与mybatis中列的映射类型无法匹配:
package com.mcp.enity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@TableName("t_student")
@Data
public class Student {
@TableId(type = IdType.AUTO)
private int id;
private String name;
private int age;
private String sex;
private String classRoom;
private String address;
}
<mapper namespace="com.mcp.mapper.StudentMapper"> <resultMap id="BaseResultMap" type="com.mcp.enity.Student"> <id column="id" jdbcType="BIGINT" property="id" /> <result column="name" jdbcType="VARCHAR" property="name" /> <result column="age" jdbcType="BIGINT" property="age" /> <result column="sex" jdbcType="VARCHAR" property="sex"/> <result column="address" jdbcType="VARCHAR" property="address"/> <result column="class_room" jdbcType="VARCHAR" property="classRoom"/> </resultMap> </mapper>
2.解决方法:修改Student类中 int类为包装类:Integer
package com.mcp.enity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@TableName("t_student")
@Data
public class Student {
@TableId(type = IdType.AUTO)
private Integer id;
private String name;
private Integer age;
private String sex;
private String classRoom;
private String address;
}
更多推荐


所有评论(0)