mybatis insert 数据 NullPointerException

ERROR [com.czljy.app.action.CourseAction] - <CourseAction.addComment:评论nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: java.lang.NullPointerException
### The error may involve com.czljy.mapper.CzlResourceCommentMapper.add-Inline
### The error occurred while setting parameters
### SQL: insert into czl_resource_comment (id,resourceId,userId,userName,answer,createDate,score)  values (?,?,?,?,?,?,?)
### Cause: java.lang.NullPointerException>
2016-11-30 14:29:10,921 ERROR [com.czljy.app.action.CourseAction] - <CourseAction.addComment:评论nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: java.lang.NullPointerException
package com.czljy.bean;

import org.springframework.format.annotation.DateTimeFormat;

public class CzlResourceComment extends BaseBean {


    private Integer id;//   ID
    private String resourceId;//   问答答案ID
    private Integer userId;//   评论人
    private String userName;//   评论人姓名
    private String answer;//   评论
    private java.sql.Timestamp createDate;//   评论时间

    private Integer score;//   评分(这个类型要做修改)
    public Integer getId() {
        return this.id;
    }
    public void setId(Integer id) {
        this.id=id;
    }
    public String getResourceId() {
        return this.resourceId;
    }
    public void setResourceId(String resourceId) {
        this.resourceId=resourceId;
    }
    public Integer getUserId() {
        return this.userId;
    }
    public void setUserId(Integer userId) {
        this.userId=userId;
    }
    public String getUserName() {
        return this.userName;
    }
    public void setUserName(String userName) {
        this.userName=userName;
    }
    public String getAnswer() {
        return this.answer;
    }
    public void setAnswer(String answer) {
        this.answer=answer;
    }
    public java.sql.Timestamp getCreateDate() {
        return this.createDate;
    }
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    public void setCreateDate(java.sql.Timestamp createDate) {
        this.createDate=createDate;
    }
    public int getScore() {
        return score;
    }
    public void setScore(int score) {
        this.score = score;
    }

}

这里写图片描述

当实体类CzlResourceComment: score不传入值时,为报这种错误。
因为score为Integer,插入时,类型不匹配,Integer默认为null。
把score类型从Integer改为int,int是基本数据类型,不初始化值时,默认为0,

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值