题目描述
使用springboot+mybits进行数据库插入操作时,使用实体类set数值,会出现报错java.lang.NullPointerException: null
问题出现的环境背景及自己尝试过哪些方法
使用输出,又可以输出实体类里面的内容,并且select可以查询出来
相关代码
具体代码:
dataIfm.setMd5(md5.toString());
dataIfm.setUsername(username);
dataIfm.setProjectName(headName);
if(dataIfm == null){
System.out.println("数据为空");
}else {
System.out.println(dataIfm.getMd5());
System.out.println(dataIfm.getProjectName());
System.out.println(dataIfm.getUsername());
}
/*int i = dataIfmService.insertIfm(dataIfm);
mapper:
<mapper namespace="com.gdr.bysj.dao.DataIfmDao" >
<resultMap id="BaseResultMap" type="com.gdr.bysj.entity.DataIfm" >
<id column="username" property="username" jdbcType="VARCHAR" />
<result column="project_name" property="projectName" jdbcType="VARCHAR" />
<result column="MD5" property="md5" jdbcType="VARCHAR" />
<result column="Data_type" property="dataType" jdbcType="VARCHAR" />
<result column="insert_time" property="insertTime" jdbcType="VARCHAR" />
</resultMap>
<insert id="insertSelective" parameterType="com.gdr.bysj.entity.DataIfm" >
insert into data_ifm
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="username != null" >
username,
</if>
<if test="projectName != null" >
project_name,
</if>
<if test="md5 != null" >
MD5,
</if>
<if test="dataType != null" >
Data_type,
</if>
<if test="insertTime != null" >
insert_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="username != null" >
#{username,jdbcType=VARCHAR},
</if>
<if test="projectName != null" >
#{projectName,jdbcType=VARCHAR},
</if>
<if test="md5 != null" >
#{md5,jdbcType=VARCHAR},
</if>
<if test="dataType != null" >
#{dataType,jdbcType=VARCHAR},
</if>
<if test="insertTime != null" >
#{insertTime,jdbcType=VARCHAR},
</if>
</trim>
</insert>
实体类:
public class DataIfm {
private String username;
private String projectName;
private String md5;
private String dataType;
private String insertTime;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username == null ? null : username.trim();
}
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName == null ? null : projectName.trim();
}
public String getMd5() {
return md5;
}
public void setMd5(String md5) {
this.md5 = md5 == null ? null : md5.trim();
}
public String getDataType() {
return dataType;
}
public void setDataType(String dataType) {
this.dataType = dataType == null ? null : dataType.trim();
}
public String getInsertTime() {
return insertTime;
}
public void setInsertTime(String insertTime) {
this.insertTime = insertTime == null ? null : insertTime.trim();
}