SSM整合,MySQLIntegrityConstraintViolationException: Column 'xxx' cannot be null

SSM整合,MySQLIntegrityConstraintViolationException: Column 'xxx' cannot be null_第1张图片
1.查询对象com.pojo.Books中参数是否get,set,toSring和有参数、无参数构造器的配置。
2.检查mybatis层BookMapper.xml的sql语句。
3.检查spring-service.xml中sqlSessionFactory工厂类和配置dao接口扫描包。
4.检查spring-service.xml的所有业务类,注入Spring是否成功。声明事务配置transactionManager中注入数据源的正确。
package com.pojo;

public class Books {
private int bookID;
private String bookName;
private int bookCounts;
private String detail;

public Books() {}
public Books(int bookID, String bookName, int bookCounts, String detail) {
    this.bookID = bookID;
    this.bookName = bookName;
    this.bookCounts = bookCounts;
    this.detail = detail;
}
@Override
public String toString() {
    return "Books{" +
            "bookID=" + bookID +
            ", bookName='" + bookName + '\'' +
            ", bookCounts=" + bookCounts +
            ", detail='" + detail + '\'' +
            '}';
}

public int getBookID() { return bookID; }

public String getBookName() { return bookName;}

public int getBookCounts() {return bookCounts;}

public String getDetail() {return detail; }

public void setBookID(int bookID) { this.bookID = bookID; }

public void setBookName(String bookName) { this.bookName = bookName; }

public void setBookCounts(int bookCounts) { this.bookCounts = bookCounts; }

public void setDetail(String detail) { this.detail = detail; }

}

我就是Books中没写set导致,没set注入报插入为空(mysql各类参数设置非空)。

booksUSE ssmbuild;

CREATE TABLE books(
bookID INT NOT NULL AUTO_INCREMENT COMMENT ‘书id’,
bookName VARCHAR(100) NOT NULL COMMENT ‘书名’,
bookCounts INT NOT NULL COMMENT ‘数量’,
detail VARCHAR(200) NOT NULL COMMENT’描述’,
KEY bookID(bookID)
) ENGINE=INNODB DEFAULT CHARSET=utf8
SELECT *FROM books;

你可能感兴趣的:(SSM整合,MySQLIntegrityConstraintViolationException: Column 'xxx' cannot be null)