使用Jfinal新增一条数据:
new CommentRecord().set("comment_time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())).set("star_level", starLevel).set("comment", commentText).save();
结果报错如下:
com.jfinal.plugin.activerecord.ActiveRecordException: java.sql.SQLException: Field 'id' doesn't have a default value at com.jfinal.plugin.activerecord.Model.save(Model.java:424)...Caused by: java.sql.SQLException: Field 'id' doesn't have a default valueat com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)...
原因是数据库对应的Table表的主键id不是自增的,修改即可: