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;
}
Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐