Error attempting to get column ‘remark‘ from result set

Error attempting to get column ‘remark’ from result set. Cause: java.sql.SQLDataException: Cannot convert string ‘1’ to java.sql.Timestamp value
; Cannot convert string ‘1’ to java.sql.Timestamp value] with root cause
先说结论:报错的原因是日期转换出了问题,数据库的日期为空值,那么就是null,这里转换走了实体类的有参构造函数,那么就报错了,在实体类里面加上无参构造函数就可以了。
实体类如下:

package com.example.entity;

import java.util.Date;

public class Stock {
    private String id;
    private String name;
    private String number;
    private String themeId;
    private String themeName;
    private String remark;
    private Date createDate;
    private Date updateDate;

    //必须写
    public Stock(){

    }
    public Stock(String id, String name, String number, String themeName, String remark, Date createDate, Date updateDate) {
        this.id = id;
        this.name = name;
        this.number = number;
        this.themeName = themeName;
        this.remark = remark;
        this.createDate = createDate;
        this.updateDate = updateDate;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getThemeName() {
        return themeName;
    }

    public void setThemeName(String themeName) {
        this.themeName = themeName;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    @Override
    public String toString() {
        return "Stock{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", number='" + number + '\'' +
                ", themeName='" + themeName + '\'' +
                ", remark='" + remark + '\'' +
                ", createDate=" + createDate +
                ", updateDate=" + updateDate +
                '}';
    }
}

mapper.xml代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.mapper.StockMapper">
    <resultMap id="BaseResultMap" type="com.example.entity.Stock">
        <id column="id" jdbcType="VARCHAR" property="id" />
        <result column="number" jdbcType="VARCHAR" property="number" />
        <result column="name" jdbcType="VARCHAR" property="name" />
        <result column="themeId" jdbcType="VARCHAR" property="themeId" />
        <result column="themeName" jdbcType="VARCHAR" property="themeName" />
        <result column="remark" jdbcType="VARCHAR" property="remark" />
        <result column="createDate" jdbcType="DATE" property="createDate" />
        <result column="updateDate" jdbcType="DATE" property="updateDate" />
    </resultMap>
    <sql id="Base_Column_List">
        id, number, name,themeId,themeName,remark,createDate,updateDate
    </sql>
    <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from stock_detail
        where id = #{id,jdbcType=VARCHAR}
    </select>
  </mapper>

你可能感兴趣的:(mybatis,mybatis,java)