要解决无法将 java.util.Date 字段 com.zk3.entity.JieShu.jtime 设置为 null 值的问题,可以使用包装类 java.util.Date 的替代方案 java.sql.Timestamp。将 JieShu 类中的 jtime 字段的类型改为 java.sql.Timestamp,并相应地更新相应的 getter 和 setter 方法。

修改后的 JieShu 类如下所示:

package com.zk3.entity;

import java.sql.Timestamp;

public class JieShu {
    private int jid;
    private String jbname;
    private int jsid;
    private String jsname;
    private String jstel;
    private double jbprice;
    private int jbnum;
    private int jts;
    private Timestamp jtime;

    public JieShu() {
    }

    public JieShu(int jid, String jbname, int jsid, String jsname, String jstel, double jbprice, int jbnum, int jts, Timestamp jtime) {
        this.jid = jid;
        this.jbname = jbname;
        this.jsid = jsid;
        this.jsname = jsname;
        this.jstel = jstel;
        this.jbprice = jbprice;
        this.jbnum = jbnum;
        this.jts = jts;
        this.jtime = jtime;
    }

    public int getJid() {
        return jid;
    }

    public void setJid(int jid) {
        this.jid = jid;
    }

    public String getJbname() {
        return jbname;
    }

    public void setJbname(String jbname) {
        this.jbname = jbname;
    }

    public int getJsid() {
        return jsid;
    }

    public void setJsid(int jsid) {
        this.jsid = jsid;
    }

    public String getJsname() {
        return jsname;
    }

    public void setJsname(String jsname) {
        this.jsname = jsname;
    }

    public String getJstel() {
        return jstel;
    }

    public void setJstel(String jstel) {
        this.jstel = jstel;
    }

    public double getJbprice() {
        return jbprice;
    }

    public void setJbprice(double jbprice) {
        this.jbprice = jbprice;
    }

    public int getJbnum() {
        return jbnum;
    }

    public void setJbnum(int jbnum) {
        this.jbnum = jbnum;
    }

    public int getJts() {
        return jts;
    }

    public void setJts(int jts) {
        this.jts = jts;
    }

    public Timestamp getJtime() {
        return jtime;
    }

    public void setJtime(Timestamp jtime) {
        this.jtime = jtime;
    }

    @Override
    public String toString() {
        return "JieShu{" +
                "jid=" + jid +
                ", jbname='" + jbname + "'" +
                ", jsid=" + jsid +
                ", jsname='" + jsname + "'" +
                ", jstel='" + jstel + "'" +
                ", jbprice=" + jbprice +
                ", jbnum=" + jbnum +
                ", jts=" + jts +
                ", jtime='" + jtime + "'" +
                '}';
    }
}

通过以上修改,即可解决无法将 java.util.Date 字段设置为 null 值的问题。

解决无法将 java.util.Date 字段设置为 null 值的问题

原文地址: http://www.cveoy.top/t/topic/bTYz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录