有很多时候table 的列为关键字:
例如这样:
INSERT INTO message (content, createtime, FROM, STATUS, TO, id) VALUES ('1', '1','1','1','1','2')
其中FROM , STATUS , TO 为关键字 .所以在插入的时候就会报错:
错误码: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from, status, to, id) values ('1', '1','1','1','1','2')' at line 1
在SSH项目中处理这种报错有一个很简单的方法,在modle 层的实体类注解一下:
@Column(name = "from", unique = false, nullable = true, insertable = true, updatable = true, length = 32)
public java.lang.String getFrom() {
return this.from;
}
改为:
@Column(name = "`from`", unique = false, nullable = true, insertable = true, updatable = true, length = 32)
public java.lang.String getFrom() {
return this.from;
}
然后就可以愉快的增删该查了